Merge pull request #316 from DataDog/tyler/async-flag

Enable async tracking for some non-async frameworks
This commit is contained in:
Tyler Benson 2018-05-11 09:30:17 +10:00 committed by GitHub
commit 632d9b8da4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 20 deletions

View File

@ -15,6 +15,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@ -94,6 +95,10 @@ public final class HandlerInstrumentation extends Instrumenter.Configurable {
.withTag("span.origin.type", source.getClass().getName())
.startActive(false);
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(true);
}
final Span span = scope.span();
Tags.HTTP_METHOD.set(span, req.getMethod());
Tags.HTTP_URL.set(span, req.getRequestURL().toString());

View File

@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.DDTransformers;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.context.TraceScope;
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
import io.opentracing.Scope;
import io.opentracing.Span;
@ -64,16 +65,23 @@ public final class JMS1MessageListenerInstrumentation extends Instrumenter.Confi
final SpanContext extractedContext =
GlobalTracer.get().extract(Format.Builtin.TEXT_MAP, new MessagePropertyTextMap(message));
return GlobalTracer.get()
.buildSpan("jms.onMessage")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "jms")
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
.withTag(DDTags.RESOURCE_NAME, "Received from " + toResourceName(message, null))
.withTag(Tags.COMPONENT.getKey(), "jms1")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.withTag("span.origin.type", listener.getClass().getName())
.startActive(true);
final Scope scope =
GlobalTracer.get()
.buildSpan("jms.onMessage")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "jms")
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
.withTag(DDTags.RESOURCE_NAME, "Received from " + toResourceName(message, null))
.withTag(Tags.COMPONENT.getKey(), "jms1")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.withTag("span.origin.type", listener.getClass().getName())
.startActive(true);
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(true);
}
return scope;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)

View File

@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.DDTransformers;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.context.TraceScope;
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
import io.opentracing.Scope;
import io.opentracing.Span;
@ -64,16 +65,23 @@ public final class JMS2MessageListenerInstrumentation extends Instrumenter.Confi
final SpanContext extractedContext =
GlobalTracer.get().extract(Format.Builtin.TEXT_MAP, new MessagePropertyTextMap(message));
return GlobalTracer.get()
.buildSpan("jms.onMessage")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "jms")
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
.withTag(DDTags.RESOURCE_NAME, "Received from " + toResourceName(message, null))
.withTag(Tags.COMPONENT.getKey(), "jms2")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.withTag("span.origin.type", listener.getClass().getName())
.startActive(true);
final Scope scope =
GlobalTracer.get()
.buildSpan("jms.onMessage")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "jms")
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
.withTag(DDTags.RESOURCE_NAME, "Received from " + toResourceName(message, null))
.withTag(Tags.COMPONENT.getKey(), "jms2")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.withTag("span.origin.type", listener.getClass().getName())
.startActive(true);
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(true);
}
return scope;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)

View File

@ -16,6 +16,7 @@ import datadog.trace.agent.tooling.DDTransformers;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@ -84,6 +85,10 @@ public final class FilterChain2Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(true);
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(true);
}
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, ((HttpServletRequest) req).getMethod());

View File

@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@ -86,6 +87,10 @@ public final class HttpServlet2Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(true);
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(true);
}
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, req.getMethod());

View File

@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@ -89,6 +90,10 @@ public final class FilterChain3Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(false);
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(true);
}
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, ((HttpServletRequest) req).getMethod());

View File

@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@ -85,6 +86,10 @@ public final class HttpServlet3Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(false);
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(true);
}
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, req.getMethod());