Merge pull request #728 from DataDog/tyler/static-import-decorators
Rename and static import decorators instance
This commit is contained in:
commit
2f3f2d4e04
|
@ -23,6 +23,11 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
|||
return DDSpanTypes.HTTP_CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String service() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Span onRequest(final Span span, final REQUEST request) {
|
||||
assert span != null;
|
||||
if (request != null) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import akka.http.scaladsl.model.HttpResponse;
|
|||
import datadog.trace.agent.decorator.HttpClientDecorator;
|
||||
|
||||
public class AkkaHttpClientDecorator extends HttpClientDecorator<HttpRequest, HttpResponse> {
|
||||
public static final AkkaHttpClientDecorator INSTANCE = new AkkaHttpClientDecorator();
|
||||
public static final AkkaHttpClientDecorator DECORATE = new AkkaHttpClientDecorator();
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
|
@ -17,11 +17,6 @@ public class AkkaHttpClientDecorator extends HttpClientDecorator<HttpRequest, Ht
|
|||
return "akka-http-client";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String service() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String method(final HttpRequest httpRequest) {
|
||||
return httpRequest.method().value();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package datadog.trace.instrumentation.akkahttp;
|
||||
|
||||
import static datadog.trace.instrumentation.akkahttp.AkkaHttpClientDecorator.DECORATE;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
@ -98,8 +99,8 @@ public final class AkkaHttpClientInstrumentation extends Instrumenter.Default {
|
|||
}
|
||||
|
||||
final Scope scope = GlobalTracer.get().buildSpan("akka-http.request").startActive(false);
|
||||
AkkaHttpClientDecorator.INSTANCE.afterStart(scope.span());
|
||||
AkkaHttpClientDecorator.INSTANCE.onRequest(scope.span(), request);
|
||||
DECORATE.afterStart(scope.span());
|
||||
DECORATE.onRequest(scope.span(), request);
|
||||
|
||||
if (request != null) {
|
||||
final AkkaHttpHeaders headers = new AkkaHttpHeaders(request);
|
||||
|
@ -128,8 +129,8 @@ public final class AkkaHttpClientInstrumentation extends Instrumenter.Default {
|
|||
if (throwable == null) {
|
||||
responseFuture.onComplete(new OnCompleteHandler(span), thiz.system().dispatcher());
|
||||
} else {
|
||||
AkkaHttpClientDecorator.INSTANCE.onError(span, throwable);
|
||||
AkkaHttpClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
scope.close();
|
||||
|
@ -174,11 +175,11 @@ public final class AkkaHttpClientInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public Void apply(final Try<HttpResponse> result) {
|
||||
if (result.isSuccess()) {
|
||||
AkkaHttpClientDecorator.INSTANCE.onResponse(span, result.get());
|
||||
DECORATE.onResponse(span, result.get());
|
||||
} else {
|
||||
AkkaHttpClientDecorator.INSTANCE.onError(span, result.failed().get());
|
||||
DECORATE.onError(span, result.failed().get());
|
||||
}
|
||||
AkkaHttpClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package datadog.trace.instrumentation.akkahttp
|
|||
import akka.NotUsed
|
||||
import akka.http.scaladsl.model.{HttpRequest, HttpResponse}
|
||||
import akka.stream.scaladsl.Flow
|
||||
import datadog.trace.instrumentation.akkahttp.AkkaHttpClientDecorator.DECORATE
|
||||
import io.opentracing.Span
|
||||
import io.opentracing.propagation.Format
|
||||
import io.opentracing.util.GlobalTracer
|
||||
|
@ -16,17 +17,17 @@ object AkkaHttpClientTransformFlow {
|
|||
Flow.fromFunction((input: (HttpRequest, T)) => {
|
||||
val (request, data) = input
|
||||
span = GlobalTracer.get.buildSpan("akka-http.request").start()
|
||||
AkkaHttpClientDecorator.INSTANCE.afterStart(span)
|
||||
AkkaHttpClientDecorator.INSTANCE.onRequest(span, request)
|
||||
DECORATE.afterStart(span)
|
||||
DECORATE.onRequest(span, request)
|
||||
val headers = new AkkaHttpClientInstrumentation.AkkaHttpHeaders(request)
|
||||
GlobalTracer.get.inject(span.context, Format.Builtin.HTTP_HEADERS, headers)
|
||||
(headers.getRequest, data)
|
||||
}).via(flow).map(output => {
|
||||
output._1 match {
|
||||
case Success(response) => AkkaHttpClientDecorator.INSTANCE.onResponse(span, response)
|
||||
case Failure(e) => AkkaHttpClientDecorator.INSTANCE.onError(span, e)
|
||||
case Success(response) => DECORATE.onResponse(span, response)
|
||||
case Failure(e) => DECORATE.onError(span, e)
|
||||
}
|
||||
AkkaHttpClientDecorator.INSTANCE.beforeFinish(span)
|
||||
DECORATE.beforeFinish(span)
|
||||
span.finish()
|
||||
output
|
||||
})
|
||||
|
|
|
@ -5,7 +5,7 @@ import akka.http.scaladsl.model.HttpResponse;
|
|||
import datadog.trace.agent.decorator.HttpServerDecorator;
|
||||
|
||||
public class AkkaHttpServerDecorator extends HttpServerDecorator<HttpRequest, HttpResponse> {
|
||||
public static final AkkaHttpServerDecorator INSTANCE = new AkkaHttpServerDecorator();
|
||||
public static final AkkaHttpServerDecorator DECORATE = new AkkaHttpServerDecorator();
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package datadog.trace.instrumentation.akkahttp;
|
||||
|
||||
import static datadog.trace.instrumentation.akkahttp.AkkaHttpServerDecorator.DECORATE;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
|
@ -106,8 +107,8 @@ public final class AkkaHttpServerInstrumentation extends Instrumenter.Default {
|
|||
.asChildOf(extractedContext)
|
||||
.startActive(false);
|
||||
|
||||
AkkaHttpServerDecorator.INSTANCE.afterStart(scope.span());
|
||||
AkkaHttpServerDecorator.INSTANCE.onRequest(scope.span(), request);
|
||||
DECORATE.afterStart(scope.span());
|
||||
DECORATE.onRequest(scope.span(), request);
|
||||
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(true);
|
||||
|
@ -116,8 +117,8 @@ public final class AkkaHttpServerInstrumentation extends Instrumenter.Default {
|
|||
}
|
||||
|
||||
public static void finishSpan(final Span span, final HttpResponse response) {
|
||||
AkkaHttpServerDecorator.INSTANCE.onResponse(span, response);
|
||||
AkkaHttpServerDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onResponse(span, response);
|
||||
DECORATE.beforeFinish(span);
|
||||
|
||||
if (GlobalTracer.get().scopeManager().active() instanceof TraceScope) {
|
||||
((TraceScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(false);
|
||||
|
@ -126,9 +127,9 @@ public final class AkkaHttpServerInstrumentation extends Instrumenter.Default {
|
|||
}
|
||||
|
||||
public static void finishSpan(final Span span, final Throwable t) {
|
||||
AkkaHttpServerDecorator.INSTANCE.onError(span, t);
|
||||
DECORATE.onError(span, t);
|
||||
Tags.HTTP_STATUS.set(span, 500);
|
||||
AkkaHttpServerDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.beforeFinish(span);
|
||||
|
||||
if (GlobalTracer.get().scopeManager().active() instanceof TraceScope) {
|
||||
((TraceScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(false);
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.apache.http.HttpResponse;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
||||
public class ApacheHttpClientDecorator extends HttpClientDecorator<HttpUriRequest, HttpResponse> {
|
||||
public static final ApacheHttpClientDecorator INSTANCE = new ApacheHttpClientDecorator();
|
||||
public static final ApacheHttpClientDecorator DECORATE = new ApacheHttpClientDecorator();
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
|
@ -18,11 +18,6 @@ public class ApacheHttpClientDecorator extends HttpClientDecorator<HttpUriReques
|
|||
return "apache-httpclient";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String service() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String method(final HttpUriRequest httpRequest) {
|
||||
return httpRequest.getRequestLine().getMethod();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package datadog.trace.instrumentation.apachehttpclient;
|
||||
|
||||
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
|
||||
import static datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientDecorator.DECORATE;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
|
@ -92,8 +93,8 @@ public class ApacheHttpClientInstrumentation extends Instrumenter.Default {
|
|||
final Scope scope = tracer.buildSpan("http.request").startActive(true);
|
||||
final Span span = scope.span();
|
||||
|
||||
ApacheHttpClientDecorator.INSTANCE.afterStart(span);
|
||||
ApacheHttpClientDecorator.INSTANCE.onRequest(span, request);
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onRequest(span, request);
|
||||
|
||||
// Wrap the handler so we capture the status code
|
||||
if (handler1 instanceof ResponseHandler) {
|
||||
|
@ -121,11 +122,11 @@ public class ApacheHttpClientInstrumentation extends Instrumenter.Default {
|
|||
final Span span = scope.span();
|
||||
|
||||
if (result instanceof HttpResponse) {
|
||||
ApacheHttpClientDecorator.INSTANCE.onResponse(span, (HttpResponse) result);
|
||||
DECORATE.onResponse(span, (HttpResponse) result);
|
||||
} // else they probably provided a ResponseHandler.
|
||||
|
||||
ApacheHttpClientDecorator.INSTANCE.onError(span, throwable);
|
||||
ApacheHttpClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
} finally {
|
||||
scope.close();
|
||||
CallDepthThreadLocalMap.reset(HttpClient.class);
|
||||
|
@ -147,7 +148,7 @@ public class ApacheHttpClientInstrumentation extends Instrumenter.Default {
|
|||
public Object handleResponse(final HttpResponse response)
|
||||
throws ClientProtocolException, IOException {
|
||||
if (null != span) {
|
||||
ApacheHttpClientDecorator.INSTANCE.onResponse(span, response);
|
||||
DECORATE.onResponse(span, response);
|
||||
}
|
||||
return handler.handleResponse(response);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class AwsSdkClientDecorator extends HttpClientDecorator<Request, Response> {
|
||||
public static final AwsSdkClientDecorator INSTANCE = new AwsSdkClientDecorator();
|
||||
public static final AwsSdkClientDecorator DECORATE = new AwsSdkClientDecorator();
|
||||
|
||||
static final String COMPONENT_NAME = "java-aws-sdk";
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package datadog.trace.instrumentation.aws.v0;
|
||||
|
||||
import static datadog.trace.instrumentation.aws.v0.AwsSdkClientDecorator.DECORATE;
|
||||
|
||||
import com.amazonaws.AmazonWebServiceRequest;
|
||||
import com.amazonaws.Request;
|
||||
import com.amazonaws.Response;
|
||||
|
@ -24,12 +26,11 @@ public class TracingRequestHandler extends RequestHandler2 {
|
|||
return request;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void beforeRequest(final Request<?> request) {
|
||||
final Scope scope = GlobalTracer.get().buildSpan("aws.command").startActive(true);
|
||||
AwsSdkClientDecorator.INSTANCE.afterStart(scope.span());
|
||||
AwsSdkClientDecorator.INSTANCE.onRequest(scope.span(), request);
|
||||
DECORATE.afterStart(scope.span());
|
||||
DECORATE.onRequest(scope.span(), request);
|
||||
|
||||
// We inject headers at aws-client level because aws requests may be signed and adding headers
|
||||
// on http-client level may break signature.
|
||||
|
@ -42,21 +43,19 @@ public class TracingRequestHandler extends RequestHandler2 {
|
|||
request.addHandlerContext(SCOPE_CONTEXT_KEY, scope);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void afterResponse(final Request<?> request, final Response<?> response) {
|
||||
final Scope scope = request.getHandlerContext(SCOPE_CONTEXT_KEY);
|
||||
AwsSdkClientDecorator.INSTANCE.onResponse(scope.span(), response);
|
||||
AwsSdkClientDecorator.INSTANCE.beforeFinish(scope.span());
|
||||
DECORATE.onResponse(scope.span(), response);
|
||||
DECORATE.beforeFinish(scope.span());
|
||||
scope.close();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void afterError(final Request<?> request, final Response<?> response, final Exception e) {
|
||||
final Scope scope = request.getHandlerContext(SCOPE_CONTEXT_KEY);
|
||||
AwsSdkClientDecorator.INSTANCE.onError(scope.span(), e);
|
||||
AwsSdkClientDecorator.INSTANCE.beforeFinish(scope.span());
|
||||
DECORATE.onError(scope.span(), e);
|
||||
DECORATE.beforeFinish(scope.span());
|
||||
scope.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import software.amazon.awssdk.http.SdkHttpRequest;
|
|||
import software.amazon.awssdk.http.SdkHttpResponse;
|
||||
|
||||
public class AwsSdkClientDecorator extends HttpClientDecorator<SdkHttpRequest, SdkHttpResponse> {
|
||||
public static final AwsSdkClientDecorator INSTANCE = new AwsSdkClientDecorator();
|
||||
public static final AwsSdkClientDecorator DECORATE = new AwsSdkClientDecorator();
|
||||
|
||||
static final String COMPONENT_NAME = "java-aws-sdk";
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package datadog.trace.instrumentation.aws.v2;
|
||||
|
||||
import static datadog.trace.instrumentation.aws.v2.AwsSdkClientDecorator.DECORATE;
|
||||
|
||||
import datadog.trace.context.TraceScope;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
|
@ -33,7 +35,7 @@ public class TracingExecutionInterceptor implements ExecutionInterceptor {
|
|||
public void beforeExecution(
|
||||
final Context.BeforeExecution context, final ExecutionAttributes executionAttributes) {
|
||||
final Span span = GlobalTracer.get().buildSpan("aws.command").start();
|
||||
AwsSdkClientDecorator.INSTANCE.afterStart(span);
|
||||
DECORATE.afterStart(span);
|
||||
executionAttributes.putAttribute(SPAN_ATTRIBUTE, span);
|
||||
}
|
||||
|
||||
|
@ -43,8 +45,8 @@ public class TracingExecutionInterceptor implements ExecutionInterceptor {
|
|||
final Span span = executionAttributes.getAttribute(SPAN_ATTRIBUTE);
|
||||
final SdkHttpRequest httpRequest = context.httpRequest();
|
||||
|
||||
AwsSdkClientDecorator.INSTANCE.onRequest(span, httpRequest);
|
||||
AwsSdkClientDecorator.INSTANCE.onAttributes(span, executionAttributes);
|
||||
DECORATE.onRequest(span, httpRequest);
|
||||
DECORATE.onAttributes(span, executionAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,9 +75,9 @@ public class TracingExecutionInterceptor implements ExecutionInterceptor {
|
|||
final Context.AfterExecution context, final ExecutionAttributes executionAttributes) {
|
||||
final Span span = executionAttributes.getAttribute(SPAN_ATTRIBUTE);
|
||||
// Call onResponse on both types of responses:
|
||||
AwsSdkClientDecorator.INSTANCE.onResponse(span, context.response());
|
||||
AwsSdkClientDecorator.INSTANCE.onResponse(span, context.httpResponse());
|
||||
AwsSdkClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onResponse(span, context.response());
|
||||
DECORATE.onResponse(span, context.httpResponse());
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
|
||||
|
@ -83,7 +85,7 @@ public class TracingExecutionInterceptor implements ExecutionInterceptor {
|
|||
public void onExecutionFailure(
|
||||
final Context.FailedExecution context, final ExecutionAttributes executionAttributes) {
|
||||
final Span span = executionAttributes.getAttribute(SPAN_ATTRIBUTE);
|
||||
AwsSdkClientDecorator.INSTANCE.onError(span, context.exception());
|
||||
DECORATE.onError(span, context.exception());
|
||||
}
|
||||
|
||||
public static Consumer<ClientOverrideConfiguration.Builder> getOverrideConfigurationConsumer() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package datadog.trace.instrumentation.couchbase.client;
|
||||
|
||||
import static datadog.trace.instrumentation.couchbase.client.CouchbaseClientDecorator.DECORATE;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
|
@ -114,7 +115,7 @@ public class CouchbaseBucketInstrumentation extends Instrumenter.Default {
|
|||
|
||||
// just replace the no-op span.
|
||||
spanRef.set(
|
||||
CouchbaseClientDecorator.INSTANCE.afterStart(
|
||||
DECORATE.afterStart(
|
||||
GlobalTracer.get()
|
||||
.buildSpan("couchbase.call")
|
||||
.withTag(DDTags.RESOURCE_NAME, resourceName)
|
||||
|
@ -135,7 +136,7 @@ public class CouchbaseBucketInstrumentation extends Instrumenter.Default {
|
|||
final Span span = spanRef.getAndSet(null);
|
||||
|
||||
if (span != null) {
|
||||
CouchbaseClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
@ -152,8 +153,8 @@ public class CouchbaseBucketInstrumentation extends Instrumenter.Default {
|
|||
public void call(final Throwable throwable) {
|
||||
final Span span = spanRef.getAndSet(null);
|
||||
if (span != null) {
|
||||
CouchbaseClientDecorator.INSTANCE.onError(span, throwable);
|
||||
CouchbaseClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import datadog.trace.agent.decorator.DatabaseClientDecorator;
|
|||
import datadog.trace.api.DDSpanTypes;
|
||||
|
||||
class CouchbaseClientDecorator extends DatabaseClientDecorator {
|
||||
public static final CouchbaseClientDecorator INSTANCE = new CouchbaseClientDecorator();
|
||||
public static final CouchbaseClientDecorator DECORATE = new CouchbaseClientDecorator();
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package datadog.trace.instrumentation.couchbase.client;
|
||||
|
||||
import static datadog.trace.instrumentation.couchbase.client.CouchbaseClientDecorator.DECORATE;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
|
@ -109,7 +110,7 @@ public class CouchbaseClusterInstrumentation extends Instrumenter.Default {
|
|||
|
||||
// just replace the no-op span.
|
||||
spanRef.set(
|
||||
CouchbaseClientDecorator.INSTANCE.afterStart(
|
||||
DECORATE.afterStart(
|
||||
GlobalTracer.get()
|
||||
.buildSpan("couchbase.call")
|
||||
.withTag(DDTags.RESOURCE_NAME, resourceName)
|
||||
|
@ -129,7 +130,7 @@ public class CouchbaseClusterInstrumentation extends Instrumenter.Default {
|
|||
final Span span = spanRef.getAndSet(null);
|
||||
|
||||
if (span != null) {
|
||||
CouchbaseClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
@ -146,8 +147,8 @@ public class CouchbaseClusterInstrumentation extends Instrumenter.Default {
|
|||
public void call(final Throwable throwable) {
|
||||
final Span span = spanRef.getAndSet(null);
|
||||
if (span != null) {
|
||||
CouchbaseClientDecorator.INSTANCE.onError(span, throwable);
|
||||
CouchbaseClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.net.InetAddress;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
public class CassandraClientDecorator extends DatabaseClientDecorator<Session> {
|
||||
public static final CassandraClientDecorator INSTANCE = new CassandraClientDecorator();
|
||||
public static final CassandraClientDecorator DECORATE = new CassandraClientDecorator();
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package datadog.trace.instrumentation.datastax.cassandra;
|
||||
|
||||
import static datadog.trace.instrumentation.datastax.cassandra.CassandraClientDecorator.DECORATE;
|
||||
|
||||
import com.datastax.driver.core.BoundStatement;
|
||||
import com.datastax.driver.core.CloseFuture;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
|
@ -209,21 +211,21 @@ public class TracingSession implements Session {
|
|||
|
||||
private Span buildSpan(final String query) {
|
||||
final Span span = tracer.buildSpan("cassandra.execute").start();
|
||||
CassandraClientDecorator.INSTANCE.afterStart(span);
|
||||
CassandraClientDecorator.INSTANCE.onSession(span, session);
|
||||
CassandraClientDecorator.INSTANCE.onStatement(span, query);
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onSession(span, session);
|
||||
DECORATE.onStatement(span, query);
|
||||
return span;
|
||||
}
|
||||
|
||||
private static void finishSpan(final Span span, final ResultSet resultSet) {
|
||||
CassandraClientDecorator.INSTANCE.onResponse(span, resultSet);
|
||||
CassandraClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onResponse(span, resultSet);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
|
||||
private static void finishSpan(final Span span, final Exception e) {
|
||||
CassandraClientDecorator.INSTANCE.onError(span, e);
|
||||
CassandraClientDecorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onError(span, e);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package datadog.trace.instrumentation.servlet2;
|
||||
|
||||
import static datadog.trace.instrumentation.servlet2.Servlet2Decorator.DECORATE;
|
||||
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.context.TraceScope;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -37,8 +39,8 @@ public class Servlet2Advice {
|
|||
.withTag("span.origin.type", servlet.getClass().getName())
|
||||
.startActive(true);
|
||||
|
||||
Servlet2Decorator.INSTANCE.afterStart(scope.span());
|
||||
Servlet2Decorator.INSTANCE.onRequest(scope.span(), httpServletRequest);
|
||||
DECORATE.afterStart(scope.span());
|
||||
DECORATE.onRequest(scope.span(), httpServletRequest);
|
||||
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(true);
|
||||
|
@ -64,9 +66,9 @@ public class Servlet2Advice {
|
|||
}
|
||||
|
||||
if (scope != null) {
|
||||
Servlet2Decorator.INSTANCE.onResponse(scope.span(), response);
|
||||
Servlet2Decorator.INSTANCE.onError(scope.span(), throwable);
|
||||
Servlet2Decorator.INSTANCE.beforeFinish(scope.span());
|
||||
DECORATE.onResponse(scope.span(), response);
|
||||
DECORATE.onError(scope.span(), throwable);
|
||||
DECORATE.beforeFinish(scope.span());
|
||||
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(false);
|
||||
|
|
|
@ -6,7 +6,7 @@ import javax.servlet.ServletResponse;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class Servlet2Decorator extends HttpServerDecorator<HttpServletRequest, ServletResponse> {
|
||||
public static final Servlet2Decorator INSTANCE = new Servlet2Decorator();
|
||||
public static final Servlet2Decorator DECORATE = new Servlet2Decorator();
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package datadog.trace.instrumentation.servlet3;
|
||||
|
||||
import static datadog.trace.instrumentation.servlet3.Servlet3Decorator.DECORATE;
|
||||
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.context.TraceScope;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -42,8 +44,8 @@ public class Servlet3Advice {
|
|||
.withTag("span.origin.type", servlet.getClass().getName())
|
||||
.startActive(false);
|
||||
|
||||
Servlet3Decorator.INSTANCE.afterStart(scope.span());
|
||||
Servlet3Decorator.INSTANCE.onRequest(scope.span(), httpServletRequest);
|
||||
DECORATE.afterStart(scope.span());
|
||||
DECORATE.onRequest(scope.span(), httpServletRequest);
|
||||
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(true);
|
||||
|
@ -75,13 +77,13 @@ public class Servlet3Advice {
|
|||
final Span span = scope.span();
|
||||
|
||||
if (throwable != null) {
|
||||
Servlet3Decorator.INSTANCE.onResponse(span, resp);
|
||||
DECORATE.onResponse(span, resp);
|
||||
if (resp.getStatus() == HttpServletResponse.SC_OK) {
|
||||
// exception is thrown in filter chain, but status code is incorrect
|
||||
Tags.HTTP_STATUS.set(span, 500);
|
||||
}
|
||||
Servlet3Decorator.INSTANCE.onError(span, throwable);
|
||||
Servlet3Decorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onError(span, throwable);
|
||||
DECORATE.beforeFinish(span);
|
||||
req.removeAttribute(SERVLET_SPAN);
|
||||
span.finish(); // Finish the span manually since finishSpanOnClose was false
|
||||
} else {
|
||||
|
@ -96,8 +98,8 @@ public class Servlet3Advice {
|
|||
}
|
||||
// Check again in case the request finished before adding the listener.
|
||||
if (!req.isAsyncStarted() && activated.compareAndSet(false, true)) {
|
||||
Servlet3Decorator.INSTANCE.onResponse(span, resp);
|
||||
Servlet3Decorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onResponse(span, resp);
|
||||
DECORATE.beforeFinish(span);
|
||||
req.removeAttribute(SERVLET_SPAN);
|
||||
span.finish(); // Finish the span manually since finishSpanOnClose was false
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
public class Servlet3Decorator
|
||||
extends HttpServerDecorator<HttpServletRequest, HttpServletResponse> {
|
||||
public static final Servlet3Decorator INSTANCE = new Servlet3Decorator();
|
||||
public static final Servlet3Decorator DECORATE = new Servlet3Decorator();
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package datadog.trace.instrumentation.servlet3;
|
||||
|
||||
import static datadog.trace.instrumentation.servlet3.Servlet3Decorator.DECORATE;
|
||||
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.tag.Tags;
|
||||
import java.io.IOException;
|
||||
|
@ -20,9 +22,8 @@ public class TagSettingAsyncListener implements AsyncListener {
|
|||
@Override
|
||||
public void onComplete(final AsyncEvent event) throws IOException {
|
||||
if (activated.compareAndSet(false, true)) {
|
||||
Servlet3Decorator.INSTANCE.onResponse(
|
||||
span, (HttpServletResponse) event.getSuppliedResponse());
|
||||
Servlet3Decorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onResponse(span, (HttpServletResponse) event.getSuppliedResponse());
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +33,7 @@ public class TagSettingAsyncListener implements AsyncListener {
|
|||
if (activated.compareAndSet(false, true)) {
|
||||
Tags.ERROR.set(span, Boolean.TRUE);
|
||||
span.setTag("timeout", event.getAsyncContext().getTimeout());
|
||||
Servlet3Decorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +46,8 @@ public class TagSettingAsyncListener implements AsyncListener {
|
|||
// exception is thrown in filter chain, but status code is incorrect
|
||||
Tags.HTTP_STATUS.set(span, 500);
|
||||
}
|
||||
Servlet3Decorator.INSTANCE.onError(span, event.getThrowable());
|
||||
Servlet3Decorator.INSTANCE.beforeFinish(span);
|
||||
DECORATE.onError(span, event.getThrowable());
|
||||
DECORATE.beforeFinish(span);
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue