Skip to content

Commit bea20a2

Browse files
committed
Migrate AWS SDKv2 to use closeActive() to close outstanding spans
1 parent 20d21cd commit bea20a2

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsHttpClientInstrumentation.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
66
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.namedOneOf;
77
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
8-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
8+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
9+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.closeActive;
910
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
1011
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
1112
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -14,7 +15,9 @@
1415
import com.google.auto.service.AutoService;
1516
import datadog.trace.agent.tooling.Instrumenter;
1617
import datadog.trace.agent.tooling.InstrumenterModule;
17-
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
18+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
19+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
20+
import datadog.trace.context.TraceScope;
1821
import net.bytebuddy.asm.Advice;
1922
import net.bytebuddy.description.type.TypeDescription;
2023
import net.bytebuddy.matcher.ElementMatcher;
@@ -69,27 +72,29 @@ public static class AwsHttpClientAdvice {
6972
* stored in channel attributes.
7073
*/
7174
@Advice.OnMethodEnter(suppress = Throwable.class)
72-
public static AgentScope methodEnter(
75+
public static TraceScope methodEnter(
7376
@Advice.This final Object thiz,
7477
@Advice.Argument(1) final RequestExecutionContext requestExecutionContext) {
75-
final AgentScope scope = activeScope();
78+
final AgentSpan activeSpan = activeSpan();
7679
// check name in case TracingExecutionInterceptor failed to activate the span
77-
if (scope != null
78-
&& ((!scope.span().isValid())
80+
if (activeSpan != null
81+
&& ((!activeSpan.isValid())
7982
|| AwsSdkClientDecorator.DECORATE
8083
.spanName(requestExecutionContext.executionAttributes())
81-
.equals(scope.span().getSpanName()))) {
84+
.equals(activeSpan.getSpanName()))) {
8285
if (thiz instanceof MakeAsyncHttpRequestStage) {
83-
scope.close(); // close async legacy HTTP span to avoid Netty leak
86+
// close async legacy HTTP span to avoid Netty leak...
87+
closeActive(); // then drop-through and activate no-op span
8488
} else {
85-
return scope; // keep sync legacy HTTP span alive for duration of call
89+
// keep sync legacy HTTP span alive for duration of call
90+
return AgentTracer::closeActive;
8691
}
8792
}
8893
return activateSpan(noopSpan());
8994
}
9095

9196
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
92-
public static void methodExit(@Advice.Enter final AgentScope scope) {
97+
public static void methodExit(@Advice.Enter final TraceScope scope) {
9398
scope.close();
9499
}
95100

0 commit comments

Comments
 (0)