19
19
20
20
import io .opentelemetry .context .Context ;
21
21
import io .opentelemetry .context .Scope ;
22
+ import io .opentelemetry .javaagent .bootstrap .CallDepth ;
22
23
import io .opentelemetry .javaagent .extension .instrumentation .TypeInstrumentation ;
23
24
import io .opentelemetry .javaagent .extension .instrumentation .TypeTransformer ;
25
+ import java .net .http .HttpClient ;
24
26
import java .net .http .HttpRequest ;
25
27
import java .net .http .HttpResponse ;
26
28
import java .util .concurrent .CompletableFuture ;
@@ -102,9 +104,15 @@ public static class SendAsyncAdvice {
102
104
public static void methodEnter (
103
105
@ Advice .Argument (value = 0 ) HttpRequest httpRequest ,
104
106
@ Advice .Argument (value = 1 , readOnly = false ) HttpResponse .BodyHandler <?> bodyHandler ,
107
+ @ Advice .Local ("otelCallDepth" ) CallDepth callDepth ,
105
108
@ Advice .Local ("otelContext" ) Context context ,
106
109
@ Advice .Local ("otelParentContext" ) Context parentContext ,
107
110
@ Advice .Local ("otelScope" ) Scope scope ) {
111
+ callDepth = CallDepth .forClass (HttpClient .class );
112
+ if (callDepth .getAndIncrement () > 0 ) {
113
+ return ;
114
+ }
115
+
108
116
parentContext = currentContext ();
109
117
if (bodyHandler != null ) {
110
118
bodyHandler = new BodyHandlerWrapper <>(bodyHandler , parentContext );
@@ -122,9 +130,14 @@ public static void methodExit(
122
130
@ Advice .Argument (value = 0 ) HttpRequest httpRequest ,
123
131
@ Advice .Return (readOnly = false ) CompletableFuture <HttpResponse <?>> future ,
124
132
@ Advice .Thrown Throwable throwable ,
133
+ @ Advice .Local ("otelCallDepth" ) CallDepth callDepth ,
125
134
@ Advice .Local ("otelContext" ) Context context ,
126
135
@ Advice .Local ("otelParentContext" ) Context parentContext ,
127
136
@ Advice .Local ("otelScope" ) Scope scope ) {
137
+ if (callDepth .decrementAndGet () > 0 ) {
138
+ return ;
139
+ }
140
+
128
141
if (scope == null ) {
129
142
return ;
130
143
}
0 commit comments