2
2
3
3
import static datadog .trace .agent .tooling .bytebuddy .matcher .NameMatchers .named ;
4
4
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 ;
6
6
import static datadog .trace .bootstrap .instrumentation .api .AgentTracer .startSpan ;
7
7
import static datadog .trace .instrumentation .googlehttpclient .GoogleHttpClientDecorator .DECORATE ;
8
8
import static datadog .trace .instrumentation .googlehttpclient .GoogleHttpClientDecorator .HTTP_REQUEST ;
@@ -60,17 +60,16 @@ public void methodAdvice(MethodTransformer transformer) {
60
60
public static class GoogleHttpClientAdvice {
61
61
@ Advice .OnMethodEnter (suppress = Throwable .class )
62
62
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 ();
65
65
// detect if scope was propagated here by java-concurrent handling
66
66
// of async requests
67
- if (null != scope ) {
68
- AgentSpan span = scope .span ();
67
+ if (null != activeSpan ) {
69
68
// reference equality to check this instrumentation created the span,
70
69
// 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 ;
74
73
}
75
74
}
76
75
return activateSpan (DECORATE .prepareSpan (startSpan (HTTP_REQUEST ), request ));
@@ -79,18 +78,18 @@ public static AgentScope methodEnter(
79
78
@ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
80
79
public static void methodExit (
81
80
@ Advice .Enter AgentScope scope ,
82
- @ Advice .Local ("inherited" ) boolean inheritedScope ,
81
+ @ Advice .Local ("inherited" ) AgentSpan inheritedSpan ,
83
82
@ Advice .Return final HttpResponse response ,
84
83
@ Advice .Thrown final Throwable throwable ) {
85
84
try {
86
- AgentSpan span = scope .span ();
85
+ AgentSpan span = scope != null ? scope .span () : inheritedSpan ;
87
86
DECORATE .onError (span , throwable );
88
87
DECORATE .onResponse (span , response );
89
88
90
89
DECORATE .beforeFinish (span );
91
90
span .finish ();
92
91
} finally {
93
- if (! inheritedScope ) {
92
+ if (scope != null ) {
94
93
scope .close ();
95
94
}
96
95
}
0 commit comments