Change the rest of decorators to tracers (#922)
This commit is contained in:
parent
a0dc9ba19c
commit
09c597e8e0
|
@ -16,9 +16,8 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.spring.httpclients;
|
||||
|
||||
import static io.opentelemetry.instrumentation.spring.httpclients.RestTemplateDecorator.DECORATE;
|
||||
import static io.opentelemetry.instrumentation.spring.httpclients.RestTemplateTracer.TRACER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
|
@ -41,18 +40,11 @@ public final class RestTemplateInterceptor implements ClientHttpRequestIntercept
|
|||
public ClientHttpResponse intercept(
|
||||
HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
|
||||
|
||||
Span clientSpan = DECORATE.getOrCreateSpan(request, tracer);
|
||||
|
||||
try (Scope scope = tracer.withSpan(clientSpan)) {
|
||||
DECORATE.onRequest(clientSpan, request);
|
||||
DECORATE.inject(Context.current(), request);
|
||||
|
||||
Span span = TRACER.startSpan(request);
|
||||
try (Scope scope = TRACER.startScope(span, request)) {
|
||||
ClientHttpResponse response = execution.execute(request, body);
|
||||
DECORATE.onResponse(clientSpan, response);
|
||||
|
||||
TRACER.end(span, response);
|
||||
return response;
|
||||
} finally {
|
||||
clientSpan.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ import static io.opentelemetry.OpenTelemetry.getPropagators;
|
|||
import static io.opentelemetry.instrumentation.spring.httpclients.HttpHeadersInjectAdapter.SETTER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
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;
|
||||
|
@ -28,12 +29,12 @@ import org.springframework.http.HttpRequest;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
|
||||
class RestTemplateDecorator extends HttpClientDecorator<HttpRequest, ClientHttpResponse> {
|
||||
class RestTemplateTracer extends HttpClientTracer<HttpRequest, ClientHttpResponse> {
|
||||
|
||||
public static final RestTemplateDecorator DECORATE = new RestTemplateDecorator();
|
||||
public static final RestTemplateTracer TRACER = new RestTemplateTracer();
|
||||
|
||||
public void inject(Context context, HttpRequest request) {
|
||||
getPropagators().getHttpTextFormat().inject(context, request, SETTER);
|
||||
getPropagators().getHttpTextFormat().inject(context, request, getSetter());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,4 +65,14 @@ class RestTemplateDecorator extends HttpClientDecorator<HttpRequest, ClientHttpR
|
|||
protected String responseHeader(ClientHttpResponse response, String name) {
|
||||
return response.getHeaders().getFirst(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<HttpRequest> getSetter() {
|
||||
return SETTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.spring-web-3.1";
|
||||
}
|
||||
}
|
|
@ -17,11 +17,11 @@
|
|||
package io.opentelemetry.instrumentation.spring.webflux.client;
|
||||
|
||||
import static io.opentelemetry.OpenTelemetry.getPropagators;
|
||||
import static io.opentelemetry.OpenTelemetry.getTracerProvider;
|
||||
import static io.opentelemetry.instrumentation.spring.webflux.client.HttpHeadersInjectAdapter.SETTER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
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;
|
||||
|
@ -30,12 +30,9 @@ import org.springframework.http.HttpHeaders;
|
|||
import org.springframework.web.reactive.function.client.ClientRequest;
|
||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
|
||||
class SpringWebfluxHttpClientDecorator extends HttpClientDecorator<ClientRequest, ClientResponse> {
|
||||
class SpringWebfluxHttpClientTracer extends HttpClientTracer<ClientRequest, ClientResponse> {
|
||||
|
||||
public static final Tracer TRACER =
|
||||
getTracerProvider().get("io.opentelemetry.auto.spring-webflux-5.0");
|
||||
public static final SpringWebfluxHttpClientDecorator DECORATE =
|
||||
new SpringWebfluxHttpClientDecorator();
|
||||
public static final SpringWebfluxHttpClientTracer TRACER = new SpringWebfluxHttpClientTracer();
|
||||
|
||||
public void onCancel(final Span span) {
|
||||
span.setAttribute("event", "cancelled");
|
||||
|
@ -71,4 +68,18 @@ class SpringWebfluxHttpClientDecorator extends HttpClientDecorator<ClientRequest
|
|||
List<String> headers = clientResponse.headers().header(name);
|
||||
return !headers.isEmpty() ? headers.get(0) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<ClientRequest> getSetter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.spring-webflux-5.0";
|
||||
}
|
||||
|
||||
public Tracer getTracer() {
|
||||
return tracer;
|
||||
}
|
||||
}
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.spring.webflux.client;
|
||||
|
||||
import static io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientDecorator.TRACER;
|
||||
import static io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer.TRACER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
|
@ -39,7 +38,7 @@ public class WebClientTracingFilter implements ExchangeFilterFunction {
|
|||
}
|
||||
|
||||
public static void addFilter(final List<ExchangeFilterFunction> exchangeFilterFunctions) {
|
||||
addFilter(exchangeFilterFunctions, TRACER);
|
||||
addFilter(exchangeFilterFunctions, TRACER.getTracer());
|
||||
}
|
||||
|
||||
public static void addFilter(
|
||||
|
@ -49,32 +48,25 @@ public class WebClientTracingFilter implements ExchangeFilterFunction {
|
|||
|
||||
@Override
|
||||
public Mono<ClientResponse> filter(final ClientRequest request, final ExchangeFunction next) {
|
||||
Span span = DECORATE.getOrCreateSpan(request, tracer);
|
||||
DECORATE.afterStart(span);
|
||||
Span span = TRACER.startSpan(request);
|
||||
|
||||
try (Scope scope = tracer.withSpan(span)) {
|
||||
ClientRequest mutatedRequest =
|
||||
ClientRequest.from(request)
|
||||
.headers(httpHeaders -> DECORATE.inject(Context.current(), httpHeaders))
|
||||
.headers(httpHeaders -> TRACER.inject(Context.current(), httpHeaders))
|
||||
.build();
|
||||
DECORATE.onRequest(span, mutatedRequest);
|
||||
|
||||
return next.exchange(mutatedRequest)
|
||||
.doOnSuccessOrError(
|
||||
(clientResponse, throwable) -> {
|
||||
if (throwable != null) {
|
||||
DECORATE.onError(span, throwable);
|
||||
TRACER.endExceptionally(span, clientResponse, throwable);
|
||||
} else {
|
||||
DECORATE.onResponse(span, clientResponse);
|
||||
TRACER.end(span, clientResponse);
|
||||
}
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
})
|
||||
.doOnCancel(
|
||||
() -> {
|
||||
DECORATE.onCancel(span);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.end(span);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,11 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.apachehttpasyncclient;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientTracer.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpasyncclient.HttpHeadersInjectAdapter.SETTER;
|
||||
import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator.DEFAULT_SPAN_NAME;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.currentContextWith;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
import static java.util.Collections.singletonMap;
|
||||
|
@ -78,7 +76,7 @@ public class ApacheHttpAsyncClientInstrumentation extends Instrumenter.Default {
|
|||
packageName + ".HttpHeadersInjectAdapter",
|
||||
getClass().getName() + "$DelegatingRequestProducer",
|
||||
getClass().getName() + "$TraceContinuedFutureCallback",
|
||||
packageName + ".ApacheHttpAsyncClientDecorator"
|
||||
packageName + ".ApacheHttpAsyncClientTracer"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -104,8 +102,7 @@ public class ApacheHttpAsyncClientInstrumentation extends Instrumenter.Default {
|
|||
@Advice.Argument(value = 3, readOnly = false) FutureCallback<?> futureCallback) {
|
||||
|
||||
Span parentSpan = TRACER.getCurrentSpan();
|
||||
Span clientSpan = TRACER.spanBuilder(DEFAULT_SPAN_NAME).setSpanKind(CLIENT).startSpan();
|
||||
DECORATE.afterStart(clientSpan);
|
||||
Span clientSpan = TRACER.startSpan(DEFAULT_SPAN_NAME);
|
||||
|
||||
requestProducer = new DelegatingRequestProducer(clientSpan, requestProducer);
|
||||
futureCallback =
|
||||
|
@ -120,9 +117,7 @@ public class ApacheHttpAsyncClientInstrumentation extends Instrumenter.Default {
|
|||
@Advice.Return final Object result,
|
||||
@Advice.Thrown final Throwable throwable) {
|
||||
if (throwable != null) {
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,8 +139,8 @@ public class ApacheHttpAsyncClientInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public HttpRequest generateRequest() throws IOException, HttpException {
|
||||
HttpRequest request = delegate.generateRequest();
|
||||
span.updateName(DECORATE.spanNameForRequest(request));
|
||||
DECORATE.onRequest(span, request);
|
||||
span.updateName(TRACER.spanNameForRequest(request));
|
||||
TRACER.onRequest(span, request);
|
||||
|
||||
Context context = withSpan(span, Context.current());
|
||||
OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, SETTER);
|
||||
|
@ -205,9 +200,7 @@ public class ApacheHttpAsyncClientInstrumentation extends Instrumenter.Default {
|
|||
|
||||
@Override
|
||||
public void completed(final T result) {
|
||||
DECORATE.onResponse(clientSpan, getResponse(context));
|
||||
DECORATE.beforeFinish(clientSpan);
|
||||
clientSpan.end(); // end span before calling delegate
|
||||
TRACER.end(clientSpan, getResponse(context));
|
||||
|
||||
if (parentSpan == null) {
|
||||
completeDelegate(result);
|
||||
|
@ -220,10 +213,8 @@ public class ApacheHttpAsyncClientInstrumentation extends Instrumenter.Default {
|
|||
|
||||
@Override
|
||||
public void failed(final Exception ex) {
|
||||
DECORATE.onResponse(clientSpan, getResponse(context));
|
||||
DECORATE.onError(clientSpan, ex);
|
||||
DECORATE.beforeFinish(clientSpan);
|
||||
clientSpan.end(); // end span before calling delegate
|
||||
// end span before calling delegate
|
||||
TRACER.endExceptionally(clientSpan, getResponse(context), ex);
|
||||
|
||||
if (parentSpan == null) {
|
||||
failDelegate(ex);
|
||||
|
@ -236,9 +227,8 @@ public class ApacheHttpAsyncClientInstrumentation extends Instrumenter.Default {
|
|||
|
||||
@Override
|
||||
public void cancelled() {
|
||||
DECORATE.onResponse(clientSpan, getResponse(context));
|
||||
DECORATE.beforeFinish(clientSpan);
|
||||
clientSpan.end(); // end span before calling delegate
|
||||
// end span before calling delegate
|
||||
TRACER.end(clientSpan, getResponse(context));
|
||||
|
||||
if (parentSpan == null) {
|
||||
cancelDelegate();
|
||||
|
|
|
@ -16,9 +16,12 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.apachehttpasyncclient;
|
||||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpasyncclient.HttpHeadersInjectAdapter.SETTER;
|
||||
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import org.apache.http.Header;
|
||||
|
@ -29,13 +32,9 @@ import org.apache.http.RequestLine;
|
|||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
||||
public class ApacheHttpAsyncClientDecorator extends HttpClientDecorator<HttpRequest, HttpResponse> {
|
||||
public class ApacheHttpAsyncClientTracer extends HttpClientTracer<HttpRequest, HttpResponse> {
|
||||
|
||||
public static final ApacheHttpAsyncClientDecorator DECORATE =
|
||||
new ApacheHttpAsyncClientDecorator();
|
||||
|
||||
public static final Tracer TRACER =
|
||||
OpenTelemetry.getTracerProvider().get("io.opentelemetry.auto.apache-httpasyncclient-4.0");
|
||||
public static final ApacheHttpAsyncClientTracer TRACER = new ApacheHttpAsyncClientTracer();
|
||||
|
||||
@Override
|
||||
protected String method(final HttpRequest request) {
|
||||
|
@ -78,8 +77,38 @@ public class ApacheHttpAsyncClientDecorator extends HttpClientDecorator<HttpRequ
|
|||
return header(response, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<HttpRequest> getSetter() {
|
||||
return SETTER;
|
||||
}
|
||||
|
||||
private static String header(HttpMessage message, String name) {
|
||||
Header header = message.getFirstHeader(name);
|
||||
return header != null ? header.getValue() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.apache-httpasyncclient-4.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to generate an acceptable CLIENT span (operation) name based on a given
|
||||
* name.
|
||||
*/
|
||||
@Override
|
||||
public Span startSpan(String spanName) {
|
||||
return tracer.spanBuilder(spanName).setSpanKind(Kind.CLIENT).startSpan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String spanNameForRequest(HttpRequest httpRequest) {
|
||||
return super.spanNameForRequest(httpRequest);
|
||||
}
|
||||
|
||||
/** This method is overridden to allow other classes in this package to call it. */
|
||||
@Override
|
||||
public Span onRequest(Span span, HttpRequest httpRequest) {
|
||||
return super.onRequest(span, httpRequest);
|
||||
}
|
||||
}
|
|
@ -16,42 +16,21 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.ApacheHttpClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.context.ContextUtils.withScopedContext;
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.ApacheHttpClientTracer.TRACER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.decorator.ClientDecorator;
|
||||
import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap;
|
||||
import io.opentelemetry.instrumentation.auto.api.SpanWithScope;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
||||
public class ApacheHttpClientHelper {
|
||||
|
||||
public static final Tracer TRACER =
|
||||
OpenTelemetry.getTracerProvider().get("io.opentelemetry.auto.spring-webflux-5.0");
|
||||
|
||||
public static SpanWithScope doMethodEnter(final HttpUriRequest request) {
|
||||
return doMethodEnter(request, TRACER);
|
||||
}
|
||||
|
||||
public static SpanWithScope doMethodEnter(final HttpUriRequest request, final Tracer tracer) {
|
||||
Span span = DECORATE.getOrCreateSpan(request, tracer);
|
||||
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, request);
|
||||
|
||||
Context context = ClientDecorator.currentContextWith(span);
|
||||
if (span.getContext().isValid()) {
|
||||
DECORATE.inject(context, request);
|
||||
}
|
||||
Scope scope = withScopedContext(context);
|
||||
|
||||
Span span = TRACER.startSpan(request);
|
||||
Scope scope = TRACER.startScope(span, request);
|
||||
return new SpanWithScope(span, scope);
|
||||
}
|
||||
|
||||
|
@ -69,14 +48,14 @@ public class ApacheHttpClientHelper {
|
|||
final SpanWithScope spanWithScope, final Object result, final Throwable throwable) {
|
||||
try {
|
||||
Span span = spanWithScope.getSpan();
|
||||
|
||||
if (result instanceof HttpResponse) {
|
||||
DECORATE.onResponse(span, (HttpResponse) result);
|
||||
} // else they probably provided a ResponseHandler.
|
||||
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.onResponse(span, (HttpResponse) result);
|
||||
} // else they probably provided a ResponseHandler
|
||||
if (throwable != null) {
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
} else {
|
||||
TRACER.end(span);
|
||||
}
|
||||
} finally {
|
||||
spanWithScope.closeScope();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ApacheHttpClientInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.ApacheHttpClientDecorator",
|
||||
"io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.ApacheHttpClientTracer",
|
||||
"io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.HttpHeadersInjectAdapter",
|
||||
"io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.HostAndRequestAsHttpUriRequest",
|
||||
"io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.ApacheHttpClientHelper",
|
||||
|
|
|
@ -16,23 +16,20 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.HttpHeadersInjectAdapter.SETTER;
|
||||
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import java.net.URI;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpMessage;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
||||
class ApacheHttpClientDecorator extends HttpClientDecorator<HttpUriRequest, HttpResponse> {
|
||||
public static final ApacheHttpClientDecorator DECORATE = new ApacheHttpClientDecorator();
|
||||
class ApacheHttpClientTracer extends HttpClientTracer<HttpUriRequest, HttpResponse> {
|
||||
|
||||
public void inject(Context context, HttpUriRequest request) {
|
||||
OpenTelemetry.getPropagators()
|
||||
.getHttpTextFormat()
|
||||
.inject(context, request, HttpHeadersInjectAdapter.SETTER);
|
||||
}
|
||||
public static final ApacheHttpClientTracer TRACER = new ApacheHttpClientTracer();
|
||||
|
||||
@Override
|
||||
protected String method(final HttpUriRequest httpRequest) {
|
||||
|
@ -59,8 +56,24 @@ class ApacheHttpClientDecorator extends HttpClientDecorator<HttpUriRequest, Http
|
|||
return header(response, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<HttpUriRequest> getSetter() {
|
||||
return SETTER;
|
||||
}
|
||||
|
||||
private static String header(HttpMessage message, String name) {
|
||||
Header header = message.getFirstHeader(name);
|
||||
return header != null ? header.getValue() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.apache-httpclient-4.0";
|
||||
}
|
||||
|
||||
/** This method is overridden to allow other classes in this package to call it. */
|
||||
@Override
|
||||
protected Span onResponse(Span span, HttpResponse httpResponse) {
|
||||
return super.onResponse(span, httpResponse);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.ApacheHttpClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.ApacheHttpClientTracer.TRACER;
|
||||
|
||||
import io.opentelemetry.trace.Span;
|
||||
import java.io.IOException;
|
||||
|
@ -37,7 +37,7 @@ public class WrappingStatusSettingResponseHandler implements ResponseHandler {
|
|||
public Object handleResponse(final HttpResponse response)
|
||||
throws ClientProtocolException, IOException {
|
||||
if (null != span) {
|
||||
DECORATE.onResponse(span, response);
|
||||
TRACER.onResponse(span, response);
|
||||
}
|
||||
return handler.handleResponse(response);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.awssdk.v1_11;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.awssdk.v1_11.OnErrorTracer.ERROR_TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.awssdk.v1_11.AwsSdkClientTracer.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.awssdk.v1_11.RequestMeta.SPAN_SCOPE_PAIR_CONTEXT_KEY;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
|
||||
|
@ -30,7 +30,6 @@ import com.amazonaws.handlers.RequestHandler2;
|
|||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
||||
import io.opentelemetry.instrumentation.auto.api.SpanWithScope;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
|
@ -57,7 +56,7 @@ public class AWSHttpClientInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".OnErrorTracer", packageName + ".RequestMeta",
|
||||
packageName + ".AwsSdkClientTracer", packageName + ".RequestMeta",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -77,8 +76,7 @@ public class AWSHttpClientInstrumentation extends Instrumenter.Default {
|
|||
SpanWithScope scope = request.getHandlerContext(SPAN_SCOPE_PAIR_CONTEXT_KEY);
|
||||
if (scope != null) {
|
||||
request.addHandlerContext(SPAN_SCOPE_PAIR_CONTEXT_KEY, null);
|
||||
Span span = scope.getSpan();
|
||||
ERROR_TRACER.endExceptionally(span, throwable);
|
||||
TRACER.endExceptionally(scope.getSpan(), throwable);
|
||||
scope.closeScope();
|
||||
}
|
||||
}
|
||||
|
@ -113,8 +111,7 @@ public class AWSHttpClientInstrumentation extends Instrumenter.Default {
|
|||
SpanWithScope scope = request.getHandlerContext(SPAN_SCOPE_PAIR_CONTEXT_KEY);
|
||||
if (scope != null) {
|
||||
request.addHandlerContext(SPAN_SCOPE_PAIR_CONTEXT_KEY, null);
|
||||
Span span = scope.getSpan();
|
||||
ERROR_TRACER.endExceptionally(span, throwable);
|
||||
TRACER.endExceptionally(scope.getSpan(), throwable);
|
||||
scope.closeScope();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,17 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.awssdk.v1_11;
|
||||
|
||||
import static io.opentelemetry.context.ContextUtils.withScopedContext;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
|
||||
import com.amazonaws.AmazonWebServiceRequest;
|
||||
import com.amazonaws.AmazonWebServiceResponse;
|
||||
import com.amazonaws.Request;
|
||||
import com.amazonaws.Response;
|
||||
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.instrumentation.auto.api.ContextStore;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
@ -32,13 +36,12 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Response<?>
|
|||
|
||||
static final String COMPONENT_NAME = "java-aws-sdk";
|
||||
|
||||
public static final AwsSdkClientTracer TRACER = new AwsSdkClientTracer();
|
||||
|
||||
private final Map<String, String> serviceNames = new ConcurrentHashMap<>();
|
||||
private final Map<Class, String> operationNames = new ConcurrentHashMap<>();
|
||||
private final ContextStore<AmazonWebServiceRequest, RequestMeta> contextStore;
|
||||
|
||||
public AwsSdkClientTracer(final ContextStore<AmazonWebServiceRequest, RequestMeta> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
}
|
||||
public AwsSdkClientTracer() {}
|
||||
|
||||
@Override
|
||||
public String spanNameForRequest(final Request<?> request) {
|
||||
|
@ -50,10 +53,8 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Response<?>
|
|||
return remapServiceName(awsServiceName) + "." + remapOperationName(awsOperation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span onRequest(final Span span, final Request<?> request) {
|
||||
// Call super first because we override the span name below.
|
||||
super.onRequest(span, request);
|
||||
public Span startSpan(Request<?> request, RequestMeta requestMeta) {
|
||||
Span span = super.startSpan(request);
|
||||
|
||||
String awsServiceName = request.getServiceName();
|
||||
AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
|
||||
|
@ -64,20 +65,27 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Response<?>
|
|||
span.setAttribute("aws.operation", awsOperation.getSimpleName());
|
||||
span.setAttribute("aws.endpoint", request.getEndpoint().toString());
|
||||
|
||||
if (contextStore != null) {
|
||||
RequestMeta requestMeta = contextStore.get(originalRequest);
|
||||
if (requestMeta != null) {
|
||||
span.setAttribute("aws.bucket.name", requestMeta.getBucketName());
|
||||
span.setAttribute("aws.queue.url", requestMeta.getQueueUrl());
|
||||
span.setAttribute("aws.queue.name", requestMeta.getQueueName());
|
||||
span.setAttribute("aws.stream.name", requestMeta.getStreamName());
|
||||
span.setAttribute("aws.table.name", requestMeta.getTableName());
|
||||
}
|
||||
if (requestMeta != null) {
|
||||
span.setAttribute("aws.bucket.name", requestMeta.getBucketName());
|
||||
span.setAttribute("aws.queue.url", requestMeta.getQueueUrl());
|
||||
span.setAttribute("aws.queue.name", requestMeta.getQueueName());
|
||||
span.setAttribute("aws.stream.name", requestMeta.getStreamName());
|
||||
span.setAttribute("aws.table.name", requestMeta.getTableName());
|
||||
}
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override startScope not to inject context into the request since no need to propagate context
|
||||
* to AWS backend services.
|
||||
*/
|
||||
@Override
|
||||
public Scope startScope(Span span, Request<?> request) {
|
||||
Context context = withSpan(span, Context.current());
|
||||
context = context.withValue(CONTEXT_CLIENT_SPAN_KEY, span);
|
||||
return withScopedContext(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span onResponse(final Span span, final Response<?> response) {
|
||||
if (response != null && response.getAwsResponse() instanceof AmazonWebServiceResponse) {
|
||||
|
|
|
@ -1,28 +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.auto.instrumentation.awssdk.v1_11;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.decorator.BaseTracer;
|
||||
|
||||
public class OnErrorTracer extends BaseTracer {
|
||||
public static final OnErrorTracer ERROR_TRACER = new OnErrorTracer();
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.aws-sdk-1.11-error";
|
||||
}
|
||||
}
|
|
@ -16,14 +16,14 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.awssdk.v1_11;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.awssdk.v1_11.AwsSdkClientTracer.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.awssdk.v1_11.RequestMeta.SPAN_SCOPE_PAIR_CONTEXT_KEY;
|
||||
import static io.opentelemetry.context.ContextUtils.withScopedContext;
|
||||
import static io.opentelemetry.instrumentation.api.decorator.ClientDecorator.currentContextWith;
|
||||
|
||||
import com.amazonaws.AmazonWebServiceRequest;
|
||||
import com.amazonaws.Request;
|
||||
import com.amazonaws.Response;
|
||||
import com.amazonaws.handlers.RequestHandler2;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.auto.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.auto.api.SpanWithScope;
|
||||
import io.opentelemetry.trace.Span;
|
||||
|
@ -31,11 +31,11 @@ import io.opentelemetry.trace.Span;
|
|||
/** Tracing Request Handler */
|
||||
public class TracingRequestHandler extends RequestHandler2 {
|
||||
|
||||
private final AwsSdkClientTracer tracer;
|
||||
private final ContextStore<AmazonWebServiceRequest, RequestMeta> contextStore;
|
||||
|
||||
public TracingRequestHandler(
|
||||
final ContextStore<AmazonWebServiceRequest, RequestMeta> contextStore) {
|
||||
tracer = new AwsSdkClientTracer(contextStore);
|
||||
this.contextStore = contextStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,10 +45,11 @@ public class TracingRequestHandler extends RequestHandler2 {
|
|||
|
||||
@Override
|
||||
public void beforeRequest(final Request<?> request) {
|
||||
Span span = tracer.startSpan(request);
|
||||
request.addHandlerContext(
|
||||
SPAN_SCOPE_PAIR_CONTEXT_KEY,
|
||||
new SpanWithScope(span, withScopedContext(currentContextWith(span))));
|
||||
AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
|
||||
RequestMeta requestMeta = contextStore.get(originalRequest);
|
||||
Span span = TRACER.startSpan(request, requestMeta);
|
||||
Scope scope = TRACER.startScope(span, request);
|
||||
request.addHandlerContext(SPAN_SCOPE_PAIR_CONTEXT_KEY, new SpanWithScope(span, scope));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +58,7 @@ public class TracingRequestHandler extends RequestHandler2 {
|
|||
if (scope != null) {
|
||||
request.addHandlerContext(SPAN_SCOPE_PAIR_CONTEXT_KEY, null);
|
||||
scope.closeScope();
|
||||
tracer.end(scope.getSpan(), response);
|
||||
TRACER.end(scope.getSpan(), response);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,7 @@ public class TracingRequestHandler extends RequestHandler2 {
|
|||
if (scope != null) {
|
||||
request.addHandlerContext(SPAN_SCOPE_PAIR_CONTEXT_KEY, null);
|
||||
scope.closeScope();
|
||||
tracer.endExceptionally(scope.getSpan(), response, e);
|
||||
TRACER.endExceptionally(scope.getSpan(), response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,16 +16,15 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.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<MultivaluedMap> {
|
||||
public final class InjectAdapter implements HttpTextFormat.Setter<ClientRequest> {
|
||||
|
||||
public static final InjectAdapter SETTER = new InjectAdapter();
|
||||
|
||||
@Override
|
||||
public void set(final MultivaluedMap headers, final String key, final String value) {
|
||||
// Don't allow duplicates.
|
||||
headers.putSingle(key, value);
|
||||
public void set(ClientRequest clientRequest, String key, String value) {
|
||||
clientRequest.getHeaders().putSingle(key, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,16 +16,11 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.jaxrsclient.v1_1;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v1_1.InjectAdapter.SETTER;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v1_1.JaxRsClientV1Decorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v1_1.JaxRsClientV1Decorator.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v1_1.JaxRsClientV1Tracer.TRACER;
|
||||
import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.extendsClass;
|
||||
import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static io.opentelemetry.context.ContextUtils.withScopedContext;
|
||||
import static io.opentelemetry.instrumentation.api.decorator.HttpServerTracer.CONTEXT_ATTRIBUTE;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
|
@ -35,10 +30,8 @@ import com.google.auto.service.AutoService;
|
|||
import com.sun.jersey.api.client.ClientHandler;
|
||||
import com.sun.jersey.api.client.ClientRequest;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
||||
import io.opentelemetry.instrumentation.auto.api.SpanWithScope;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -67,7 +60,7 @@ public final class JaxRsClientV1Instrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".JaxRsClientV1Decorator", packageName + ".InjectAdapter",
|
||||
packageName + ".JaxRsClientV1Tracer", packageName + ".InjectAdapter",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -83,45 +76,35 @@ public final class JaxRsClientV1Instrumentation extends Instrumenter.Default {
|
|||
public static class HandleAdvice {
|
||||
|
||||
@Advice.OnMethodEnter
|
||||
public static SpanWithScope onEnter(
|
||||
@Advice.Argument(0) final ClientRequest request, @Advice.This final ClientHandler thisObj) {
|
||||
public static void onEnter(
|
||||
@Advice.Argument(0) final ClientRequest request,
|
||||
@Advice.This final ClientHandler thisObj,
|
||||
@Advice.Local("otelSpan") Span span,
|
||||
@Advice.Local("otelScope") Scope scope) {
|
||||
|
||||
// WARNING: this might be a chain...so we only have to trace the first in the chain.
|
||||
boolean isRootClientHandler = null == request.getProperties().get(CONTEXT_ATTRIBUTE);
|
||||
if (isRootClientHandler) {
|
||||
Span span =
|
||||
TRACER
|
||||
.spanBuilder(DECORATE.spanNameForRequest(request))
|
||||
.setSpanKind(CLIENT)
|
||||
.startSpan();
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, request);
|
||||
|
||||
Context context = withSpan(span, Context.current());
|
||||
request.getProperties().put(CONTEXT_ATTRIBUTE, context);
|
||||
|
||||
OpenTelemetry.getPropagators()
|
||||
.getHttpTextFormat()
|
||||
.inject(context, request.getHeaders(), SETTER);
|
||||
return new SpanWithScope(span, withScopedContext(context));
|
||||
span = TRACER.startSpan(request);
|
||||
scope = TRACER.startScope(span, request);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void onExit(
|
||||
@Advice.Enter final SpanWithScope spanWithScope,
|
||||
@Advice.Return final ClientResponse response,
|
||||
@Advice.Thrown final Throwable throwable) {
|
||||
if (spanWithScope == null) {
|
||||
return;
|
||||
@Advice.Thrown final Throwable throwable,
|
||||
@Advice.Local("otelSpan") Span span,
|
||||
@Advice.Local("otelScope") Scope scope) {
|
||||
if (scope != null) {
|
||||
scope.close();
|
||||
}
|
||||
|
||||
if (throwable != null) {
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
} else {
|
||||
TRACER.end(span, response);
|
||||
}
|
||||
Span span = spanWithScope.getSpan();
|
||||
DECORATE.onResponse(span, response);
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
spanWithScope.closeScope();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,18 +16,16 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.jaxrsclient.v1_1;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v1_1.InjectAdapter.SETTER;
|
||||
|
||||
import com.sun.jersey.api.client.ClientRequest;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer;
|
||||
import java.net.URI;
|
||||
|
||||
public class JaxRsClientV1Decorator extends HttpClientDecorator<ClientRequest, ClientResponse> {
|
||||
public static final JaxRsClientV1Decorator DECORATE = new JaxRsClientV1Decorator();
|
||||
|
||||
public static final Tracer TRACER =
|
||||
OpenTelemetry.getTracerProvider().get("io.opentelemetry.auto.jaxrs-client-1.1");
|
||||
public class JaxRsClientV1Tracer extends HttpClientTracer<ClientRequest, ClientResponse> {
|
||||
public static final JaxRsClientV1Tracer TRACER = new JaxRsClientV1Tracer();
|
||||
|
||||
@Override
|
||||
protected String method(final ClientRequest httpRequest) {
|
||||
|
@ -54,4 +52,14 @@ public class JaxRsClientV1Decorator extends HttpClientDecorator<ClientRequest, C
|
|||
protected String responseHeader(ClientResponse clientResponse, String name) {
|
||||
return clientResponse.getHeaders().getFirst(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<ClientRequest> getSetter() {
|
||||
return SETTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.jaxrs-client-1.1";
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.JaxRsClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.JaxRsClientTracer.TRACER;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
@ -56,7 +56,7 @@ public final class JerseyClientConnectionErrorInstrumentation extends Instrument
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
getClass().getName() + "$WrappedFuture", JaxRsClientDecorator.class.getName(),
|
||||
getClass().getName() + "$WrappedFuture", JaxRsClientTracer.class.getName(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -84,9 +84,7 @@ public final class JerseyClientConnectionErrorInstrumentation extends Instrument
|
|||
if (throwable != null) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
|
||||
if (prop instanceof Span) {
|
||||
Span span = (Span) prop;
|
||||
DECORATE.onError(span, throwable);
|
||||
span.end();
|
||||
TRACER.endExceptionally((Span) prop, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,9 +134,7 @@ public final class JerseyClientConnectionErrorInstrumentation extends Instrument
|
|||
} catch (final ExecutionException e) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
|
||||
if (prop instanceof Span) {
|
||||
Span span = (Span) prop;
|
||||
DECORATE.onError(span, e.getCause());
|
||||
span.end();
|
||||
TRACER.endExceptionally((Span) prop, e.getCause());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
@ -152,9 +148,7 @@ public final class JerseyClientConnectionErrorInstrumentation extends Instrument
|
|||
} catch (final ExecutionException e) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
|
||||
if (prop instanceof Span) {
|
||||
Span span = (Span) prop;
|
||||
DECORATE.onError(span, e.getCause());
|
||||
span.end();
|
||||
TRACER.endExceptionally((Span) prop, e.getCause());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.JaxRsClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.JaxRsClientTracer.TRACER;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
@ -56,7 +56,7 @@ public final class ResteasyClientConnectionErrorInstrumentation extends Instrume
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
getClass().getName() + "$WrappedFuture", JaxRsClientDecorator.class.getName(),
|
||||
getClass().getName() + "$WrappedFuture", JaxRsClientTracer.class.getName(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -84,9 +84,7 @@ public final class ResteasyClientConnectionErrorInstrumentation extends Instrume
|
|||
if (throwable != null) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
|
||||
if (prop instanceof Span) {
|
||||
Span span = (Span) prop;
|
||||
DECORATE.onError(span, throwable);
|
||||
span.end();
|
||||
TRACER.endExceptionally((Span) prop, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,9 +134,7 @@ public final class ResteasyClientConnectionErrorInstrumentation extends Instrume
|
|||
} catch (final ExecutionException e) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
|
||||
if (prop instanceof Span) {
|
||||
Span span = (Span) prop;
|
||||
DECORATE.onError(span, e.getCause());
|
||||
span.end();
|
||||
TRACER.endExceptionally((Span) prop, e.getCause());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
@ -152,9 +148,7 @@ public final class ResteasyClientConnectionErrorInstrumentation extends Instrume
|
|||
} catch (final ExecutionException e) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
|
||||
if (prop instanceof Span) {
|
||||
Span span = (Span) prop;
|
||||
DECORATE.onError(span, e.getCause());
|
||||
span.end();
|
||||
TRACER.endExceptionally((Span) prop, e.getCause());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
package io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.InjectAdapter.SETTER;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.JaxRsClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.JaxRsClientDecorator.TRACER;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
import static io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0.JaxRsClientTracer.TRACER;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
|
||||
import io.grpc.Context;
|
||||
|
@ -38,14 +36,7 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
|
|||
|
||||
@Override
|
||||
public void filter(final ClientRequestContext requestContext) {
|
||||
Span span =
|
||||
TRACER
|
||||
.spanBuilder(DECORATE.spanNameForRequest(requestContext))
|
||||
.setSpanKind(CLIENT)
|
||||
.startSpan();
|
||||
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, requestContext);
|
||||
Span span = TRACER.startSpan(requestContext);
|
||||
|
||||
Context context = withSpan(span, Context.current());
|
||||
OpenTelemetry.getPropagators()
|
||||
|
@ -61,9 +52,7 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
|
|||
Object spanObj = requestContext.getProperty(SPAN_PROPERTY_NAME);
|
||||
if (spanObj instanceof Span) {
|
||||
Span span = (Span) spanObj;
|
||||
DECORATE.onResponse(span, responseContext);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.end(span, responseContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public final class JaxRsClientInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".JaxRsClientDecorator",
|
||||
packageName + ".JaxRsClientTracer",
|
||||
packageName + ".ClientTracingFeature",
|
||||
packageName + ".ClientTracingFilter",
|
||||
packageName + ".InjectAdapter",
|
||||
|
|
|
@ -16,19 +16,15 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.jaxrsclient.v2_0;
|
||||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
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;
|
||||
|
||||
public class JaxRsClientDecorator
|
||||
extends HttpClientDecorator<ClientRequestContext, ClientResponseContext> {
|
||||
public static final JaxRsClientDecorator DECORATE = new JaxRsClientDecorator();
|
||||
|
||||
public static final Tracer TRACER =
|
||||
OpenTelemetry.getTracerProvider().get("io.opentelemetry.auto.jaxrs-client-2.0");
|
||||
public class JaxRsClientTracer
|
||||
extends HttpClientTracer<ClientRequestContext, ClientResponseContext> {
|
||||
public static final JaxRsClientTracer TRACER = new JaxRsClientTracer();
|
||||
|
||||
@Override
|
||||
protected String method(final ClientRequestContext httpRequest) {
|
||||
|
@ -54,4 +50,14 @@ public class JaxRsClientDecorator
|
|||
protected String responseHeader(ClientResponseContext clientResponseContext, String name) {
|
||||
return clientResponseContext.getHeaderString(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<ClientRequestContext> getSetter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.jaxrs-client-2.0";
|
||||
}
|
||||
}
|
|
@ -54,7 +54,7 @@ public class KubernetesClientInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".KubernetesClientDecorator",
|
||||
packageName + ".KubernetesClientTracer",
|
||||
packageName + ".TracingInterceptor",
|
||||
packageName + ".KubernetesRequestDigest",
|
||||
packageName + ".KubernetesResource",
|
||||
|
|
|
@ -16,18 +16,17 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.kubernetesclient;
|
||||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import java.net.URI;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class KubernetesClientDecorator extends HttpClientDecorator<Request, Response> {
|
||||
public static final KubernetesClientDecorator DECORATE = new KubernetesClientDecorator();
|
||||
|
||||
public static final Tracer TRACER =
|
||||
OpenTelemetry.getTracerProvider().get("io.opentelemetry.auto.kubernetes-client-7.0");
|
||||
public class KubernetesClientTracer extends HttpClientTracer<Request, Response> {
|
||||
public static final KubernetesClientTracer TRACER = new KubernetesClientTracer();
|
||||
|
||||
@Override
|
||||
protected String method(final Request httpRequest) {
|
||||
|
@ -53,4 +52,33 @@ public class KubernetesClientDecorator extends HttpClientDecorator<Request, Resp
|
|||
protected String responseHeader(Response response, String name) {
|
||||
return response.header(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<Request> getSetter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.kubernetes-client-7.0";
|
||||
}
|
||||
|
||||
/** This method is overridden to allow other classes in this package to call it. */
|
||||
@Override
|
||||
protected Span onRequest(Span span, Request request) {
|
||||
return super.onRequest(span, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to generate an acceptable CLIENT span (operation) name based on a given
|
||||
* KubernetesRequestDigest.
|
||||
*/
|
||||
public Span startSpan(KubernetesRequestDigest digest) {
|
||||
return tracer
|
||||
.spanBuilder(digest.toString())
|
||||
.setSpanKind(CLIENT)
|
||||
.setAttribute("namespace", digest.getResourceMeta().getNamespace())
|
||||
.setAttribute("name", digest.getResourceMeta().getName())
|
||||
.startSpan();
|
||||
}
|
||||
}
|
|
@ -16,10 +16,8 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.kubernetesclient;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.kubernetesclient.KubernetesClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.kubernetesclient.KubernetesClientDecorator.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.kubernetesclient.KubernetesClientTracer.TRACER;
|
||||
import static io.opentelemetry.context.ContextUtils.withScopedContext;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
|
||||
import io.grpc.Context;
|
||||
|
@ -36,16 +34,8 @@ public class TracingInterceptor implements Interceptor {
|
|||
|
||||
KubernetesRequestDigest digest = KubernetesRequestDigest.parse(chain.request());
|
||||
|
||||
Span span =
|
||||
TRACER
|
||||
.spanBuilder(digest.toString())
|
||||
.setSpanKind(CLIENT)
|
||||
.setAttribute("namespace", digest.getResourceMeta().getNamespace())
|
||||
.setAttribute("name", digest.getResourceMeta().getName())
|
||||
.startSpan();
|
||||
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, chain.request());
|
||||
Span span = TRACER.startSpan(digest);
|
||||
TRACER.onRequest(span, chain.request());
|
||||
|
||||
Context context = withSpan(span, Context.current());
|
||||
|
||||
|
@ -53,15 +43,11 @@ public class TracingInterceptor implements Interceptor {
|
|||
try (Scope scope = withScopedContext(context)) {
|
||||
response = chain.proceed(chain.request());
|
||||
} catch (final Exception e) {
|
||||
DECORATE.onError(span, e);
|
||||
span.end();
|
||||
TRACER.endExceptionally(span, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
DECORATE.onResponse(span, response);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
|
||||
TRACER.end(span, response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.playws.v1_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientTracer.TRACER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.context.ContextUtils;
|
||||
|
@ -64,11 +64,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
|
|||
@Override
|
||||
public Object onCompleted() throws Exception {
|
||||
Response response = builder.build();
|
||||
if (response != null) {
|
||||
DECORATE.onResponse(span, response);
|
||||
}
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.end(span, response);
|
||||
|
||||
try (Scope scope = ContextUtils.withScopedContext(invocationContext)) {
|
||||
return delegate.onCompleted();
|
||||
|
@ -77,8 +73,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
|
|||
|
||||
@Override
|
||||
public void onThrowable(final Throwable throwable) {
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
span.end();
|
||||
|
||||
try (Scope scope = ContextUtils.withScopedContext(invocationContext)) {
|
||||
|
|
|
@ -16,18 +16,13 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.playws.v1_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.playws.HeadersInjectAdapter.SETTER;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.TRACER;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.getSpan;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientTracer.TRACER;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.auto.instrumentation.playws.BasePlayWSClientInstrumentation;
|
||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import play.shaded.ahc.org.asynchttpclient.AsyncHandler;
|
||||
|
@ -39,24 +34,15 @@ import play.shaded.ahc.org.asynchttpclient.ws.WebSocketUpgradeHandler;
|
|||
public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation {
|
||||
public static class ClientAdvice {
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Span methodEnter(
|
||||
public static void methodEnter(
|
||||
@Advice.Argument(0) final Request request,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler) {
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler,
|
||||
@Advice.Local("otelSpan") Span span,
|
||||
@Advice.Local("otelScope") Scope scope) {
|
||||
Context parentContext = Context.current();
|
||||
|
||||
Span span =
|
||||
TRACER
|
||||
.spanBuilder(DECORATE.spanNameForRequest(request))
|
||||
.setSpanKind(CLIENT)
|
||||
.setParent(getSpan(parentContext))
|
||||
.startSpan();
|
||||
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, request);
|
||||
|
||||
OpenTelemetry.getPropagators()
|
||||
.getHttpTextFormat()
|
||||
.inject(withSpan(span, parentContext), request, SETTER);
|
||||
span = TRACER.startSpan(request);
|
||||
scope = TRACER.startScope(span, request);
|
||||
|
||||
if (asyncHandler instanceof StreamedAsyncHandler) {
|
||||
asyncHandler =
|
||||
|
@ -66,18 +52,17 @@ public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation
|
|||
// websocket upgrade handlers aren't supported
|
||||
asyncHandler = new AsyncHandlerWrapper(asyncHandler, span, parentContext);
|
||||
}
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void methodExit(
|
||||
@Advice.Enter final Span clientSpan, @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) {
|
||||
DECORATE.onError(clientSpan, throwable);
|
||||
DECORATE.beforeFinish(clientSpan);
|
||||
clientSpan.end();
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.playws.v2_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientTracer.TRACER;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.currentContextWith;
|
||||
|
||||
import io.opentelemetry.context.Scope;
|
||||
|
@ -67,11 +66,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
|
|||
@Override
|
||||
public Object onCompleted() throws Exception {
|
||||
Response response = builder.build();
|
||||
if (response != null) {
|
||||
DECORATE.onResponse(span, response);
|
||||
}
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.end(span, response);
|
||||
|
||||
if (parentSpan.getContext().isValid()) {
|
||||
try (Scope scope = currentContextWith(parentSpan)) {
|
||||
|
@ -84,9 +79,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
|
|||
|
||||
@Override
|
||||
public void onThrowable(final Throwable throwable) {
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
|
||||
if (parentSpan.getContext().isValid()) {
|
||||
try (Scope scope = currentContextWith(parentSpan)) {
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
package io.opentelemetry.auto.instrumentation.playws.v2_0;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.playws.HeadersInjectAdapter.SETTER;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.TRACER;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientTracer.TRACER;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
|
@ -38,16 +36,12 @@ import play.shaded.ahc.org.asynchttpclient.ws.WebSocketUpgradeHandler;
|
|||
public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation {
|
||||
public static class ClientAdvice {
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Span methodEnter(
|
||||
public static void methodEnter(
|
||||
@Advice.Argument(0) final Request request,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler) {
|
||||
|
||||
Span span =
|
||||
TRACER.spanBuilder(DECORATE.spanNameForRequest(request)).setSpanKind(CLIENT).startSpan();
|
||||
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, request);
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler,
|
||||
@Advice.Local("otelSpan") Span span) {
|
||||
|
||||
span = TRACER.startSpan(request);
|
||||
Context context = withSpan(span, Context.current());
|
||||
OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, SETTER);
|
||||
|
||||
|
@ -57,18 +51,14 @@ public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation
|
|||
// websocket upgrade handlers aren't supported
|
||||
asyncHandler = new AsyncHandlerWrapper(asyncHandler, span);
|
||||
}
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void methodExit(
|
||||
@Advice.Enter final Span clientSpan, @Advice.Thrown final Throwable throwable) {
|
||||
@Advice.Thrown final Throwable throwable, @Advice.Local("otelSpan") Span span) {
|
||||
|
||||
if (throwable != null) {
|
||||
DECORATE.onError(clientSpan, throwable);
|
||||
DECORATE.beforeFinish(clientSpan);
|
||||
clientSpan.end();
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.playws.v2_1;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientTracer.TRACER;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.currentContextWith;
|
||||
|
||||
import io.opentelemetry.context.Scope;
|
||||
|
@ -68,11 +67,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
|
|||
@Override
|
||||
public Object onCompleted() throws Exception {
|
||||
Response response = builder.build();
|
||||
if (response != null) {
|
||||
DECORATE.onResponse(span, response);
|
||||
}
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.end(span, response);
|
||||
|
||||
if (parentSpan.getContext().isValid()) {
|
||||
try (Scope scope = currentContextWith(parentSpan)) {
|
||||
|
@ -85,9 +80,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
|
|||
|
||||
@Override
|
||||
public void onThrowable(final Throwable throwable) {
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.end();
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
|
||||
if (parentSpan.getContext().isValid()) {
|
||||
try (Scope scope = currentContextWith(parentSpan)) {
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
package io.opentelemetry.auto.instrumentation.playws.v2_1;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.playws.HeadersInjectAdapter.SETTER;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator.TRACER;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.PlayWSClientTracer.TRACER;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
|
@ -38,16 +36,12 @@ import play.shaded.ahc.org.asynchttpclient.ws.WebSocketUpgradeHandler;
|
|||
public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation {
|
||||
public static class ClientAdvice {
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Span methodEnter(
|
||||
public static void methodEnter(
|
||||
@Advice.Argument(0) final Request request,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler) {
|
||||
|
||||
Span span =
|
||||
TRACER.spanBuilder(DECORATE.spanNameForRequest(request)).setSpanKind(CLIENT).startSpan();
|
||||
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, request);
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler,
|
||||
@Advice.Local("otelSpan") Span span) {
|
||||
|
||||
span = TRACER.startSpan(request);
|
||||
Context context = withSpan(span, Context.current());
|
||||
OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, SETTER);
|
||||
|
||||
|
@ -57,18 +51,14 @@ public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation
|
|||
// websocket upgrade handlers aren't supported
|
||||
asyncHandler = new AsyncHandlerWrapper(asyncHandler, span);
|
||||
}
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void methodExit(
|
||||
@Advice.Enter final Span clientSpan, @Advice.Thrown final Throwable throwable) {
|
||||
@Advice.Thrown final Throwable throwable, @Advice.Local("otelSpan") Span span) {
|
||||
|
||||
if (throwable != null) {
|
||||
DECORATE.onError(clientSpan, throwable);
|
||||
DECORATE.beforeFinish(clientSpan);
|
||||
clientSpan.end();
|
||||
TRACER.endExceptionally(span, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public abstract class BasePlayWSClientInstrumentation extends Instrumenter.Defau
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.auto.instrumentation.playws.PlayWSClientDecorator",
|
||||
"io.opentelemetry.auto.instrumentation.playws.PlayWSClientTracer",
|
||||
"io.opentelemetry.auto.instrumentation.playws.HeadersInjectAdapter",
|
||||
packageName + ".AsyncHandlerWrapper",
|
||||
packageName + ".StreamedAsyncHandlerWrapper"
|
||||
|
|
|
@ -16,19 +16,17 @@
|
|||
|
||||
package io.opentelemetry.auto.instrumentation.playws;
|
||||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import static io.opentelemetry.auto.instrumentation.playws.HeadersInjectAdapter.SETTER;
|
||||
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientTracer;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import play.shaded.ahc.org.asynchttpclient.Request;
|
||||
import play.shaded.ahc.org.asynchttpclient.Response;
|
||||
|
||||
public class PlayWSClientDecorator extends HttpClientDecorator<Request, Response> {
|
||||
public static final PlayWSClientDecorator DECORATE = new PlayWSClientDecorator();
|
||||
|
||||
public static final Tracer TRACER =
|
||||
OpenTelemetry.getTracerProvider().get("io.opentelemetry.auto.play-ws-2.1");
|
||||
public class PlayWSClientTracer extends HttpClientTracer<Request, Response> {
|
||||
public static final PlayWSClientTracer TRACER = new PlayWSClientTracer();
|
||||
|
||||
@Override
|
||||
protected String method(final Request request) {
|
||||
|
@ -54,4 +52,14 @@ public class PlayWSClientDecorator extends HttpClientDecorator<Request, Response
|
|||
protected String responseHeader(Response response, String name) {
|
||||
return response.getHeaders().get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Setter<Request> getSetter() {
|
||||
return SETTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstrumentationName() {
|
||||
return "io.opentelemetry.auto.play-ws-2.1";
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public class WebClientFilterInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientDecorator",
|
||||
"io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientTracer",
|
||||
"io.opentelemetry.instrumentation.spring.webflux.client.HttpHeadersInjectAdapter",
|
||||
"io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter"
|
||||
};
|
||||
|
|
|
@ -75,12 +75,14 @@ public abstract class HttpClientTracer<REQUEST, RESPONSE> extends BaseTracer {
|
|||
|
||||
public Scope startScope(Span span, REQUEST request) {
|
||||
Context context = withSpan(span, Context.current());
|
||||
|
||||
Setter<REQUEST> 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);
|
||||
context = context.withValue(CONTEXT_CLIENT_SPAN_KEY, span);
|
||||
return withScopedContext(context);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue