Skip to content

Commit 0ee33ae

Browse files
committed
Migrate Undertow to use closeActive() to close outstanding spans
1 parent 2b476c5 commit 0ee33ae

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

dd-java-agent/instrumentation/undertow/undertow-2.0/src/main/java/datadog/trace/instrumentation/undertow/HttpRequestParserInstrumentation.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.extendsClass;
44
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
55
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
6-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
6+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
7+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.closeActive;
78
import static datadog.trace.instrumentation.undertow.UndertowDecorator.DECORATE;
89
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
910
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -71,12 +72,10 @@ public static void afterRequestParse(
7172
// a span
7273
// this because undertow will just write down a http 400 raw response over the net channel.
7374
// Here we try to create a span to record this
74-
AgentScope scope = activeScope();
75-
AgentSpan span = null;
75+
AgentSpan span = activeSpan();
76+
AgentScope scope = null;
7677
try {
77-
if (scope != null) {
78-
span = scope.span();
79-
} else {
78+
if (span == null) {
8079
final AgentSpanContext.Extracted extractedContext = DECORATE.extract(exchange);
8180
span = DECORATE.startSpan(exchange, extractedContext).setMeasured(true);
8281
scope = activateSpan(span);
@@ -90,9 +89,11 @@ public static void afterRequestParse(
9089
} finally {
9190
if (span != null) {
9291
span.finish();
93-
}
94-
if (scope != null) {
95-
scope.close();
92+
if (scope != null) {
93+
scope.close();
94+
} else {
95+
closeActive();
96+
}
9697
}
9798
}
9899
}

0 commit comments

Comments
 (0)