Skip to content

Commit 3888c68

Browse files
committed
Force adding a context if missing
1 parent 4c3504a commit 3888c68

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

dd-java-agent/instrumentation/apache-httpclient-5/src/main/java/datadog/trace/instrumentation/apachehttpclient5/ApacheHttpAsyncClientInstrumentation.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import net.bytebuddy.matcher.ElementMatcher;
2222
import org.apache.hc.core5.concurrent.FutureCallback;
2323
import org.apache.hc.core5.http.nio.AsyncRequestProducer;
24+
import org.apache.hc.core5.http.protocol.BasicHttpContext;
2425
import org.apache.hc.core5.http.protocol.HttpContext;
2526

2627
@AutoService(InstrumenterModule.class)
@@ -91,14 +92,18 @@ public static class ClientAdvice {
9192
@Advice.OnMethodEnter(suppress = Throwable.class)
9293
public static AgentScope methodEnter(
9394
@Advice.Argument(value = 0, readOnly = false) AsyncRequestProducer requestProducer,
94-
@Advice.Argument(3) HttpContext context,
95+
@Advice.Argument(value = 3, readOnly = false) HttpContext context,
9596
@Advice.Argument(value = 4, readOnly = false) FutureCallback<?> futureCallback) {
9697

9798
final AgentScope parentScope = activeScope();
9899
final AgentSpan clientSpan = startSpan(HTTP_REQUEST);
99100
final AgentScope clientScope = activateSpan(clientSpan);
100101
DECORATE.afterStart(clientSpan);
101102

103+
if (context == null) {
104+
context = new BasicHttpContext();
105+
}
106+
102107
requestProducer = new DelegatingRequestProducer(clientSpan, requestProducer);
103108
futureCallback =
104109
new TraceContinuedFutureCallback<>(parentScope, clientSpan, context, futureCallback);

0 commit comments

Comments
 (0)