8000 Update Google HttpClient to avoid activeScope() · DataDog/dd-trace-java@9603115 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9603115

Browse files
committed
Update Google HttpClient to avoid activeScope()
1 parent d59685c commit 9603115

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

dd-java-agent/instrumentation/google-http-client/src/main/java/datadog/trace/instrumentation/googlehttpclient/GoogleHttpClientInstrumentation.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
44
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
5-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
5+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
77
import static datadog.trace.instrumentation.googlehttpclient.GoogleHttpClientDecorator.DECORATE;
88
import static datadog.trace.instrumentation.googlehttpclient.GoogleHttpClientDecorator.HTTP_REQUEST;
@@ -60,17 +60,16 @@ public void methodAdvice(MethodTransformer transformer) {
6060
public static class GoogleHttpClientAdvice {
6161
@Advice.OnMethodEnter(suppress = Throwable.class)
6262
public static AgentScope methodEnter(
63-
@Advice.This HttpRequest request, @Advice.Local("inherited") boolean inheritedScope) {
64-
AgentScope scope = activeScope();
63+
@Advice.This HttpRequest request, @Advice.Local("inherited") AgentSpan inheritedSpan) {
64+
AgentSpan activeSpan = activeSpan();
6565
// detect if scope was propagated here by java-concurrent handling
6666
// of async requests
67-
if (null != scope) {
68-
AgentSpan span = scope.span();
67+
if (null != activeSpan) {
6968
// reference equality to check this instrumentation created the span,
7069
// not some other HTTP client
71-
if (HTTP_REQUEST == span.getOperationName()) {
72-
inheritedScope = true;
73-
return scope;
70+
if (HTTP_REQUEST == activeSpan.getOperationName()) {
71+
inheritedSpan = activeSpan;
72+
return null;
7473
}
7574
}
7675
return activateSpan(DECORATE.prepareSpan(startSpan(HTTP_REQUEST), request));
@@ -79,18 +78,18 @@ public static AgentScope methodEnter(
7978
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
8079
public static void methodExit(
8180
@Advice.Enter AgentScope scope,
82-
@Advice.Local("inherited") boolean inheritedScope,
81+
@Advice.Local("inherited") AgentSpan inheritedSpan,
8382
@Advice.Return final HttpResponse response,
8483
@Advice.Thrown final Throwable throwable) {
8584
try {
86-
AgentSpan span = scope.span();
85+
AgentSpan span = scope != null ? scope.span() : inheritedSpan;
8786
DECORATE.onError(span, throwable);
8887
DECORATE.onResponse(span, response);
8988

9089
DECORATE.beforeFinish(span);
9190
span.finish();
9291
} finally {
93-
if (!inheritedScope) {
92+
if (scope != null) {
9493
scope.close();
9594
}
9695
}

0 commit comments

Comments
 (0)
0