Skip to content

Commit e8eddc2

Browse files
authored
Migrating all HttpClient Instrumentations to Inject Full Context (#8826)
* adding support for Akka * updating support for akka * spotless * updating more instrumentations * spotless * supporting more integrations * supporting more integrations 2 * updating final client instrumentations * PR comments * lint
1 parent 0f42e0a commit e8eddc2

File tree

26 files changed

+58
-30
lines changed

26 files changed

+58
-30
lines changed

dd-java-agent/instrumentation/akka-http/akka-http-10.0/src/main/java/datadog/trace/instrumentation/akkahttp/AkkaHttpSingleRequestInstrumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
55
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
7+
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
78
import static datadog.trace.bootstrap.instrumentation.decorator.HttpClientDecorator.CLIENT_PATHWAY_EDGE_TAGS;
89
import static datadog.trace.instrumentation.akkahttp.AkkaHttpClientDecorator.AKKA_CLIENT_REQUEST;
910
import static datadog.trace.instrumentation.akkahttp.AkkaHttpClientDecorator.DECORATE;
@@ -80,7 +81,8 @@ public static AgentScope methodEnter(
8081

8182
if (request != null) {
8283
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
83-
defaultPropagator().inject(span.with(dsmContext), request, headers);
84+
defaultPropagator()
85+
.inject(getCurrentContext().with(span).with(dsmContext), request, headers);
8486
// Request is immutable, so we have to assign new value once we update headers
8587
request = headers.getRequest();
8688
}

dd-java-agent/instrumentation/akka-http/akka-http-10.6/src/main/java11/datadog/trace/instrumentation/akkahttp106/SingleRequestAdvice.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static datadog.context.propagation.Propagators.defaultPropagator;
44
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
55
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
6+
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
67
import static datadog.trace.bootstrap.instrumentation.decorator.HttpClientDecorator.CLIENT_PATHWAY_EDGE_TAGS;
78

89
import akka.http.scaladsl.HttpExt;
@@ -30,7 +31,7 @@ public static AgentScope methodEnter(
3031

3132
if (request != null) {
3233
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
33-
defaultPropagator().inject(span.with(dsmContext), request, headers);
34+
defaultPropagator().inject(getCurrentContext().with(span).with(dsmContext), request, headers);
3435
// Request is immutable, so we have to assign new value once we update headers
3536
request = headers.getRequest();
3637
}

dd-java-agent/instrumentation/apache-httpasyncclient-4/src/main/java/datadog/trace/instrumentation/apachehttpasyncclient/DelegatingRequestProducer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static datadog.trace.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator.DECORATE;
66
import static datadog.trace.instrumentation.apachehttpasyncclient.HttpHeadersInjectAdapter.SETTER;
77

8+
import datadog.context.Context;
89
import datadog.trace.api.datastreams.DataStreamsContext;
910
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1011
import java.io.IOException;
@@ -36,7 +37,7 @@ public HttpRequest generateRequest() throws IOException, HttpException {
3637
DECORATE.onRequest(span, new HostAndRequestAsHttpUriRequest(delegate.getTarget(), request));
3738

3839
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
39-
defaultPropagator().inject(span.with(dsmContext), request, SETTER);
40+
defaultPropagator().inject(Context.current().with(span).with(dsmContext), request, SETTER);
4041

4142
return request;
4243
}

dd-java-agent/instrumentation/apache-httpclient-4/src/main/java/datadog/trace/instrumentation/apachehttpclient/HelperMethods.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientDecorator.HTTP_REQUEST;
99
import static datadog.trace.instrumentation.apachehttpclient.HttpHeadersInjectAdapter.SETTER;
1010

11+
import datadog.context.Context;
1112
import datadog.trace.api.datastreams.DataStreamsContext;
1213
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
1314
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
@@ -47,7 +48,7 @@ private static AgentScope activateHttpSpan(final HttpUriRequest request) {
4748
// AWS calls are often signed, so we can't add headers without breaking the signature.
4849
if (!awsClientCall) {
4950
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
50-
defaultPropagator().inject(span.with(dsmContext), request, SETTER);
51+
defaultPropagator().inject(Context.current().with(span).with(dsmContext), request, SETTER);
5152
}
5253

5354
return scope;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static datadog.trace.instrumentation.apachehttpclient5.ApacheHttpClientDecorator.DECORATE;
66
import static datadog.trace.instrumentation.apachehttpclient5.HttpHeadersInjectAdapter.SETTER;
77

8+
import datadog.context.Context;
89
import datadog.trace.api.datastreams.DataStreamsContext;
910
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1011
import java.io.IOException;
@@ -29,7 +30,7 @@ public void sendRequest(HttpRequest request, EntityDetails entityDetails, HttpCo
2930
DECORATE.onRequest(span, request);
3031

3132
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
32-
defaultPropagator().inject(span.with(dsmContext), request, SETTER);
33+
defaultPropagator().inject(Context.current().with(span).with(dsmContext), request, SETTER);
3334
delegate.sendRequest(request, entityDetails, context);
3435
}
3536
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static datadog.trace.instrumentation.apachehttpclient5.ApacheHttpClientDecorator.HTTP_REQUEST;
99
import static datadog.trace.instrumentation.apachehttpclient5.HttpHeadersInjectAdapter.SETTER;
1010

11+
import datadog.context.Context;
1112
import datadog.trace.api.datastreams.DataStreamsContext;
1213
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
1314
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
@@ -47,7 +48,7 @@ private static AgentScope activateHttpSpan(final HttpRequest request) {
4748
// AWS calls are often signed, so we can't add headers without breaking the signature.
4849
if (!awsClientCall) {
4950
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
50-
defaultPropagator().inject(span.with(dsmContext), request, SETTER);
51+
defaultPropagator().inject(Context.current().with(span).with(dsmContext), request, SETTER);
5152
}
5253

5354
return scope;

dd-java-agent/instrumentation/commons-httpclient-2/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientInstrumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
55
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
7+
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
78
import static datadog.trace.bootstrap.instrumentation.decorator.HttpClientDecorator.CLIENT_PATHWAY_EDGE_TAGS;
89
import static datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator.DECORATE;
910
import static datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator.HTTP_REQUEST;
@@ -70,7 +71,8 @@ public static AgentScope methodEnter(@Advice.Argument(1) final HttpMethod httpMe
7071
DECORATE.afterStart(span);
7172
DECORATE.onRequest(span, httpMethod);
7273
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
73-
defaultPropagator().inject(span.with(dsmContext), httpMethod, SETTER);
74+
defaultPropagator()
75+
.inject(getCurrentContext().with(span).with(dsmContext), httpMethod, SETTER);
7476

7577
return scope;
7678
} catch (BlockingException e) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.google.api.client.http.HttpRequest;
77
import com.google.api.client.http.HttpResponse;
8+
import datadog.context.Context;
89
import datadog.trace.api.datastreams.DataStreamsContext;
910
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1011
import datadog.trace.bootstrap.instrumentation.api.URIUtils;
@@ -39,7 +40,7 @@ public AgentSpan prepareSpan(AgentSpan span, HttpRequest request) {
3940
DECORATE.afterStart(span);
4041
DECORATE.onRequest(span, request);
4142
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
42-
defaultPropagator().inject(span.with(dsmContext), request, SETTER);
43+
defaultPropagator().inject(Context.current().with(span).with(dsmContext), request, SETTER);
4344
return span;
4445
}
4546

dd-java-agent/instrumentation/grizzly-client-1.9/src/main/java/datadog/trace/instrumentation/grizzly/client/AsyncHttpClientInstrumentation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
55
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
7+
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
78
import static datadog.trace.bootstrap.instrumentation.decorator.HttpClientDecorator.CLIENT_PATHWAY_EDGE_TAGS;
89
import static datadog.trace.instrumentation.grizzly.client.ClientDecorator.DECORATE;
910
import static datadog.trace.instrumentation.grizzly.client.ClientDecorator.HTTP_REQUEST;
@@ -70,7 +71,7 @@ public static void onEnter(
7071
DECORATE.afterStart(span);
7172
DECORATE.onRequest(span, request);
7273
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
73-
defaultPropagator().inject(span.with(dsmContext), request, SETTER);
74+
defaultPropagator().inject(getCurrentContext().with(span).with(dsmContext), request, SETTER);
7475
handler = new AsyncHandlerAdapter<>(span, parentSpan, handler);
7576
}
7677
}

dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/HttpUrlConnectionInstrumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static datadog.context.propagation.Propagators.defaultPropagator;
44
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
55
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.namedOneOf;
6+
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
67
import static datadog.trace.bootstrap.instrumentation.decorator.HttpClientDecorator.CLIENT_PATHWAY_EDGE_TAGS;
78
import static datadog.trace.bootstrap.instrumentation.httpurlconnection.HeadersInjectAdapter.SETTER;
89
import static java.util.Collections.singletonMap;
@@ -87,7 +88,8 @@ public static HttpUrlState methodEnter(
8788
final AgentSpan span = state.start(thiz);
8889
if (!connected) {
8990
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
90-
defaultPropagator().inject(span.with(dsmContext), thiz, SETTER);
91+
defaultPropagator()
92+
.inject(getCurrentContext().with(span).with(dsmContext), thiz, SETTER);
9193
}
9294
}
9395
return state;

0 commit comments

Comments
 (0)