Skip to content

Commit 553b4fe

Browse files
committed
fix(tracing): record CancellationException on lingering attempt when superseded by retry
1 parent b542ff1 commit 553b4fe

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTracingTracer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public void attemptStarted(Object request, int attemptNumber) {
243243
}
244244
// End lingering previous attempt outside the lock to avoid holding the lock during callbacks.
245245
if (oldSpan != null) {
246-
endSpan(oldSpan, null);
246+
endSpan(oldSpan, new CancellationException("Attempt superseded by retry"));
247247
}
248248
}
249249

‎sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpenTelemetryTracingTracerTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ void testAttemptStarted_whenPreviousAttemptActive_closesOldSpan() {
799799

800800
// Start a second attempt before the first attempt was ended
801801
openTelemetryTracingTracer.attemptStarted(new Object(), 1);
802+
verify(span1).recordException(any(java.util.concurrent.CancellationException.class));
803+
verify(span1).setStatus(io.opentelemetry.api.trace.StatusCode.ERROR);
802804
verify(span1).end();
803805
verify(span2, never()).end();
804806

0 commit comments

Comments
 (0)