From b8ef52f3b45c5afc80a1452c6cd8210b27d250fe Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 13 Aug 2020 21:20:27 -0700 Subject: [PATCH 01/20] Tracers and Setters --- .../webclient/WebClientAutoConfiguration.java | 10 ++++- .../webclient/WebClientBeanPostProcessor.java | 6 +-- .../httpclients/HttpHeadersInjectAdapter.java | 8 ++-- .../httpclients/RestTemplateInterceptor.java | 2 +- .../httpclients/RestTemplateTracer.java | 14 ++----- .../client/HttpHeadersInjectAdapter.java | 8 ++-- .../client/SpringWebfluxHttpClientTracer.java | 20 ++++----- .../client/WebClientTracingFilter.java | 20 ++++----- .../AkkaHttpClientInstrumentation.java | 41 +++++++++---------- .../auto/akkahttp/AkkaHttpClientTracer.java | 10 +++-- .../ApacheHttpAsyncClientTracer.java | 3 +- .../v2_0/CommonsHttpClientTracer.java | 2 +- .../v4_0/ApacheHttpClientTracer.java | 3 +- .../v1_0/client/ArmeriaClientTracer.java | 3 +- .../auto/awssdk/v1_11/AwsSdkClientTracer.java | 2 +- .../awssdk/v2_2/AwsSdkClientTracer.java | 3 +- .../GoogleHttpClientInstrumentation.java | 4 +- .../GoogleHttpClientTracer.java | 5 ++- .../HeadersInjectAdapter.java | 8 ++-- .../grizzly/client/GrizzlyClientTracer.java | 6 ++- .../grizzly/client/GrizzlyInjectAdapter.java | 10 +++-- .../HttpUrlConnectionInstrumentation.java | 16 ++++---- .../HttpUrlConnectionTracer.java | 7 +++- .../auto/jaxrsclient/v1_1/InjectAdapter.java | 8 ++-- .../jaxrsclient/v1_1/JaxRsClientV1Tracer.java | 6 ++- .../jaxrsclient/v2_0/ClientTracingFilter.java | 14 ++----- .../jaxrsclient/v2_0/JaxRsClientTracer.java | 9 ++-- .../auto/khttp/KHttpAdvice.java | 9 +--- .../auto/khttp/KHttpTracer.java | 9 ++-- .../KubernetesClientTracer.java | 3 +- .../v3_8/client/NettyHttpClientTracer.java | 21 +++------- .../HttpClientRequestTracingHandler.java | 29 ++++--------- .../v4_0/client/NettyHttpClientTracer.java | 30 +++++++++----- .../v4_1/client/NettyHttpClientTracer.java | 21 +++------- .../auto/okhttp/v2_2/OkHttpClientTracer.java | 8 ++-- .../auto/okhttp/v2_2/TracingInterceptor.java | 10 +---- .../auto/okhttp/v3_0/OkHttpClientTracer.java | 8 ++-- .../v2_0/PlayWSClientInstrumentation.java | 10 ++--- .../auto/playws/HeadersInjectAdapter.java | 8 ++-- .../auto/playws/PlayWSClientTracer.java | 5 ++- .../api/decorator/HttpClientTracer.java | 10 ++--- 41 files changed, 203 insertions(+), 226 deletions(-) diff --git a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java index 3cc2bfff75ac..3e9f0eb70275 100644 --- a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java +++ b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java @@ -17,6 +17,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webclient; import io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.HttpClientsProperties; +import io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer; import io.opentelemetry.trace.Tracer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -42,7 +43,14 @@ public class WebClientAutoConfiguration { @Bean @Autowired - public WebClientBeanPostProcessor otelWebClientBeanPostProcessor(final Tracer tracer) { + public SpringWebfluxHttpClientTracer otelSpringWebfluxHttpClientTracer(final Tracer tracer) { + return new SpringWebfluxHttpClientTracer(tracer); + } + + @Bean + @Autowired + public WebClientBeanPostProcessor otelWebClientBeanPostProcessor( + final SpringWebfluxHttpClientTracer tracer) { return new WebClientBeanPostProcessor(tracer); } } diff --git a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java index b218abe63a55..b988ba09c11f 100644 --- a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java +++ b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java @@ -16,8 +16,8 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webclient; +import io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer; import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter; -import io.opentelemetry.trace.Tracer; import java.util.List; import java.util.function.Consumer; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -31,9 +31,9 @@ */ final class WebClientBeanPostProcessor implements BeanPostProcessor { - private final Tracer tracer; + private final SpringWebfluxHttpClientTracer tracer; - WebClientBeanPostProcessor(Tracer tracer) { + WebClientBeanPostProcessor(SpringWebfluxHttpClientTracer tracer) { this.tracer = tracer; } diff --git a/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/HttpHeadersInjectAdapter.java b/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/HttpHeadersInjectAdapter.java index ec3718f50c65..fa5069a3fefa 100644 --- a/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/HttpHeadersInjectAdapter.java +++ b/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/HttpHeadersInjectAdapter.java @@ -17,14 +17,14 @@ package io.opentelemetry.instrumentation.spring.httpclients; import io.opentelemetry.context.propagation.HttpTextFormat; -import org.springframework.http.HttpRequest; +import org.springframework.http.HttpHeaders; -class HttpHeadersInjectAdapter implements HttpTextFormat.Setter { +class HttpHeadersInjectAdapter implements HttpTextFormat.Setter { public static final HttpHeadersInjectAdapter SETTER = new HttpHeadersInjectAdapter(); @Override - public void set(HttpRequest carrier, String key, String value) { - carrier.getHeaders().set(key, value); + public void set(HttpHeaders carrier, String key, String value) { + carrier.set(key, value); } } diff --git a/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateInterceptor.java b/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateInterceptor.java index efded28a5f74..feb08c45cb7d 100644 --- a/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateInterceptor.java +++ b/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateInterceptor.java @@ -41,7 +41,7 @@ public ClientHttpResponse intercept( HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { Span span = TRACER.startSpan(request); - try (Scope scope = TRACER.startScope(span, request)) { + try (Scope scope = TRACER.startScope(span, request.getHeaders())) { ClientHttpResponse response = execution.execute(request, body); TRACER.end(span, response); return response; diff --git a/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateTracer.java b/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateTracer.java index a61afbfef041..7d0045a63bc8 100644 --- a/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateTracer.java +++ b/instrumentation-core/spring/spring-web-3.1/src/main/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateTracer.java @@ -16,34 +16,28 @@ package io.opentelemetry.instrumentation.spring.httpclients; -import static io.opentelemetry.OpenTelemetry.getPropagators; import static io.opentelemetry.instrumentation.spring.httpclients.HttpHeadersInjectAdapter.SETTER; -import io.grpc.Context; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; -class RestTemplateTracer extends HttpClientTracer { +class RestTemplateTracer extends HttpClientTracer { public static final RestTemplateTracer TRACER = new RestTemplateTracer(); - public void inject(Context context, HttpRequest request) { - getPropagators().getHttpTextFormat().inject(context, request, getSetter()); - } - @Override protected String method(final HttpRequest httpRequest) { return httpRequest.getMethod().name(); } @Override - protected URI url(HttpRequest request) throws URISyntaxException { + protected URI url(HttpRequest request) { return request.getURI(); } @@ -67,7 +61,7 @@ protected String responseHeader(ClientHttpResponse response, String name) { } @Override - protected Setter getSetter() { + protected Setter getSetter() { return SETTER; } diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/HttpHeadersInjectAdapter.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/HttpHeadersInjectAdapter.java index dd5d92d71a50..ede293bfadbb 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/HttpHeadersInjectAdapter.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/HttpHeadersInjectAdapter.java @@ -17,14 +17,14 @@ package io.opentelemetry.instrumentation.spring.webflux.client; import io.opentelemetry.context.propagation.HttpTextFormat; -import org.springframework.http.HttpHeaders; +import org.springframework.web.reactive.function.client.ClientRequest; -class HttpHeadersInjectAdapter implements HttpTextFormat.Setter { +class HttpHeadersInjectAdapter implements HttpTextFormat.Setter { public static final HttpHeadersInjectAdapter SETTER = new HttpHeadersInjectAdapter(); @Override - public void set(final HttpHeaders carrier, final String key, final String value) { - carrier.set(key, value); + public void set(final ClientRequest.Builder carrier, final String key, final String value) { + carrier.header(key, value); } } diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java index eb00f709abe4..cbfc1d6b168a 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java @@ -16,33 +16,33 @@ package io.opentelemetry.instrumentation.spring.webflux.client; -import static io.opentelemetry.OpenTelemetry.getPropagators; import static io.opentelemetry.instrumentation.spring.webflux.client.HttpHeadersInjectAdapter.SETTER; -import io.grpc.Context; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import io.opentelemetry.trace.Span; import io.opentelemetry.trace.Tracer; import java.net.URI; import java.util.List; -import org.springframework.http.HttpHeaders; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; -class SpringWebfluxHttpClientTracer extends HttpClientTracer { +public class SpringWebfluxHttpClientTracer + extends HttpClientTracer { public static final SpringWebfluxHttpClientTracer TRACER = new SpringWebfluxHttpClientTracer(); + public SpringWebfluxHttpClientTracer(Tracer tracer) { + super(tracer); + } + + public SpringWebfluxHttpClientTracer() {} + public void onCancel(final Span span) { span.setAttribute("event", "cancelled"); span.setAttribute("message", "The subscription was cancelled"); } - public void inject(Context context, HttpHeaders httpHeaders) { - getPropagators().getHttpTextFormat().inject(context, httpHeaders, SETTER); - } - @Override protected String method(final ClientRequest httpRequest) { return httpRequest.method().name(); @@ -70,8 +70,8 @@ protected String responseHeader(ClientResponse clientResponse, String name) { } @Override - protected Setter getSetter() { - return null; + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java index 22823e8ebdfd..74ffce6ed543 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java @@ -18,10 +18,8 @@ import static io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer.TRACER; -import io.grpc.Context; import io.opentelemetry.context.Scope; import io.opentelemetry.trace.Span; -import io.opentelemetry.trace.Tracer; import java.util.List; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; @@ -31,18 +29,19 @@ public class WebClientTracingFilter implements ExchangeFilterFunction { - private final Tracer tracer; + private final SpringWebfluxHttpClientTracer tracer; - public WebClientTracingFilter(Tracer tracer) { + public WebClientTracingFilter(SpringWebfluxHttpClientTracer tracer) { this.tracer = tracer; } public static void addFilter(final List exchangeFilterFunctions) { - addFilter(exchangeFilterFunctions, TRACER.getTracer()); + addFilter(exchangeFilterFunctions, TRACER); } public static void addFilter( - final List exchangeFilterFunctions, Tracer tracer) { + final List exchangeFilterFunctions, + SpringWebfluxHttpClientTracer tracer) { exchangeFilterFunctions.add(0, new WebClientTracingFilter(tracer)); } @@ -50,12 +49,9 @@ public static void addFilter( public Mono filter(final ClientRequest request, final ExchangeFunction next) { Span span = TRACER.startSpan(request); - try (Scope scope = tracer.withSpan(span)) { - ClientRequest mutatedRequest = - ClientRequest.from(request) - .headers(httpHeaders -> TRACER.inject(Context.current(), httpHeaders)) - .build(); - return next.exchange(mutatedRequest) + ClientRequest.Builder requestBuilder = ClientRequest.from(request); + try (Scope scope = TRACER.startScope(span, requestBuilder)) { + return next.exchange(requestBuilder.build()) .doOnSuccessOrError( (clientResponse, throwable) -> { if (throwable != null) { diff --git a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java index bb10bce43dcc..d34363f1a145 100644 --- a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java +++ b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java @@ -16,9 +16,7 @@ package io.opentelemetry.instrumentation.auto.akkahttp; -import static io.opentelemetry.context.ContextUtils.withScopedContext; import static io.opentelemetry.instrumentation.auto.akkahttp.AkkaHttpClientTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; @@ -27,8 +25,6 @@ import akka.http.scaladsl.model.HttpRequest; import akka.http.scaladsl.model.HttpResponse; import com.google.auto.service.AutoService; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.auto.tooling.Instrumenter; import io.opentelemetry.context.Scope; import io.opentelemetry.context.propagation.HttpTextFormat; @@ -95,15 +91,10 @@ public static void methodEnter( callDepth = TRACER.getCallDepth(); if (callDepth.getAndIncrement() == 0) { span = TRACER.startSpan(request); - - Context context = withSpan(span, Context.current()); - if (request != null) { - AkkaHttpHeaders headers = new AkkaHttpHeaders(request); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, headers); - // Request is immutable, so we have to assign new value once we update headers - request = headers.getRequest(); - } - scope = withScopedContext(context); + // Request is immutable, so we have to assign new value once we update headers + AkkaHttpHeaders headers = new AkkaHttpHeaders(request); + scope = TRACER.startScope(span, headers); + request = headers.getRequest(); } } @@ -145,21 +136,29 @@ public Void apply(final Try result) { } } - public static class AkkaHttpHeaders implements HttpTextFormat.Setter { + public static class AkkaHttpHeaders { private HttpRequest request; - public AkkaHttpHeaders(final HttpRequest request) { + public AkkaHttpHeaders(HttpRequest request) { this.request = request; } - @Override - public void set(final HttpRequest carrier, final String key, final String value) { - // It looks like this cast is only needed in Java, Scala would have figured it out - request = (HttpRequest) request.addHeader(RawHeader.create(key, value)); - } - public HttpRequest getRequest() { return request; } + + public void setRequest(HttpRequest request) { + this.request = request; + } + } + + public static class InjectAdapter implements HttpTextFormat.Setter { + + public static final InjectAdapter SETTER = new InjectAdapter(); + + @Override + public void set(final AkkaHttpHeaders carrier, final String key, final String value) { + carrier.setRequest(carrier.getRequest().addHeader(RawHeader.create(key, value))); + } } } diff --git a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientTracer.java b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientTracer.java index 5627e6b21629..a5b8497d21e9 100644 --- a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientTracer.java +++ b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientTracer.java @@ -16,18 +16,22 @@ package io.opentelemetry.instrumentation.auto.akkahttp; +import static io.opentelemetry.instrumentation.auto.akkahttp.AkkaHttpClientInstrumentation.InjectAdapter.SETTER; + import akka.http.javadsl.model.HttpHeader; import akka.http.scaladsl.HttpExt; import akka.http.scaladsl.model.HttpRequest; import akka.http.scaladsl.model.HttpResponse; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; +import io.opentelemetry.instrumentation.auto.akkahttp.AkkaHttpClientInstrumentation.AkkaHttpHeaders; import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap; import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap.Depth; import java.net.URI; import java.net.URISyntaxException; -public class AkkaHttpClientTracer extends HttpClientTracer { +public class AkkaHttpClientTracer + extends HttpClientTracer { public static final AkkaHttpClientTracer TRACER = new AkkaHttpClientTracer(); public Depth getCallDepth() { @@ -60,8 +64,8 @@ protected String responseHeader(HttpResponse httpResponse, String name) { } @Override - protected Setter getSetter() { - return null; + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientTracer.java b/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientTracer.java index e5583068433a..96894a073e2d 100644 --- a/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientTracer.java +++ b/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientTracer.java @@ -32,7 +32,8 @@ import org.apache.http.StatusLine; import org.apache.http.client.methods.HttpUriRequest; -public class ApacheHttpAsyncClientTracer extends HttpClientTracer { +public class ApacheHttpAsyncClientTracer + extends HttpClientTracer { public static final ApacheHttpAsyncClientTracer TRACER = new ApacheHttpAsyncClientTracer(); diff --git a/instrumentation/apache-httpclient/apache-httpclient-2.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v2_0/CommonsHttpClientTracer.java b/instrumentation/apache-httpclient/apache-httpclient-2.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v2_0/CommonsHttpClientTracer.java index 8085fbaa1ee9..99a16fb0e34f 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-2.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v2_0/CommonsHttpClientTracer.java +++ b/instrumentation/apache-httpclient/apache-httpclient-2.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v2_0/CommonsHttpClientTracer.java @@ -28,7 +28,7 @@ import org.apache.commons.httpclient.StatusLine; import org.apache.commons.httpclient.URIException; -public class CommonsHttpClientTracer extends HttpClientTracer { +public class CommonsHttpClientTracer extends HttpClientTracer { public static final CommonsHttpClientTracer TRACER = new CommonsHttpClientTracer(); @Override diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v4_0/ApacheHttpClientTracer.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v4_0/ApacheHttpClientTracer.java index ceace87a61b4..d9e13688d2a1 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v4_0/ApacheHttpClientTracer.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpclient/v4_0/ApacheHttpClientTracer.java @@ -27,7 +27,8 @@ import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpUriRequest; -class ApacheHttpClientTracer extends HttpClientTracer { +class ApacheHttpClientTracer + extends HttpClientTracer { public static final ApacheHttpClientTracer TRACER = new ApacheHttpClientTracer(); diff --git a/instrumentation/armeria-1.0/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_0/client/ArmeriaClientTracer.java b/instrumentation/armeria-1.0/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_0/client/ArmeriaClientTracer.java index 60f42e8fa821..2f6956742356 100644 --- a/instrumentation/armeria-1.0/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_0/client/ArmeriaClientTracer.java +++ b/instrumentation/armeria-1.0/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_0/client/ArmeriaClientTracer.java @@ -24,7 +24,8 @@ import java.net.URI; import java.net.URISyntaxException; -public class ArmeriaClientTracer extends HttpClientTracer { +public class ArmeriaClientTracer + extends HttpClientTracer { ArmeriaClientTracer() {} diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/src/main/java/io/opentelemetry/instrumentation/auto/awssdk/v1_11/AwsSdkClientTracer.java b/instrumentation/aws-sdk/aws-sdk-1.11/src/main/java/io/opentelemetry/instrumentation/auto/awssdk/v1_11/AwsSdkClientTracer.java index 89a0dc3f8ab4..95f71ff4e804 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/src/main/java/io/opentelemetry/instrumentation/auto/awssdk/v1_11/AwsSdkClientTracer.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/src/main/java/io/opentelemetry/instrumentation/auto/awssdk/v1_11/AwsSdkClientTracer.java @@ -32,7 +32,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public class AwsSdkClientTracer extends HttpClientTracer, Response> { +public class AwsSdkClientTracer extends HttpClientTracer, Request, Response> { static final String COMPONENT_NAME = "java-aws-sdk"; diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkClientTracer.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkClientTracer.java index 23bf611a5aee..733ca2414250 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkClientTracer.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkClientTracer.java @@ -29,7 +29,8 @@ import software.amazon.awssdk.http.SdkHttpRequest; import software.amazon.awssdk.http.SdkHttpResponse; -final class AwsSdkClientTracer extends HttpClientTracer { +final class AwsSdkClientTracer + extends HttpClientTracer { static final AwsSdkClientTracer TRACER = new AwsSdkClientTracer(); // Certain headers in the request like User-Agent are only available after execution. diff --git a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java index 2b552e949702..41fa1b01aa39 100644 --- a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java +++ b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java @@ -106,7 +106,9 @@ public static void methodEnter(@Advice.This final HttpRequest request) { Span span = state.getSpan(); Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, SETTER); + OpenTelemetry.getPropagators() + .getHttpTextFormat() + .inject(context, request.getHeaders(), SETTER); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) diff --git a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientTracer.java b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientTracer.java index 289a4b38fac6..ece0a8f92233 100644 --- a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientTracer.java +++ b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientTracer.java @@ -24,7 +24,8 @@ import java.net.URI; import java.net.URISyntaxException; -public class GoogleHttpClientTracer extends HttpClientTracer { +public class GoogleHttpClientTracer + extends HttpClientTracer { public static final GoogleHttpClientTracer TRACER = new GoogleHttpClientTracer(); @Override @@ -62,7 +63,7 @@ protected String responseHeader(HttpResponse httpResponse, String name) { } @Override - protected Setter getSetter() { + protected Setter getSetter() { return HeadersInjectAdapter.SETTER; } diff --git a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/HeadersInjectAdapter.java b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/HeadersInjectAdapter.java index a84b566ffed0..3436d2be8049 100644 --- a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/HeadersInjectAdapter.java +++ b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/HeadersInjectAdapter.java @@ -16,15 +16,15 @@ package io.opentelemetry.instrumentation.auto.googlehttpclient; -import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpHeaders; import io.opentelemetry.context.propagation.HttpTextFormat; -public class HeadersInjectAdapter implements HttpTextFormat.Setter { +public class HeadersInjectAdapter implements HttpTextFormat.Setter { public static final HeadersInjectAdapter SETTER = new HeadersInjectAdapter(); @Override - public void set(final HttpRequest carrier, final String key, final String value) { - carrier.getHeaders().put(key, value); + public void set(final HttpHeaders carrier, final String key, final String value) { + carrier.put(key, value); } } diff --git a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java index bf521176f17b..504bf41c08c9 100644 --- a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java +++ b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java @@ -16,6 +16,7 @@ package io.opentelemetry.instrumentation.auto.grizzly.client; +import com.ning.http.client.FluentCaseInsensitiveStringsMap; import com.ning.http.client.Request; import com.ning.http.client.Response; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; @@ -23,7 +24,8 @@ import java.net.URI; import java.net.URISyntaxException; -public class GrizzlyClientTracer extends HttpClientTracer { +public class GrizzlyClientTracer + extends HttpClientTracer { public static final GrizzlyClientTracer TRACER = new GrizzlyClientTracer(); @@ -53,7 +55,7 @@ protected String responseHeader(Response response, String name) { } @Override - protected Setter getSetter() { + protected Setter getSetter() { return GrizzlyInjectAdapter.SETTER; } diff --git a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java index 40eb93c8f642..3108c3c9c531 100644 --- a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java +++ b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java @@ -16,15 +16,17 @@ package io.opentelemetry.instrumentation.auto.grizzly.client; -import com.ning.http.client.Request; +import com.ning.http.client.FluentCaseInsensitiveStringsMap; import io.opentelemetry.context.propagation.HttpTextFormat; -public class GrizzlyInjectAdapter implements HttpTextFormat.Setter { +public class GrizzlyInjectAdapter + implements HttpTextFormat.Setter { public static final GrizzlyInjectAdapter SETTER = new GrizzlyInjectAdapter(); @Override - public void set(final Request carrier, final String key, final String value) { - carrier.getHeaders().replaceWith(key, value); + public void set( + final FluentCaseInsensitiveStringsMap carrier, final String key, final String value) { + carrier.replaceWith(key, value); } } diff --git a/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionInstrumentation.java b/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionInstrumentation.java index f4698a5abfdb..efc79e5bc5b2 100644 --- a/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionInstrumentation.java +++ b/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionInstrumentation.java @@ -18,10 +18,8 @@ import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.extendsClass; import static io.opentelemetry.auto.tooling.matcher.NameMatchers.namedOneOf; -import static io.opentelemetry.instrumentation.auto.httpurlconnection.HeadersInjectAdapter.SETTER; import static io.opentelemetry.instrumentation.auto.httpurlconnection.HttpUrlConnectionTracer.TRACER; import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; import static java.util.Collections.singletonMap; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isPublic; @@ -30,8 +28,6 @@ import static net.bytebuddy.matcher.ElementMatchers.not; import com.google.auto.service.AutoService; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.auto.tooling.Instrumenter; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap; @@ -89,7 +85,8 @@ public static class HttpUrlConnectionAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static HttpUrlState methodEnter( @Advice.This final HttpURLConnection thiz, - @Advice.FieldValue("connected") final boolean connected) { + @Advice.FieldValue("connected") final boolean connected, + @Advice.Local("otelScope") Scope scope) { int callDepth = CallDepthThreadLocalMap.incrementCallDepth(HttpURLConnection.class); if (callDepth > 0) { @@ -104,8 +101,7 @@ public static HttpUrlState methodEnter( if (!state.hasSpan() && !state.isFinished()) { Span span = state.start(thiz); if (!connected) { - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, thiz, SETTER); + scope = TRACER.startScope(span, thiz); } } return state; @@ -117,8 +113,12 @@ public static void methodExit( @Advice.Enter final HttpUrlState state, @Advice.FieldValue("responseCode") final int responseCode, @Advice.Thrown final Throwable throwable, - @Advice.Origin("#m") final String methodName) { + @Advice.Origin("#m") final String methodName, + @Advice.Local("otelScope") Scope scope) { + if (scope != null) { + scope.close(); + } if (state == null) { return; } diff --git a/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionTracer.java b/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionTracer.java index 7d30905d7648..4a623b6bcc61 100644 --- a/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionTracer.java +++ b/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/HttpUrlConnectionTracer.java @@ -16,6 +16,8 @@ package io.opentelemetry.instrumentation.auto.httpurlconnection; +import static io.opentelemetry.instrumentation.auto.httpurlconnection.HeadersInjectAdapter.SETTER; + import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import io.opentelemetry.trace.Span; @@ -24,7 +26,8 @@ import java.net.URI; import java.net.URISyntaxException; -public class HttpUrlConnectionTracer extends HttpClientTracer { +public class HttpUrlConnectionTracer + extends HttpClientTracer { public static final HttpUrlConnectionTracer TRACER = new HttpUrlConnectionTracer(); @@ -55,7 +58,7 @@ protected String responseHeader(Integer integer, String name) { @Override protected Setter getSetter() { - return null; + return SETTER; } @Override diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java index b7d5b26a4b60..cac1d092e3e1 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java @@ -16,15 +16,15 @@ package io.opentelemetry.instrumentation.auto.jaxrsclient.v1_1; -import com.sun.jersey.api.client.ClientRequest; import io.opentelemetry.context.propagation.HttpTextFormat; +import javax.ws.rs.core.MultivaluedMap; -public final class InjectAdapter implements HttpTextFormat.Setter { +public final class InjectAdapter implements HttpTextFormat.Setter> { public static final InjectAdapter SETTER = new InjectAdapter(); @Override - public void set(ClientRequest clientRequest, String key, String value) { - clientRequest.getHeaders().putSingle(key, value); + public void set(MultivaluedMap carrier, String key, String value) { + carrier.putSingle(key, value); } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java index 42082b1b5ae0..3ce374a33891 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java @@ -23,8 +23,10 @@ import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import java.net.URI; +import javax.ws.rs.core.MultivaluedMap; -public class JaxRsClientV1Tracer extends HttpClientTracer { +public class JaxRsClientV1Tracer + extends HttpClientTracer, ClientResponse> { public static final JaxRsClientV1Tracer TRACER = new JaxRsClientV1Tracer(); @Override @@ -54,7 +56,7 @@ protected String responseHeader(ClientResponse clientResponse, String name) { } @Override - protected Setter getSetter() { + protected Setter> getSetter() { return SETTER; } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java index 5fc38d2b02af..65f443a3143b 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java @@ -16,12 +16,9 @@ package io.opentelemetry.instrumentation.auto.jaxrsclient.v2_0; -import static io.opentelemetry.instrumentation.auto.jaxrsclient.v2_0.InjectAdapter.SETTER; import static io.opentelemetry.instrumentation.auto.jaxrsclient.v2_0.JaxRsClientTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; +import io.opentelemetry.context.Scope; import io.opentelemetry.trace.Span; import javax.annotation.Priority; import javax.ws.rs.Priorities; @@ -37,12 +34,9 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF @Override public void filter(final ClientRequestContext requestContext) { Span span = TRACER.startSpan(requestContext); - - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators() - .getHttpTextFormat() - .inject(context, requestContext.getHeaders(), SETTER); - + // TODO (trask) expose inject separate from startScope, e.g. for async cases + Scope scope = TRACER.startScope(span, requestContext.getHeaders()); + scope.close(); requestContext.setProperty(SPAN_PROPERTY_NAME, span); } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java index 5b02ba324f0d..4631a36359d8 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java @@ -16,14 +16,17 @@ package io.opentelemetry.instrumentation.auto.jaxrsclient.v2_0; +import static io.opentelemetry.instrumentation.auto.jaxrsclient.v2_0.InjectAdapter.SETTER; + import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import java.net.URI; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientResponseContext; +import javax.ws.rs.core.MultivaluedMap; public class JaxRsClientTracer - extends HttpClientTracer { + extends HttpClientTracer { public static final JaxRsClientTracer TRACER = new JaxRsClientTracer(); @Override @@ -52,8 +55,8 @@ protected String responseHeader(ClientResponseContext clientResponseContext, Str } @Override - protected Setter getSetter() { - return null; + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpAdvice.java b/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpAdvice.java index f9e8a1188099..7284cf3b4315 100644 --- a/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpAdvice.java +++ b/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpAdvice.java @@ -16,14 +16,9 @@ package io.opentelemetry.instrumentation.auto.khttp; -import static io.opentelemetry.context.ContextUtils.withScopedContext; -import static io.opentelemetry.instrumentation.auto.khttp.KHttpHeadersInjectAdapter.SETTER; import static io.opentelemetry.instrumentation.auto.khttp.KHttpHeadersInjectAdapter.asWritable; import static io.opentelemetry.instrumentation.auto.khttp.KHttpTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap.Depth; import io.opentelemetry.trace.Span; @@ -46,10 +41,8 @@ public static void methodEnter( if (callDepth.getAndIncrement() == 0) { span = TRACER.startSpan(new RequestWrapper(method, uri, headers)); if (span.getContext().isValid()) { - Context context = withSpan(span, Context.current()); headers = asWritable(headers); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, headers, SETTER); - scope = withScopedContext(context); + scope = TRACER.startScope(span, headers); } } } diff --git a/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpTracer.java b/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpTracer.java index 4a5ad8f03c83..d4b48f512656 100644 --- a/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpTracer.java +++ b/instrumentation/khttp-0.1/src/main/java/io/opentelemetry/instrumentation/auto/khttp/KHttpTracer.java @@ -16,16 +16,19 @@ package io.opentelemetry.instrumentation.auto.khttp; +import static io.opentelemetry.instrumentation.auto.khttp.KHttpHeadersInjectAdapter.SETTER; + import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap; import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap.Depth; import java.net.URI; import java.net.URISyntaxException; +import java.util.Map; import khttp.KHttp; import khttp.responses.Response; -public class KHttpTracer extends HttpClientTracer { +public class KHttpTracer extends HttpClientTracer, Response> { public static final KHttpTracer TRACER = new KHttpTracer(); public Depth getCallDepth() { @@ -58,8 +61,8 @@ protected String responseHeader(Response response, String name) { } @Override - protected Setter getSetter() { - return null; + protected Setter> getSetter() { + return SETTER; } @Override diff --git a/instrumentation/kubernetes-client-7.0/src/main/java/io/opentelemetry/instrumentation/auto/kubernetesclient/KubernetesClientTracer.java b/instrumentation/kubernetes-client-7.0/src/main/java/io/opentelemetry/instrumentation/auto/kubernetesclient/KubernetesClientTracer.java index 0c0cc80b9200..223ad25f4beb 100644 --- a/instrumentation/kubernetes-client-7.0/src/main/java/io/opentelemetry/instrumentation/auto/kubernetesclient/KubernetesClientTracer.java +++ b/instrumentation/kubernetes-client-7.0/src/main/java/io/opentelemetry/instrumentation/auto/kubernetesclient/KubernetesClientTracer.java @@ -25,7 +25,7 @@ import okhttp3.Request; import okhttp3.Response; -public class KubernetesClientTracer extends HttpClientTracer { +public class KubernetesClientTracer extends HttpClientTracer { public static final KubernetesClientTracer TRACER = new KubernetesClientTracer(); @Override @@ -55,6 +55,7 @@ protected String responseHeader(Response response, String name) { @Override protected Setter getSetter() { + // TODO (trask) no propagation implemented yet? return null; } diff --git a/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java b/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java index c58b817715a9..a2e2e876b513 100644 --- a/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java +++ b/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java @@ -16,23 +16,19 @@ package io.opentelemetry.instrumentation.auto.netty.v3_8.client; -import static io.opentelemetry.context.ContextUtils.withScopedContext; import static io.opentelemetry.instrumentation.auto.netty.v3_8.client.NettyResponseInjectAdapter.SETTER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.HOST; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.context.Scope; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; -import io.opentelemetry.trace.Span; import java.net.URI; import java.net.URISyntaxException; +import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; -public class NettyHttpClientTracer extends HttpClientTracer { +public class NettyHttpClientTracer + extends HttpClientTracer { public static final NettyHttpClientTracer TRACER = new NettyHttpClientTracer(); @Override @@ -66,15 +62,8 @@ protected String responseHeader(HttpResponse httpResponse, String name) { } @Override - protected Setter getSetter() { - return null; - } - - @Override - public Scope startScope(Span span, HttpRequest request) { - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request.headers(), SETTER); - return withScopedContext(context); + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/HttpClientRequestTracingHandler.java b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/HttpClientRequestTracingHandler.java index d1b8f800dc02..137d89c21505 100644 --- a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/HttpClientRequestTracingHandler.java +++ b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/HttpClientRequestTracingHandler.java @@ -17,16 +17,12 @@ package io.opentelemetry.instrumentation.auto.netty.v4_0.client; import static io.opentelemetry.instrumentation.auto.netty.v4_0.client.NettyHttpClientTracer.TRACER; -import static io.opentelemetry.instrumentation.auto.netty.v4_0.client.NettyResponseInjectAdapter.SETTER; import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; -import io.grpc.Context; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.handler.codec.http.HttpRequest; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.decorator.BaseTracer; import io.opentelemetry.instrumentation.auto.netty.v4_0.AttributeKeys; @@ -59,25 +55,14 @@ public void write(final ChannelHandlerContext ctx, final Object msg, final Chann } Span span = TRACER.startSpan(request); - try (Scope scope = currentContextWith(span)) { - BaseTracer.onPeerConnection(span, (InetSocketAddress) ctx.channel().remoteAddress()); + BaseTracer.onPeerConnection(span, (InetSocketAddress) ctx.channel().remoteAddress()); + ctx.channel().attr(AttributeKeys.CLIENT_ATTRIBUTE_KEY).set(span); - // AWS calls are often signed, so we can't add headers without breaking the signature. - if (!request.headers().contains("amz-sdk-invocation-id")) { - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators() - .getHttpTextFormat() - .inject(context, request.headers(), SETTER); - } - - ctx.channel().attr(AttributeKeys.CLIENT_ATTRIBUTE_KEY).set(span); - - try { - ctx.write(msg, prm); - } catch (final Throwable throwable) { - TRACER.endExceptionally(span, throwable); - throw throwable; - } + try (Scope scope = TRACER.startScope(span, request.headers())) { + ctx.write(msg, prm); + } catch (final Throwable throwable) { + TRACER.endExceptionally(span, throwable); + throw throwable; } finally { if (null != parentScope) { parentScope.close(); diff --git a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/NettyHttpClientTracer.java b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/NettyHttpClientTracer.java index df6c29c558f5..d9230a245fff 100644 --- a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/NettyHttpClientTracer.java +++ b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_0/client/NettyHttpClientTracer.java @@ -22,9 +22,9 @@ import static io.opentelemetry.trace.TracingContextUtils.withSpan; import io.grpc.Context; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.context.Scope; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; @@ -32,9 +32,24 @@ import java.net.URI; import java.net.URISyntaxException; -public class NettyHttpClientTracer extends HttpClientTracer { +public class NettyHttpClientTracer + extends HttpClientTracer { public static final NettyHttpClientTracer TRACER = new NettyHttpClientTracer(); + @Override + public Scope startScope(Span span, HttpHeaders headers) { + if (!headers.contains("amz-sdk-invocation-id")) { + return super.startScope(span, headers); + } else { + // TODO (trask) if we move injection up to aws-sdk layer, and start suppressing nested netty + // spans, do we still need this condition? + // AWS calls are often signed, so we can't add headers without breaking the signature. + Context context = withSpan(span, Context.current()); + context = context.withValue(CONTEXT_CLIENT_SPAN_KEY, span); + return withScopedContext(context); + } + } + @Override protected String method(final HttpRequest httpRequest) { return httpRequest.getMethod().name(); @@ -66,15 +81,8 @@ protected String responseHeader(HttpResponse httpResponse, String name) { } @Override - protected Setter getSetter() { - return null; - } - - @Override - public Scope startScope(Span span, HttpRequest request) { - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request.headers(), SETTER); - return withScopedContext(context); + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/NettyHttpClientTracer.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/NettyHttpClientTracer.java index b0fb37af9fba..809e88b81efa 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/NettyHttpClientTracer.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/NettyHttpClientTracer.java @@ -17,22 +17,18 @@ package io.opentelemetry.instrumentation.auto.netty.v4_1.client; import static io.netty.handler.codec.http.HttpHeaderNames.HOST; -import static io.opentelemetry.context.ContextUtils.withScopedContext; import static io.opentelemetry.instrumentation.auto.netty.v4_1.client.NettyResponseInjectAdapter.SETTER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; -import io.grpc.Context; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; -import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.context.Scope; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; -import io.opentelemetry.trace.Span; import java.net.URI; import java.net.URISyntaxException; -public class NettyHttpClientTracer extends HttpClientTracer { +public class NettyHttpClientTracer + extends HttpClientTracer { public static final NettyHttpClientTracer TRACER = new NettyHttpClientTracer(); @Override @@ -66,15 +62,8 @@ protected String responseHeader(HttpResponse httpResponse, String name) { } @Override - protected Setter getSetter() { - return null; - } - - @Override - public Scope startScope(Span span, HttpRequest request) { - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request.headers(), SETTER); - return withScopedContext(context); + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/OkHttpClientTracer.java b/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/OkHttpClientTracer.java index da8d9137569d..ba36da6d424f 100644 --- a/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/OkHttpClientTracer.java +++ b/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/OkHttpClientTracer.java @@ -16,6 +16,8 @@ package io.opentelemetry.instrumentation.auto.okhttp.v2_2; +import static io.opentelemetry.instrumentation.auto.okhttp.v2_2.RequestBuilderInjectAdapter.SETTER; + import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; @@ -23,7 +25,7 @@ import java.net.URI; import java.net.URISyntaxException; -public class OkHttpClientTracer extends HttpClientTracer { +public class OkHttpClientTracer extends HttpClientTracer { public static final OkHttpClientTracer TRACER = new OkHttpClientTracer(); @Override @@ -52,8 +54,8 @@ protected String responseHeader(Response response, String name) { } @Override - protected Setter getSetter() { - return null; + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/TracingInterceptor.java b/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/TracingInterceptor.java index 6e9d6614b62d..22ec15619fa2 100644 --- a/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/TracingInterceptor.java +++ b/instrumentation/okhttp/okhttp-2.2/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v2_2/TracingInterceptor.java @@ -16,15 +16,11 @@ package io.opentelemetry.instrumentation.auto.okhttp.v2_2; -import static io.opentelemetry.context.ContextUtils.withScopedContext; import static io.opentelemetry.instrumentation.auto.okhttp.v2_2.OkHttpClientTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; import com.squareup.okhttp.Interceptor; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.context.Scope; import io.opentelemetry.trace.Span; import java.io.IOException; @@ -33,14 +29,10 @@ public class TracingInterceptor implements Interceptor { @Override public Response intercept(final Chain chain) throws IOException { Span span = TRACER.startSpan(chain.request()); - Context context = withSpan(span, Context.current()); Request.Builder requestBuilder = chain.request().newBuilder(); - OpenTelemetry.getPropagators() - .getHttpTextFormat() - .inject(context, requestBuilder, RequestBuilderInjectAdapter.SETTER); Response response; - try (Scope scope = withScopedContext(context)) { + try (Scope scope = TRACER.startScope(span, requestBuilder)) { response = chain.proceed(requestBuilder.build()); } catch (final Exception e) { TRACER.endExceptionally(span, e); diff --git a/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/OkHttpClientTracer.java b/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/OkHttpClientTracer.java index 55a80c0bfd55..c6cbfa48d043 100644 --- a/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/OkHttpClientTracer.java +++ b/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/OkHttpClientTracer.java @@ -16,13 +16,15 @@ package io.opentelemetry.instrumentation.auto.okhttp.v3_0; +import static io.opentelemetry.instrumentation.auto.okhttp.v3_0.RequestBuilderInjectAdapter.SETTER; + import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import java.net.URI; import okhttp3.Request; import okhttp3.Response; -public class OkHttpClientTracer extends HttpClientTracer { +public class OkHttpClientTracer extends HttpClientTracer { public static final OkHttpClientTracer TRACER = new OkHttpClientTracer(); @Override @@ -51,8 +53,8 @@ protected String responseHeader(Response response, String name) { } @Override - protected Setter getSetter() { - return null; + protected Setter getSetter() { + return SETTER; } @Override diff --git a/instrumentation/play-ws/play-ws-2.0/src/main/java/io/opentelemetry/instrumentation/auto/playws/v2_0/PlayWSClientInstrumentation.java b/instrumentation/play-ws/play-ws-2.0/src/main/java/io/opentelemetry/instrumentation/auto/playws/v2_0/PlayWSClientInstrumentation.java index ee9ba2712780..0df46c24df34 100644 --- a/instrumentation/play-ws/play-ws-2.0/src/main/java/io/opentelemetry/instrumentation/auto/playws/v2_0/PlayWSClientInstrumentation.java +++ b/instrumentation/play-ws/play-ws-2.0/src/main/java/io/opentelemetry/instrumentation/auto/playws/v2_0/PlayWSClientInstrumentation.java @@ -16,14 +16,11 @@ package io.opentelemetry.instrumentation.auto.playws.v2_0; -import static io.opentelemetry.instrumentation.auto.playws.HeadersInjectAdapter.SETTER; import static io.opentelemetry.instrumentation.auto.playws.PlayWSClientTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; import com.google.auto.service.AutoService; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.auto.playws.BasePlayWSClientInstrumentation; import io.opentelemetry.trace.Span; import net.bytebuddy.asm.Advice; @@ -42,8 +39,9 @@ public static void methodEnter( @Advice.Local("otelSpan") Span span) { span = TRACER.startSpan(request); - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, SETTER); + // TODO (trask) expose inject separate from startScope, e.g. for async cases + Scope scope = TRACER.startScope(span, request.getHeaders()); + scope.close(); if (asyncHandler instanceof StreamedAsyncHandler) { asyncHandler = new StreamedAsyncHandlerWrapper((StreamedAsyncHandler) asyncHandler, span); diff --git a/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/HeadersInjectAdapter.java b/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/HeadersInjectAdapter.java index 291fa6bc1061..b572a5ce7d30 100644 --- a/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/HeadersInjectAdapter.java +++ b/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/HeadersInjectAdapter.java @@ -17,14 +17,14 @@ package io.opentelemetry.instrumentation.auto.playws; import io.opentelemetry.context.propagation.HttpTextFormat; -import play.shaded.ahc.org.asynchttpclient.Request; +import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders; -public class HeadersInjectAdapter implements HttpTextFormat.Setter { +public class HeadersInjectAdapter implements HttpTextFormat.Setter { public static final HeadersInjectAdapter SETTER = new HeadersInjectAdapter(); @Override - public void set(final Request carrier, final String key, final String value) { - carrier.getHeaders().add(key, value); + public void set(final HttpHeaders carrier, final String key, final String value) { + carrier.add(key, value); } } diff --git a/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/PlayWSClientTracer.java b/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/PlayWSClientTracer.java index 6c9f23b4cb3d..51ccdbc9f7b1 100644 --- a/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/PlayWSClientTracer.java +++ b/instrumentation/play-ws/play-ws-common/src/main/java/io/opentelemetry/instrumentation/auto/playws/PlayWSClientTracer.java @@ -22,10 +22,11 @@ import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; import java.net.URI; import java.net.URISyntaxException; +import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders; import play.shaded.ahc.org.asynchttpclient.Request; import play.shaded.ahc.org.asynchttpclient.Response; -public class PlayWSClientTracer extends HttpClientTracer { +public class PlayWSClientTracer extends HttpClientTracer { public static final PlayWSClientTracer TRACER = new PlayWSClientTracer(); @Override @@ -54,7 +55,7 @@ protected String responseHeader(Response response, String name) { } @Override - protected Setter getSetter() { + protected Setter getSetter() { return SETTER; } diff --git a/library-api/src/main/java/io/opentelemetry/instrumentation/api/decorator/HttpClientTracer.java b/library-api/src/main/java/io/opentelemetry/instrumentation/api/decorator/HttpClientTracer.java index f6b4daea4064..6b8f15d0434f 100644 --- a/library-api/src/main/java/io/opentelemetry/instrumentation/api/decorator/HttpClientTracer.java +++ b/library-api/src/main/java/io/opentelemetry/instrumentation/api/decorator/HttpClientTracer.java @@ -37,7 +37,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class HttpClientTracer extends BaseTracer { +public abstract class HttpClientTracer extends BaseTracer { private static final Logger log = LoggerFactory.getLogger(HttpClientTracer.class); @@ -55,7 +55,7 @@ public abstract class HttpClientTracer extends BaseTracer { protected abstract String responseHeader(RESPONSE response, String name); - protected abstract HttpTextFormat.Setter getSetter(); + protected abstract HttpTextFormat.Setter getSetter(); protected HttpClientTracer() { super(); @@ -73,15 +73,15 @@ public Span startSpan(REQUEST request, long startTimeNanos) { return startSpan(request, spanNameForRequest(request), startTimeNanos); } - public Scope startScope(Span span, REQUEST request) { + public Scope startScope(Span span, HEADERS headers) { Context context = withSpan(span, Context.current()); - Setter setter = getSetter(); + Setter setter = getSetter(); if (setter == null) { throw new IllegalStateException( "getSetter() not defined but calling startScope(), either getSetter must be implemented or the scope should be setup manually"); } - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, setter); + OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, headers, setter); context = context.withValue(CONTEXT_CLIENT_SPAN_KEY, span); return withScopedContext(context); } From 719f3ae513cd8d8e8a36865f92b845c2312674a8 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 13 Aug 2020 22:09:17 -0700 Subject: [PATCH 02/20] build --- .../auto/akkahttp/AkkaHttpClientInstrumentation.java | 6 +++++- .../grizzly/client/GrizzlyClientRequestAdvice.java | 2 +- .../jaxrsclient/v1_1/JaxRsClientV1Instrumentation.java | 2 +- .../auto/playws/v1_0/PlayWSClientInstrumentation.java | 2 +- .../auto/playws/v2_1/PlayWSClientInstrumentation.java | 10 ++++------ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java index d34363f1a145..d97929099ab0 100644 --- a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java +++ b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java @@ -158,7 +158,11 @@ public static class InjectAdapter implements HttpTextFormat.Setter Date: Thu, 13 Aug 2020 22:29:16 -0700 Subject: [PATCH 03/20] build --- .../httpclients/webclient/WebClientBeanPostProcessorTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java b/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java index 484645987ea3..41d009ab63cf 100644 --- a/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java +++ b/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer; import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter; import io.opentelemetry.trace.Tracer; import org.junit.jupiter.api.DisplayName; @@ -32,7 +33,8 @@ class WebClientBeanPostProcessorTest { @Mock Tracer tracer; - WebClientBeanPostProcessor webClientBeanPostProcessor = new WebClientBeanPostProcessor(tracer); + WebClientBeanPostProcessor webClientBeanPostProcessor = + new WebClientBeanPostProcessor(new SpringWebfluxHttpClientTracer(tracer)); @Test @DisplayName( From c7c48118a217458d12908acacf553941c6c52061 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 13 Aug 2020 22:39:06 -0700 Subject: [PATCH 04/20] remove unused --- .../spring/webflux/client/SpringWebfluxHttpClientTracer.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java index cbfc1d6b168a..2dc6506513b4 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java @@ -78,8 +78,4 @@ protected Setter getSetter() { protected String getInstrumentationName() { return "io.opentelemetry.auto.spring-webflux-5.0"; } - - public Tracer getTracer() { - return tracer; - } } From 35507e38a37982e9af79631e2029f54a643b3e6e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 13 Aug 2020 22:42:12 -0700 Subject: [PATCH 05/20] fix --- .../spring/webflux/client/WebClientTracingFilter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java index 74ffce6ed543..b625275bf26c 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java @@ -62,6 +62,7 @@ public Mono filter(final ClientRequest request, final ExchangeFu }) .doOnCancel( () -> { + TRACER.onCancel(span); TRACER.end(span); }); } From 6b40b4728b9812ad6a0b89d0ec18a4e7450b8e12 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 13 Aug 2020 23:25:00 -0700 Subject: [PATCH 06/20] tests --- .../client/WebClientTracingFilter.java | 2 +- .../httpurlconnection/UrlInstrumentation.java | 2 +- .../client/SpringWebfluxHttpClientTest.groovy | 44 +------------------ 3 files changed, 3 insertions(+), 45 deletions(-) diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java index b625275bf26c..175b6d8dde35 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java @@ -50,7 +50,7 @@ public Mono filter(final ClientRequest request, final ExchangeFu Span span = TRACER.startSpan(request); ClientRequest.Builder requestBuilder = ClientRequest.from(request); - try (Scope scope = TRACER.startScope(span, requestBuilder)) { + try (Scope ignored = TRACER.startScope(span, requestBuilder)) { return next.exchange(requestBuilder.build()) .doOnSuccessOrError( (clientResponse, throwable) -> { diff --git a/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/UrlInstrumentation.java b/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/UrlInstrumentation.java index 530f2ea9e75c..106198fd325f 100644 --- a/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/UrlInstrumentation.java +++ b/instrumentation/http-url-connection/src/main/java/io/opentelemetry/instrumentation/auto/httpurlconnection/UrlInstrumentation.java @@ -61,7 +61,7 @@ public Map, String> transfor @Override public String[] helperClassNames() { return new String[] { - packageName + ".HttpUrlConnectionTracer", + packageName + ".HttpUrlConnectionTracer", packageName + ".HeadersInjectAdapter" }; } diff --git a/instrumentation/spring-webflux-5.0/src/test/groovy/client/SpringWebfluxHttpClientTest.groovy b/instrumentation/spring-webflux-5.0/src/test/groovy/client/SpringWebfluxHttpClientTest.groovy index eac376d322d3..43fdb1f0e363 100644 --- a/instrumentation/spring-webflux-5.0/src/test/groovy/client/SpringWebfluxHttpClientTest.groovy +++ b/instrumentation/spring-webflux-5.0/src/test/groovy/client/SpringWebfluxHttpClientTest.groovy @@ -16,17 +16,13 @@ package client -import io.opentelemetry.auto.test.asserts.TraceAssert + import io.opentelemetry.auto.test.base.HttpClientTest -import io.opentelemetry.instrumentation.api.MoreAttributes -import io.opentelemetry.trace.attributes.SemanticAttributes import org.springframework.http.HttpMethod import org.springframework.web.reactive.function.client.ClientResponse import org.springframework.web.reactive.function.client.WebClient import spock.lang.Timeout -import static io.opentelemetry.trace.Span.Kind.CLIENT - @Timeout(5) class SpringWebfluxHttpClientTest extends HttpClientTest { @@ -44,44 +40,6 @@ class SpringWebfluxHttpClientTest extends HttpClientTest { response.statusCode().value() } - @Override - // parent spanRef must be cast otherwise it breaks debugging classloading (junit loads it early) - void clientSpan(TraceAssert trace, int index, Object parentSpan, String method = "GET", boolean tagQueryString = false, URI uri = server.address.resolve("/success"), Integer status = 200, Throwable exception = null) { - super.clientSpan(trace, index, parentSpan, method, tagQueryString, uri, status, exception) - if (!exception) { - trace.span(index + 1) { - childOf(trace.span(index)) - operationName "HTTP $method" - spanKind CLIENT - errored exception != null - if (exception) { - errorEvent(exception.class, exception.message) - } - attributes { - "${SemanticAttributes.NET_PEER_NAME.key()}" "localhost" - "${SemanticAttributes.NET_PEER_PORT.key()}" uri.port - "${SemanticAttributes.NET_PEER_IP.key()}" { it == null || it == "127.0.0.1" } // Optional - "${SemanticAttributes.HTTP_URL.key()}" { it == "${uri}" || it == "${removeFragment(uri)}" } - "${SemanticAttributes.HTTP_METHOD.key()}" method - "${SemanticAttributes.HTTP_USER_AGENT.key()}" { it.startsWith("ReactorNetty") } - if (status) { - "${SemanticAttributes.HTTP_STATUS_CODE.key()}" status - } - if (tagQueryString) { - "$MoreAttributes.HTTP_QUERY" uri.query - "$MoreAttributes.HTTP_FRAGMENT" { it == null || it == uri.fragment } // Optional - } - } - } - } - } - - @Override - int extraClientSpans() { - // has netty-client span inside of spring-webflux-client - return 1 - } - boolean testRedirects() { false } From bc228a34bac45d65001037f946d8f695306b9efa Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 12:42:18 -0700 Subject: [PATCH 07/20] more --- .../HttpClientRequestTracingHandler.java | 9 +----- .../v3_8/client/NettyHttpClientTracer.java | 19 +++++++++++++ .../HttpClientRequestTracingHandler.java | 28 +++++-------------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/HttpClientRequestTracingHandler.java b/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/HttpClientRequestTracingHandler.java index bbed4fa72ba2..18c7d9537ebe 100644 --- a/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/HttpClientRequestTracingHandler.java +++ b/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/HttpClientRequestTracingHandler.java @@ -17,12 +17,8 @@ package io.opentelemetry.instrumentation.auto.netty.v3_8.client; import static io.opentelemetry.instrumentation.auto.netty.v3_8.client.NettyHttpClientTracer.TRACER; -import static io.opentelemetry.instrumentation.auto.netty.v3_8.client.NettyResponseInjectAdapter.SETTER; import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.decorator.BaseTracer; import io.opentelemetry.instrumentation.auto.api.ContextStore; @@ -66,12 +62,9 @@ public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent m Span span = TRACER.startSpan(request); BaseTracer.onPeerConnection(span, (InetSocketAddress) ctx.getChannel().getRemoteAddress()); - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request.headers(), SETTER); - channelTraceContext.setClientSpan(span); - try (Scope scope = currentContextWith(span)) { + try (Scope ignored = TRACER.startScope(span, request.headers())) { ctx.sendDownstream(msg); } catch (final Throwable throwable) { TRACER.endExceptionally(span, throwable); diff --git a/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java b/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java index a2e2e876b513..2f2590d8ecbb 100644 --- a/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java +++ b/instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/instrumentation/auto/netty/v3_8/client/NettyHttpClientTracer.java @@ -16,11 +16,16 @@ package io.opentelemetry.instrumentation.auto.netty.v3_8.client; +import static io.opentelemetry.context.ContextUtils.withScopedContext; import static io.opentelemetry.instrumentation.auto.netty.v3_8.client.NettyResponseInjectAdapter.SETTER; +import static io.opentelemetry.trace.TracingContextUtils.withSpan; import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.HOST; +import io.grpc.Context; +import io.opentelemetry.context.Scope; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer; +import io.opentelemetry.trace.Span; import java.net.URI; import java.net.URISyntaxException; import org.jboss.netty.handler.codec.http.HttpHeaders; @@ -31,6 +36,20 @@ public class NettyHttpClientTracer extends HttpClientTracer { public static final NettyHttpClientTracer TRACER = new NettyHttpClientTracer(); + @Override + public Scope startScope(Span span, HttpHeaders headers) { + if (!headers.contains("amz-sdk-invocation-id")) { + return super.startScope(span, headers); + } else { + // TODO (trask) if we move injection up to aws-sdk layer, and start suppressing nested netty + // spans, do we still need this condition? + // AWS calls are often signed, so we can't add headers without breaking the signature. + Context context = withSpan(span, Context.current()); + context = context.withValue(CONTEXT_CLIENT_SPAN_KEY, span); + return withScopedContext(context); + } + } + @Override protected String method(final HttpRequest httpRequest) { return httpRequest.getMethod().getName(); diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java index f6ce0fb64250..8e3b4e2406ac 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java @@ -17,16 +17,12 @@ package io.opentelemetry.instrumentation.auto.netty.v4_1.client; import static io.opentelemetry.instrumentation.auto.netty.v4_1.client.NettyHttpClientTracer.TRACER; -import static io.opentelemetry.instrumentation.auto.netty.v4_1.client.NettyResponseInjectAdapter.SETTER; import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; -import io.grpc.Context; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.handler.codec.http.HttpRequest; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.decorator.BaseTracer; import io.opentelemetry.instrumentation.auto.netty.v4_1.AttributeKeys; @@ -59,24 +55,14 @@ public void write(final ChannelHandlerContext ctx, final Object msg, final Chann } Span span = TRACER.startSpan(request); - try (Scope scope = currentContextWith(span)) { - BaseTracer.onPeerConnection(span, (InetSocketAddress) ctx.channel().remoteAddress()); - // AWS calls are often signed, so we can't add headers without breaking the signature. - if (!request.headers().contains("amz-sdk-invocation-id")) { - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators() - .getHttpTextFormat() - .inject(context, request.headers(), SETTER); - } - - ctx.channel().attr(AttributeKeys.CLIENT_ATTRIBUTE_KEY).set(span); + BaseTracer.onPeerConnection(span, (InetSocketAddress) ctx.channel().remoteAddress()); + ctx.channel().attr(AttributeKeys.CLIENT_ATTRIBUTE_KEY).set(span); - try { - ctx.write(msg, prm); - } catch (final Throwable throwable) { - TRACER.endExceptionally(span, throwable); - throw throwable; - } + try (Scope ignored = TRACER.startScope(span, request.headers())) { + ctx.write(msg, prm); + } catch (final Throwable throwable) { + TRACER.endExceptionally(span, throwable); + throw throwable; } finally { if (null != parentScope) { parentScope.close(); From 4e59c229c3fc3dddd73dc4e3b558a2b813640c08 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 13:03:53 -0700 Subject: [PATCH 08/20] more --- .../auto/okhttp/v3_0/TracingInterceptor.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/TracingInterceptor.java b/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/TracingInterceptor.java index 55a4819c9a62..bd0278ac12cd 100644 --- a/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/TracingInterceptor.java +++ b/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/auto/okhttp/v3_0/TracingInterceptor.java @@ -16,12 +16,8 @@ package io.opentelemetry.instrumentation.auto.okhttp.v3_0; -import static io.opentelemetry.context.ContextUtils.withScopedContext; import static io.opentelemetry.instrumentation.auto.okhttp.v3_0.OkHttpClientTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.context.Scope; import io.opentelemetry.trace.Span; import java.io.IOException; @@ -34,15 +30,10 @@ public class TracingInterceptor implements Interceptor { @Override public Response intercept(final Chain chain) throws IOException { Span span = TRACER.startSpan(chain.request()); - Context context = withSpan(span, Context.current()); - - Request.Builder requestBuilder = chain.request().newBuilder(); - OpenTelemetry.getPropagators() - .getHttpTextFormat() - .inject(context, requestBuilder, RequestBuilderInjectAdapter.SETTER); Response response; - try (Scope scope = withScopedContext(context)) { + Request.Builder requestBuilder = chain.request().newBuilder(); + try (Scope ignored = TRACER.startScope(span, requestBuilder)) { response = chain.proceed(requestBuilder.build()); } catch (final Exception e) { TRACER.endExceptionally(span, e); From b80c09f7681bfb6310110f586ada761b7abd712c Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 14:08:02 -0700 Subject: [PATCH 09/20] more --- .../auto/netty/v4_1/AttributeKeys.java | 4 ++-- .../v4_1/ChannelFutureListenerInstrumentation.java | 11 ++++++----- .../v4_1/NettyChannelPipelineInstrumentation.java | 12 ++++-------- .../v4_1/client/HttpClientRequestTracingHandler.java | 12 +++++++----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/AttributeKeys.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/AttributeKeys.java index 2a1480bea5a8..f1afad0dee61 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/AttributeKeys.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/AttributeKeys.java @@ -37,8 +37,8 @@ public ConcurrentMap> get(final ClassLoader ignore) { } }; - public static final AttributeKey PARENT_CONNECT_SPAN_ATTRIBUTE_KEY = - attributeKey("io.opentelemetry.instrumentation.auto.netty.v4_1.parent.connect.span"); + public static final AttributeKey PARENT_CONNECT_CONTEXT_ATTRIBUTE_KEY = + attributeKey("io.opentelemetry.instrumentation.auto.netty.v4_1.parent.connect.context"); /** * This constant is copied over to diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/ChannelFutureListenerInstrumentation.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/ChannelFutureListenerInstrumentation.java index 1110688c1ee8..e0f3182a3a84 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/ChannelFutureListenerInstrumentation.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/ChannelFutureListenerInstrumentation.java @@ -18,13 +18,14 @@ import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed; import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface; -import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; +import static io.opentelemetry.context.ContextUtils.withScopedContext; import static java.util.Collections.singletonMap; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import com.google.auto.service.AutoService; +import io.grpc.Context; import io.netty.channel.ChannelFuture; import io.opentelemetry.auto.tooling.Instrumenter; import io.opentelemetry.context.Scope; @@ -97,12 +98,12 @@ public static Scope activateScope(@Advice.Argument(0) final ChannelFuture future if (cause == null) { return null; } - Span parentSpan = - future.channel().attr(AttributeKeys.PARENT_CONNECT_SPAN_ATTRIBUTE_KEY).getAndRemove(); - if (parentSpan == null) { + Context parentContext = + future.channel().attr(AttributeKeys.PARENT_CONNECT_CONTEXT_ATTRIBUTE_KEY).getAndRemove(); + if (parentContext == null) { return null; } - Scope parentScope = currentContextWith(parentSpan); + Scope parentScope = withScopedContext(parentContext); Span errorSpan = NettyHttpClientTracer.TRACER.startSpan("CONNECT"); NettyHttpClientTracer.TRACER.endExceptionally(errorSpan, cause); return parentScope; diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/NettyChannelPipelineInstrumentation.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/NettyChannelPipelineInstrumentation.java index 6442d55ad248..d2ac7d36e784 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/NettyChannelPipelineInstrumentation.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/NettyChannelPipelineInstrumentation.java @@ -18,7 +18,6 @@ import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed; import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface; -import static io.opentelemetry.instrumentation.auto.netty.v4_1.server.NettyHttpServerTracer.TRACER; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; import static net.bytebuddy.matcher.ElementMatchers.named; @@ -26,6 +25,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import com.google.auto.service.AutoService; +import io.grpc.Context; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpClientCodec; @@ -43,7 +43,6 @@ import io.opentelemetry.instrumentation.auto.netty.v4_1.server.HttpServerRequestTracingHandler; import io.opentelemetry.instrumentation.auto.netty.v4_1.server.HttpServerResponseTracingHandler; import io.opentelemetry.instrumentation.auto.netty.v4_1.server.HttpServerTracingHandler; -import io.opentelemetry.trace.Span; import java.util.HashMap; import java.util.Map; import net.bytebuddy.asm.Advice; @@ -172,12 +171,9 @@ public static void addHandler( public static class ChannelPipelineConnectAdvice { @Advice.OnMethodEnter public static void addParentSpan(@Advice.This final ChannelPipeline pipeline) { - Span span = TRACER.getCurrentSpan(); - if (span.getContext().isValid()) { - Attribute attribute = - pipeline.channel().attr(AttributeKeys.PARENT_CONNECT_SPAN_ATTRIBUTE_KEY); - attribute.compareAndSet(null, span); - } + Attribute attribute = + pipeline.channel().attr(AttributeKeys.PARENT_CONNECT_CONTEXT_ATTRIBUTE_KEY); + attribute.compareAndSet(null, Context.current()); } } } diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java index 8e3b4e2406ac..70f4c1c09e0d 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/instrumentation/auto/netty/v4_1/client/HttpClientRequestTracingHandler.java @@ -16,9 +16,10 @@ package io.opentelemetry.instrumentation.auto.netty.v4_1.client; +import static io.opentelemetry.context.ContextUtils.withScopedContext; import static io.opentelemetry.instrumentation.auto.netty.v4_1.client.NettyHttpClientTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; +import io.grpc.Context; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; @@ -39,10 +40,11 @@ public void write(final ChannelHandlerContext ctx, final Object msg, final Chann } Scope parentScope = null; - Span parentSpan = - ctx.channel().attr(AttributeKeys.PARENT_CONNECT_SPAN_ATTRIBUTE_KEY).getAndRemove(); - if (parentSpan != null) { - parentScope = currentContextWith(parentSpan); + Context parentContext = + ctx.channel().attr(AttributeKeys.PARENT_CONNECT_CONTEXT_ATTRIBUTE_KEY).getAndRemove(); + if (parentContext != null) { + // TODO (trask) if null then do with ROOT scope? + parentScope = withScopedContext(parentContext); } HttpRequest request = (HttpRequest) msg; From bcfe8faf9c5b0a34ce895cacd7d77ec8b8f7d64c Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 14:10:25 -0700 Subject: [PATCH 10/20] muzzle --- .../auto/akkahttp/AkkaHttpClientInstrumentation.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java index d97929099ab0..630ad7bd9b27 100644 --- a/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java +++ b/instrumentation/akka-http-10.0/src/main/java/io/opentelemetry/instrumentation/auto/akkahttp/AkkaHttpClientInstrumentation.java @@ -56,6 +56,7 @@ public String[] helperClassNames() { return new String[] { AkkaHttpClientInstrumentation.class.getName() + "$OnCompleteHandler", AkkaHttpClientInstrumentation.class.getName() + "$AkkaHttpHeaders", + AkkaHttpClientInstrumentation.class.getName() + "$InjectAdapter", packageName + ".AkkaHttpClientTracer", }; } From c1d966e15c11043422b1ce105249c59f32651496 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 21:25:52 -0700 Subject: [PATCH 11/20] muzzle --- .../v2_0/JerseyClientConnectionErrorInstrumentation.java | 4 +++- .../v2_0/ResteasyClientConnectionErrorInstrumentation.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JerseyClientConnectionErrorInstrumentation.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JerseyClientConnectionErrorInstrumentation.java index fc26b24a5bee..fc5dfe45538a 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JerseyClientConnectionErrorInstrumentation.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JerseyClientConnectionErrorInstrumentation.java @@ -56,7 +56,9 @@ public ElementMatcher typeMatcher() { @Override public String[] helperClassNames() { return new String[] { - getClass().getName() + "$WrappedFuture", JaxRsClientTracer.class.getName(), + getClass().getName() + "$WrappedFuture", + packageName + ".JaxRsClientTracer", + packageName + ".InjectAdapter", }; } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ResteasyClientConnectionErrorInstrumentation.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ResteasyClientConnectionErrorInstrumentation.java index 5a0fcd5e13e8..33b8cd399b68 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ResteasyClientConnectionErrorInstrumentation.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ResteasyClientConnectionErrorInstrumentation.java @@ -56,7 +56,9 @@ public ElementMatcher typeMatcher() { @Override public String[] helperClassNames() { return new String[] { - getClass().getName() + "$WrappedFuture", JaxRsClientTracer.class.getName(), + getClass().getName() + "$WrappedFuture", + packageName + ".JaxRsClientTracer", + packageName + ".InjectAdapter", }; } From 8c67c988e1b116039a2656401417380aaab824bb Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 21:41:59 -0700 Subject: [PATCH 12/20] Revert unrelated change --- .../webclient/WebClientAutoConfiguration.java | 10 +--------- .../webclient/WebClientBeanPostProcessor.java | 6 +++--- .../webclient/WebClientBeanPostProcessorTest.java | 4 +--- .../webflux/client/SpringWebfluxHttpClientTracer.java | 10 ++++------ .../spring/webflux/client/WebClientTracingFilter.java | 10 +++++----- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java index 3e9f0eb70275..3cc2bfff75ac 100644 --- a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java +++ b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfiguration.java @@ -17,7 +17,6 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webclient; import io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.HttpClientsProperties; -import io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer; import io.opentelemetry.trace.Tracer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -43,14 +42,7 @@ public class WebClientAutoConfiguration { @Bean @Autowired - public SpringWebfluxHttpClientTracer otelSpringWebfluxHttpClientTracer(final Tracer tracer) { - return new SpringWebfluxHttpClientTracer(tracer); - } - - @Bean - @Autowired - public WebClientBeanPostProcessor otelWebClientBeanPostProcessor( - final SpringWebfluxHttpClientTracer tracer) { + public WebClientBeanPostProcessor otelWebClientBeanPostProcessor(final Tracer tracer) { return new WebClientBeanPostProcessor(tracer); } } diff --git a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java index b988ba09c11f..b218abe63a55 100644 --- a/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java +++ b/instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessor.java @@ -16,8 +16,8 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webclient; -import io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer; import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter; +import io.opentelemetry.trace.Tracer; import java.util.List; import java.util.function.Consumer; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -31,9 +31,9 @@ */ final class WebClientBeanPostProcessor implements BeanPostProcessor { - private final SpringWebfluxHttpClientTracer tracer; + private final Tracer tracer; - WebClientBeanPostProcessor(SpringWebfluxHttpClientTracer tracer) { + WebClientBeanPostProcessor(Tracer tracer) { this.tracer = tracer; } diff --git a/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java b/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java index 41d009ab63cf..484645987ea3 100644 --- a/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java +++ b/instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientBeanPostProcessorTest.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer; import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter; import io.opentelemetry.trace.Tracer; import org.junit.jupiter.api.DisplayName; @@ -33,8 +32,7 @@ class WebClientBeanPostProcessorTest { @Mock Tracer tracer; - WebClientBeanPostProcessor webClientBeanPostProcessor = - new WebClientBeanPostProcessor(new SpringWebfluxHttpClientTracer(tracer)); + WebClientBeanPostProcessor webClientBeanPostProcessor = new WebClientBeanPostProcessor(tracer); @Test @DisplayName( diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java index d649609c597f..c35470ee0c55 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxHttpClientTracer.java @@ -32,12 +32,6 @@ public class SpringWebfluxHttpClientTracer public static final SpringWebfluxHttpClientTracer TRACER = new SpringWebfluxHttpClientTracer(); - public SpringWebfluxHttpClientTracer(Tracer tracer) { - super(tracer); - } - - public SpringWebfluxHttpClientTracer() {} - public void onCancel(final Span span) { span.setAttribute("event", "cancelled"); span.setAttribute("message", "The subscription was cancelled"); @@ -78,4 +72,8 @@ protected Setter getSetter() { protected String getInstrumentationName() { return "io.opentelemetry.auto.spring-webflux-5.0"; } + + public Tracer getTracer() { + return tracer; + } } diff --git a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java index 175b6d8dde35..7dd34a9226a4 100644 --- a/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java +++ b/instrumentation-core/spring/spring-webflux-5.0/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/WebClientTracingFilter.java @@ -20,6 +20,7 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.trace.Span; +import io.opentelemetry.trace.Tracer; import java.util.List; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; @@ -29,19 +30,18 @@ public class WebClientTracingFilter implements ExchangeFilterFunction { - private final SpringWebfluxHttpClientTracer tracer; + private final Tracer tracer; - public WebClientTracingFilter(SpringWebfluxHttpClientTracer tracer) { + public WebClientTracingFilter(Tracer tracer) { this.tracer = tracer; } public static void addFilter(final List exchangeFilterFunctions) { - addFilter(exchangeFilterFunctions, TRACER); + addFilter(exchangeFilterFunctions, TRACER.getTracer()); } public static void addFilter( - final List exchangeFilterFunctions, - SpringWebfluxHttpClientTracer tracer) { + final List exchangeFilterFunctions, Tracer tracer) { exchangeFilterFunctions.add(0, new WebClientTracingFilter(tracer)); } From 83b14a02d05afe60c2fa8116f1c5debb8baa8e85 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 21:50:19 -0700 Subject: [PATCH 13/20] build --- .../instrumentation/api/tracer/HttpClientTracerTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientTracerTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientTracerTest.groovy index 41486fcedec7..137a3b58191b 100644 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientTracerTest.groovy +++ b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientTracerTest.groovy @@ -170,7 +170,7 @@ class HttpClientTracerTest extends BaseTracerTest { @Override def newTracer() { - return new HttpClientTracer() { + return new HttpClientTracer() { @Override protected String method(Map m) { From 9dd438e4e0e4c3d9b65da3834aecbbd2620371e3 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 14 Aug 2020 21:58:55 -0700 Subject: [PATCH 14/20] Simplify google-http-client --- .../GoogleHttpClientInstrumentation.java | 63 ++++++++----------- .../auto/googlehttpclient/RequestState.java | 55 ---------------- 2 files changed, 26 insertions(+), 92 deletions(-) delete mode 100644 instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/RequestState.java diff --git a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java index 41fa1b01aa39..cca66da11023 100644 --- a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java +++ b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java @@ -17,8 +17,6 @@ package io.opentelemetry.instrumentation.auto.googlehttpclient; import static io.opentelemetry.instrumentation.auto.googlehttpclient.GoogleHttpClientTracer.TRACER; -import static io.opentelemetry.instrumentation.auto.googlehttpclient.HeadersInjectAdapter.SETTER; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; import static java.util.Collections.singletonMap; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isPublic; @@ -29,9 +27,8 @@ import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.auto.service.AutoService; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.auto.api.ContextStore; import io.opentelemetry.instrumentation.auto.api.InstrumentationContext; import io.opentelemetry.trace.Span; @@ -59,15 +56,13 @@ public ElementMatcher typeMatcher() { @Override public Map contextStore() { - return singletonMap("com.google.api.client.http.HttpRequest", RequestState.class.getName()); + return singletonMap("com.google.api.client.http.HttpRequest", Span.class.getName()); } @Override public String[] helperClassNames() { return new String[] { - packageName + ".GoogleHttpClientTracer", - packageName + ".RequestState", - packageName + ".HeadersInjectAdapter" + packageName + ".GoogleHttpClientTracer", packageName + ".HeadersInjectAdapter" }; } @@ -91,39 +86,36 @@ public Map, String> transfor public static class GoogleHttpClientAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static void methodEnter(@Advice.This final HttpRequest request) { + public static void methodEnter( + @Advice.This final HttpRequest request, @Advice.Local("otelScope") Scope scope) { - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, RequestState.class); + ContextStore contextStore = + InstrumentationContext.get(HttpRequest.class, Span.class); - RequestState state = contextStore.get(request); + Span span = contextStore.get(request); - if (state == null) { - state = new RequestState(TRACER.startSpan(request)); - contextStore.put(request, state); + if (span == null) { + span = TRACER.startSpan(request); + contextStore.put(request, span); } - Span span = state.getSpan(); - - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators() - .getHttpTextFormat() - .inject(context, request.getHeaders(), SETTER); + scope = TRACER.startScope(span, request.getHeaders()); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void methodExit( @Advice.This final HttpRequest request, @Advice.Return final HttpResponse response, - @Advice.Thrown final Throwable throwable) { + @Advice.Thrown final Throwable throwable, + @Advice.Local("otelScope") Scope scope) { - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, RequestState.class); - RequestState state = contextStore.get(request); + scope.close(); - if (state != null) { - Span span = state.getSpan(); + ContextStore contextStore = + InstrumentationContext.get(HttpRequest.class, Span.class); + Span span = contextStore.get(request); + if (span != null) { if (throwable == null) { TRACER.end(span, response); } else { @@ -144,11 +136,10 @@ public static class GoogleHttpClientAsyncAdvice { public static void methodEnter(@Advice.This final HttpRequest request) { Span span = TRACER.startSpan(request); - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, RequestState.class); + ContextStore contextStore = + InstrumentationContext.get(HttpRequest.class, Span.class); - RequestState state = new RequestState(span); - contextStore.put(request, state); + contextStore.put(request, span); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) @@ -157,13 +148,11 @@ public static void methodExit( if (throwable != null) { - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, RequestState.class); - RequestState state = contextStore.get(request); - - if (state != null) { - Span span = state.getSpan(); + ContextStore contextStore = + InstrumentationContext.get(HttpRequest.class, Span.class); + Span span = contextStore.get(request); + if (span != null) { TRACER.endExceptionally(span, throwable); } } diff --git a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/RequestState.java b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/RequestState.java deleted file mode 100644 index ad292ee021e6..000000000000 --- a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/RequestState.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.instrumentation.auto.googlehttpclient; - -import io.opentelemetry.trace.Span; -import java.util.Objects; - -public class RequestState { - - private Span span; - - public RequestState(Span span) { - setSpan(span); - } - - public Span getSpan() { - return span; - } - - public void setSpan(Span span) { - Objects.requireNonNull(span); - this.span = span; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - RequestState that = (RequestState) o; - return Objects.equals(span, that.span); - } - - @Override - public int hashCode() { - return Objects.hash(span); - } -} From 258bf1afcef8bbbd2eb077ede2ecfb1ed55247ea Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sat, 15 Aug 2020 11:15:31 -0700 Subject: [PATCH 15/20] more --- .../GoogleHttpClientInstrumentation.java | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java index cca66da11023..fe969e22e27c 100644 --- a/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java +++ b/instrumentation/google-http-client-1.19/src/main/java/io/opentelemetry/instrumentation/auto/googlehttpclient/GoogleHttpClientInstrumentation.java @@ -27,12 +27,15 @@ import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.auto.service.AutoService; +import io.grpc.Context; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.ContextUtils; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.auto.api.ContextStore; import io.opentelemetry.instrumentation.auto.api.InstrumentationContext; import io.opentelemetry.trace.Span; import io.opentelemetry.trace.Status; +import io.opentelemetry.trace.TracingContextUtils; import java.util.HashMap; import java.util.Map; import net.bytebuddy.asm.Advice; @@ -56,7 +59,7 @@ public ElementMatcher typeMatcher() { @Override public Map contextStore() { - return singletonMap("com.google.api.client.http.HttpRequest", Span.class.getName()); + return singletonMap("com.google.api.client.http.HttpRequest", Context.class.getName()); } @Override @@ -87,45 +90,44 @@ public Map, String> transfor public static class GoogleHttpClientAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static void methodEnter( - @Advice.This final HttpRequest request, @Advice.Local("otelScope") Scope scope) { - - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, Span.class); + @Advice.This final HttpRequest request, + @Advice.Local("otelSpan") Span span, + @Advice.Local("otelScope") Scope scope) { - Span span = contextStore.get(request); + ContextStore contextStore = + InstrumentationContext.get(HttpRequest.class, Context.class); + Context context = contextStore.get(request); - if (span == null) { + if (context == null) { span = TRACER.startSpan(request); - contextStore.put(request, span); + scope = TRACER.startScope(span, request.getHeaders()); + // TODO (trask) ideally we could pass current context into startScope to avoid extra lookup + contextStore.put(request, Context.current()); + } else { + // span was created by GoogleHttpClientAsyncAdvice instrumentation below + span = TracingContextUtils.getSpan(context); + scope = ContextUtils.withScopedContext(context); } - - scope = TRACER.startScope(span, request.getHeaders()); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void methodExit( - @Advice.This final HttpRequest request, @Advice.Return final HttpResponse response, @Advice.Thrown final Throwable throwable, + @Advice.Local("otelSpan") Span span, @Advice.Local("otelScope") Scope scope) { scope.close(); - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, Span.class); - Span span = contextStore.get(request); - - if (span != null) { - if (throwable == null) { - TRACER.end(span, response); - } else { - TRACER.endExceptionally(span, response, throwable); - } - // If HttpRequest.setThrowExceptionOnExecuteError is set to false, there are no exceptions - // for a failed request. Thus, check the response code - if (response != null && !response.isSuccessStatusCode()) { - span.setStatus(Status.UNKNOWN); - } + if (throwable == null) { + TRACER.end(span, response); + } else { + TRACER.endExceptionally(span, response, throwable); + } + // If HttpRequest.setThrowExceptionOnExecuteError is set to false, there are no exceptions + // for a failed request. Thus, check the response code + if (response != null && !response.isSuccessStatusCode()) { + span.setStatus(Status.UNKNOWN); } } } @@ -133,28 +135,30 @@ public static void methodExit( public static class GoogleHttpClientAsyncAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static void methodEnter(@Advice.This final HttpRequest request) { - Span span = TRACER.startSpan(request); + public static void methodEnter( + @Advice.This final HttpRequest request, + @Advice.Local("otelSpan") Span span, + @Advice.Local("otelScope") Scope scope) { - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, Span.class); + span = TRACER.startSpan(request); + scope = TRACER.startScope(span, request.getHeaders()); - contextStore.put(request, span); + // propagating the context manually here so this instrumentation will work with and without + // the java-concurrent instrumentation + ContextStore contextStore = + InstrumentationContext.get(HttpRequest.class, Context.class); + contextStore.put(request, Context.current()); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void methodExit( - @Advice.This final HttpRequest request, @Advice.Thrown final Throwable throwable) { + @Advice.Thrown final Throwable throwable, + @Advice.Local("otelSpan") Span span, + @Advice.Local("otelScope") Scope scope) { + scope.close(); if (throwable != null) { - - ContextStore contextStore = - InstrumentationContext.get(HttpRequest.class, Span.class); - Span span = contextStore.get(request); - - if (span != null) { - TRACER.endExceptionally(span, throwable); - } + TRACER.endExceptionally(span, throwable); } } } From 57ac54b748b68f773cb09bd5b790877abac1d913 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sat, 15 Aug 2020 11:44:56 -0700 Subject: [PATCH 16/20] more --- .../ApacheHttpAsyncClientInstrumentation.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientInstrumentation.java b/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientInstrumentation.java index 01e928a45187..ff4d53188d49 100644 --- a/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientInstrumentation.java +++ b/instrumentation/apache-httpasyncclient-4.0/src/main/java/io/opentelemetry/instrumentation/auto/apachehttpasyncclient/ApacheHttpAsyncClientInstrumentation.java @@ -20,9 +20,7 @@ import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface; import static io.opentelemetry.instrumentation.api.tracer.HttpClientTracer.DEFAULT_SPAN_NAME; import static io.opentelemetry.instrumentation.auto.apachehttpasyncclient.ApacheHttpAsyncClientTracer.TRACER; -import static io.opentelemetry.instrumentation.auto.apachehttpasyncclient.HttpHeadersInjectAdapter.SETTER; import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; -import static io.opentelemetry.trace.TracingContextUtils.withSpan; import static java.util.Collections.singletonMap; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.named; @@ -30,8 +28,6 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import com.google.auto.service.AutoService; -import io.grpc.Context; -import io.opentelemetry.OpenTelemetry; import io.opentelemetry.auto.tooling.Instrumenter; import io.opentelemetry.context.Scope; import io.opentelemetry.trace.Span; @@ -142,8 +138,9 @@ public HttpRequest generateRequest() throws IOException, HttpException { span.updateName(TRACER.spanNameForRequest(request)); TRACER.onRequest(span, request); - Context context = withSpan(span, Context.current()); - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, SETTER); + // TODO (trask) expose inject separate from startScope, e.g. for async cases + Scope scope = TRACER.startScope(span, request); + scope.close(); return request; } From ce45ba0403638f165473fc7c8fecf02b18e3523f Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 17 Aug 2020 12:25:17 -0700 Subject: [PATCH 17/20] Rename HEADERS to CARRIER --- .../instrumentation/api/tracer/HttpClientTracer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientTracer.java index bd9c7d533399..405a46f04d41 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientTracer.java @@ -38,7 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class HttpClientTracer extends BaseTracer { +public abstract class HttpClientTracer extends BaseTracer { private static final Logger log = LoggerFactory.getLogger(HttpClientTracer.class); @@ -56,7 +56,7 @@ public abstract class HttpClientTracer extends BaseT protected abstract String responseHeader(RESPONSE response, String name); - protected abstract HttpTextFormat.Setter getSetter(); + protected abstract HttpTextFormat.Setter getSetter(); protected HttpClientTracer() { super(); @@ -74,15 +74,15 @@ public Span startSpan(REQUEST request, long startTimeNanos) { return startSpan(request, spanNameForRequest(request), startTimeNanos); } - public Scope startScope(Span span, HEADERS headers) { + public Scope startScope(Span span, CARRIER carrier) { Context context = withSpan(span, Context.current()); - Setter setter = getSetter(); + Setter setter = getSetter(); if (setter == null) { throw new IllegalStateException( "getSetter() not defined but calling startScope(), either getSetter must be implemented or the scope should be setup manually"); } - OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, headers, setter); + OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, carrier, setter); context = context.withValue(CONTEXT_CLIENT_SPAN_KEY, span); return withScopedContext(context); } From 83ffab161cf5e7c4b54b3677069860ae1984dd01 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 17 Aug 2020 12:28:42 -0700 Subject: [PATCH 18/20] Don't use weird carrier types --- .../auto/grizzly/client/GrizzlyClientRequestAdvice.java | 2 +- .../auto/grizzly/client/GrizzlyClientTracer.java | 6 ++---- .../auto/grizzly/client/GrizzlyInjectAdapter.java | 9 ++++----- .../auto/jaxrsclient/v1_1/InjectAdapter.java | 8 ++++---- .../jaxrsclient/v1_1/JaxRsClientV1Instrumentation.java | 2 +- .../auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java | 5 ++--- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientRequestAdvice.java b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientRequestAdvice.java index c0804096029b..169f50115ff1 100644 --- a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientRequestAdvice.java +++ b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientRequestAdvice.java @@ -37,7 +37,7 @@ public static Scope onEnter( Span span = TRACER.startSpan(request); InstrumentationContext.get(AsyncHandler.class, Pair.class) .put(handler, Pair.of(parentContext, span)); - return TRACER.startScope(span, request.getHeaders()); + return TRACER.startScope(span, request); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) diff --git a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java index 4ae7374ba292..1b6e55c647bd 100644 --- a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java +++ b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyClientTracer.java @@ -16,7 +16,6 @@ package io.opentelemetry.instrumentation.auto.grizzly.client; -import com.ning.http.client.FluentCaseInsensitiveStringsMap; import com.ning.http.client.Request; import com.ning.http.client.Response; import io.opentelemetry.context.propagation.HttpTextFormat.Setter; @@ -24,8 +23,7 @@ import java.net.URI; import java.net.URISyntaxException; -public class GrizzlyClientTracer - extends HttpClientTracer { +public class GrizzlyClientTracer extends HttpClientTracer { public static final GrizzlyClientTracer TRACER = new GrizzlyClientTracer(); @@ -55,7 +53,7 @@ protected String responseHeader(Response response, String name) { } @Override - protected Setter getSetter() { + protected Setter getSetter() { return GrizzlyInjectAdapter.SETTER; } diff --git a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java index 786e4f9d97ab..1daa76d21262 100644 --- a/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java +++ b/instrumentation/grizzly-client-1.9/src/main/java/io/opentelemetry/instrumentation/auto/grizzly/client/GrizzlyInjectAdapter.java @@ -16,16 +16,15 @@ package io.opentelemetry.instrumentation.auto.grizzly.client; -import com.ning.http.client.FluentCaseInsensitiveStringsMap; +import com.ning.http.client.Request; import io.opentelemetry.context.propagation.HttpTextFormat; -public class GrizzlyInjectAdapter - implements HttpTextFormat.Setter { +public class GrizzlyInjectAdapter implements HttpTextFormat.Setter { public static final GrizzlyInjectAdapter SETTER = new GrizzlyInjectAdapter(); @Override - public void set(FluentCaseInsensitiveStringsMap carrier, String key, String value) { - carrier.replaceWith(key, value); + public void set(Request carrier, String key, String value) { + carrier.getHeaders().replaceWith(key, value); } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java index cac1d092e3e1..b981a0968bf0 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/InjectAdapter.java @@ -16,15 +16,15 @@ package io.opentelemetry.instrumentation.auto.jaxrsclient.v1_1; +import com.sun.jersey.api.client.ClientRequest; import io.opentelemetry.context.propagation.HttpTextFormat; -import javax.ws.rs.core.MultivaluedMap; -public final class InjectAdapter implements HttpTextFormat.Setter> { +public final class InjectAdapter implements HttpTextFormat.Setter { public static final InjectAdapter SETTER = new InjectAdapter(); @Override - public void set(MultivaluedMap carrier, String key, String value) { - carrier.putSingle(key, value); + public void set(ClientRequest carrier, String key, String value) { + carrier.getHeaders().putSingle(key, value); } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Instrumentation.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Instrumentation.java index 2ba94484173b..10606d6d1eca 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Instrumentation.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Instrumentation.java @@ -86,7 +86,7 @@ public static void onEnter( boolean isRootClientHandler = null == request.getProperties().get(CONTEXT_ATTRIBUTE); if (isRootClientHandler) { span = TRACER.startSpan(request); - scope = TRACER.startScope(span, request.getHeaders()); + scope = TRACER.startScope(span, request); } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java index 02ac11651d2f..ea7831e068b7 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v1_1/JaxRsClientV1Tracer.java @@ -23,10 +23,9 @@ import io.opentelemetry.context.propagation.HttpTextFormat.Setter; import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer; import java.net.URI; -import javax.ws.rs.core.MultivaluedMap; public class JaxRsClientV1Tracer - extends HttpClientTracer, ClientResponse> { + extends HttpClientTracer { public static final JaxRsClientV1Tracer TRACER = new JaxRsClientV1Tracer(); @Override @@ -56,7 +55,7 @@ protected String responseHeader(ClientResponse clientResponse, String name) { } @Override - protected Setter> getSetter() { + protected Setter getSetter() { return SETTER; } From 9bfcb28885e27071afd13eb3ab2b4426cc9fd38a Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 18 Aug 2020 16:01:12 -0700 Subject: [PATCH 19/20] feedback --- .../auto/jaxrsclient/v2_0/InjectAdapter.java | 8 ++++---- .../auto/jaxrsclient/v2_0/JaxRsClientTracer.java | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/InjectAdapter.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/InjectAdapter.java index 13fa79d4cb76..a9418b26f755 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/InjectAdapter.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/InjectAdapter.java @@ -17,15 +17,15 @@ package io.opentelemetry.instrumentation.auto.jaxrsclient.v2_0; import io.opentelemetry.context.propagation.HttpTextFormat; -import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.client.ClientRequestContext; -public final class InjectAdapter implements HttpTextFormat.Setter { +public final class InjectAdapter implements HttpTextFormat.Setter { public static final InjectAdapter SETTER = new InjectAdapter(); @Override - public void set(MultivaluedMap headers, String key, String value) { + public void set(ClientRequestContext carrier, String key, String value) { // Don't allow duplicates. - headers.putSingle(key, value); + carrier.getHeaders().putSingle(key, value); } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java index ddad1c17302b..f1f269c4a59b 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/JaxRsClientTracer.java @@ -23,10 +23,9 @@ import java.net.URI; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientResponseContext; -import javax.ws.rs.core.MultivaluedMap; public class JaxRsClientTracer - extends HttpClientTracer { + extends HttpClientTracer { public static final JaxRsClientTracer TRACER = new JaxRsClientTracer(); @Override @@ -55,7 +54,7 @@ protected String responseHeader(ClientResponseContext clientResponseContext, Str } @Override - protected Setter getSetter() { + protected Setter getSetter() { return SETTER; } From ce64a1eeeab73e89d6d09d03c22fba4572883374 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 18 Aug 2020 16:07:38 -0700 Subject: [PATCH 20/20] fix --- .../auto/jaxrsclient/v2_0/ClientTracingFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java index 5141113aee60..798e675391c0 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrsclient/v2_0/ClientTracingFilter.java @@ -35,7 +35,7 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF public void filter(ClientRequestContext requestContext) { Span span = TRACER.startSpan(requestContext); // TODO (trask) expose inject separate from startScope, e.g. for async cases - Scope scope = TRACER.startScope(span, requestContext.getHeaders()); + Scope scope = TRACER.startScope(span, requestContext); scope.close(); requestContext.setProperty(SPAN_PROPERTY_NAME, span); }