|
20 | 20 | import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.BACKEND_SERVICE_KEY; |
21 | 21 | import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.LOCALITY_KEY; |
22 | 22 | import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.METHOD_KEY; |
23 | | -import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.RETRY_TYPE_KEY; |
24 | 23 | import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.STATUS_KEY; |
25 | 24 | import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.TARGET_KEY; |
26 | 25 |
|
|
45 | 44 | import io.grpc.Status; |
46 | 45 | import io.grpc.Status.Code; |
47 | 46 | import io.grpc.StreamTracer; |
48 | | -import io.grpc.opentelemetry.internal.OpenTelemetryConstants; |
49 | 47 | import io.opentelemetry.api.common.AttributesBuilder; |
50 | 48 | import java.util.ArrayList; |
51 | 49 | import java.util.Collection; |
@@ -299,6 +297,7 @@ static final class CallAttemptsTracerFactory extends ClientStreamTracer.Factory |
299 | 297 | private long callLatencyNanos; |
300 | 298 | private final Object lock = new Object(); |
301 | 299 | private final AtomicLong attemptsPerCall = new AtomicLong(); |
| 300 | + private final AtomicLong hedgedAttemptsPerCall = new AtomicLong(); |
302 | 301 | private final AtomicLong transparentRetriesPerCall = new AtomicLong(); |
303 | 302 | @GuardedBy("lock") |
304 | 303 | private int activeStreams; |
@@ -352,7 +351,10 @@ public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata metada |
352 | 351 | } |
353 | 352 | if (info.isTransparentRetry()) { |
354 | 353 | transparentRetriesPerCall.incrementAndGet(); |
355 | | - } else { |
| 354 | + } else if (info.isHedging()) { |
| 355 | + hedgedAttemptsPerCall.incrementAndGet(); |
| 356 | + } |
| 357 | + else { |
356 | 358 | attemptsPerCall.incrementAndGet(); |
357 | 359 | } |
358 | 360 | return newClientTracer(info); |
@@ -442,19 +444,30 @@ void recordFinishedCall() { |
442 | 444 | retriesPerCall = attempts - 1; |
443 | 445 | } |
444 | 446 |
|
445 | | - module.resource.clientCallRetriesCounter().record( |
446 | | - retriesPerCall, |
447 | | - baseAttributes.toBuilder() |
448 | | - .put(RETRY_TYPE_KEY, OpenTelemetryConstants.RetryType.RETRY.getValue()) |
449 | | - .build() |
450 | | - ); |
| 447 | + if (retriesPerCall > 0) { |
| 448 | + module.resource.clientCallRetriesCounter().record(retriesPerCall, baseAttributes); |
| 449 | + } |
| 450 | + } |
| 451 | + |
| 452 | + // Hedge counts |
| 453 | + if (module.resource.clientCallHedgesCounter() != null) { |
451 | 454 |
|
| 455 | + long hedgesPerCall = 0; |
| 456 | + long attempts = hedgedAttemptsPerCall.get(); |
| 457 | + if (attempts > 0) { |
| 458 | + hedgesPerCall = attempts - 1; |
| 459 | + } |
| 460 | + |
| 461 | + if (hedgesPerCall > 0) { |
| 462 | + module.resource.clientCallHedgesCounter().record(hedgesPerCall, baseAttributes); |
| 463 | + } |
| 464 | + } |
| 465 | + |
| 466 | + // Transparent Retry counts |
| 467 | + if (module.resource.clientCallTransparentRetriesCounter() != null |
| 468 | + && transparentRetriesPerCall.get() > 0) { |
452 | 469 | module.resource.clientCallRetriesCounter().record( |
453 | | - transparentRetriesPerCall.get(), |
454 | | - baseAttributes.toBuilder() |
455 | | - .put(RETRY_TYPE_KEY, OpenTelemetryConstants.RetryType.TRANSPARENT.getValue()) |
456 | | - .build() |
457 | | - ); |
| 470 | + transparentRetriesPerCall.get(), baseAttributes); |
458 | 471 | } |
459 | 472 |
|
460 | 473 | // Retry delay |
|
0 commit comments