Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -225,21 +226,22 @@ private void recordErrorAndEndAttempt(@Nullable Throwable error) {
attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(responseAttributes));
}

if (error != null && !Strings.isNullOrEmpty(error.getMessage())) {
attemptSpan.setAttribute(
ObservabilityAttributes.STATUS_MESSAGE_ATTRIBUTE, error.getMessage());
if (error != null) {
attemptSpan.setStatus(StatusCode.ERROR);
if (!Strings.isNullOrEmpty(error.getMessage())) {
attemptSpan.setAttribute(
ObservabilityAttributes.STATUS_MESSAGE_ATTRIBUTE, error.getMessage());
}
}
Comment thread
jinseopkim0 marked this conversation as resolved.

endAttempt();
}

private void endAttempt() {
if (attemptSpan == null) {
return;
if (attemptSpan != null) {
attemptSpan.end();
attemptSpan = null;
}

attemptSpan.end();
attemptSpan = null;
}
Comment thread
jinseopkim0 marked this conversation as resolved.
Comment thread
jinseopkim0 marked this conversation as resolved.

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ void testAttemptLifecycle_startsAndEndsAttemptSpan() {
verify(span).end();
}

@Test
void testAttemptFailed_setsErrorStatus() {
openTelemetryTracingTracer.attemptStarted(new Object(), 1);
openTelemetryTracingTracer.attemptFailedDuration(
new RuntimeException("Test error"), java.time.Duration.ofSeconds(1));

verify(span).setStatus(io.opentelemetry.api.trace.StatusCode.ERROR);
verify(span).end();
}
Comment thread
jinseopkim0 marked this conversation as resolved.

@Test
void testAttemptSucceeded_grpc() {
ApiTracerContext context =
Expand Down
Loading