Remove OpenTracing interoperability (#44)
* Remove dependency on OpenTracing constants * Remove OpenTracing tracer resolver * Remove dep on OpenTracing Tracer and GlobalTracer * Remove dep on OpenTracing ScopeManager/Context * Remove dep on OpenTracing References * Remove dep on OpenTracing Format * Remove dep on OpenTracing Scope * Remove dep on OpenTracing Span * Remove OpenTracing compatibility tests * Remove dep on OpenTracing SpanContext * Remove dep on OpenTracing propagation classes * Remove dep on OpenTracing log field name constants * Remove dependency on OpenTracing * Some last OpenTracing related renaming * Remove unused code * Remove code that's not doing anything * A bit more cleanup
This commit is contained in:
parent
1fced9d473
commit
71cd1a69b3
|
@ -1,6 +1,5 @@
|
|||
Component,Origin,License,Copyright
|
||||
https://github.com/DataDog/dd-trace-java/blob/dev/dd-trace/src/main/java/com/datadoghq/trace/propagation/Codec.java,Uber,MIT,
|
||||
import,io.opentracing,Apache-2.0,Copyright 2016-2017 The OpenTracing Authors
|
||||
import,org.slf4j,MIT,Copyright (c) 2004-2017 QOS.ch
|
||||
import,com.google.auto.service.AutoService,Apache-2.0,"Copyright 2013 Google, Inc."
|
||||
logback.xml,ch.qos.logback,EPL-1.0 OR LGPL-2.1,"Copyright (C) 1999-2015, QOS.ch. All rights reserved."
|
||||
|
|
|
|
@ -7,7 +7,6 @@ apply from: "${rootDir}/gradle/java.gradle"
|
|||
|
||||
dependencies {
|
||||
compile project(':dd-trace-api')
|
||||
compile deps.opentracing
|
||||
compile deps.slf4j
|
||||
compile group: 'org.slf4j', name: 'slf4j-simple', version: versions.slf4j
|
||||
// ^ Generally a bad idea for libraries, but we're shadowing.
|
||||
|
|
|
@ -13,8 +13,6 @@ public interface AgentSpan {
|
|||
|
||||
AgentSpan setError(boolean error);
|
||||
|
||||
AgentSpan setErrorMessage(String errorMessage);
|
||||
|
||||
AgentSpan addThrowable(Throwable throwable);
|
||||
|
||||
AgentSpan getLocalRootSpan();
|
||||
|
|
|
@ -167,11 +167,6 @@ public class AgentTracer {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan setErrorMessage(final String errorMessage) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan addThrowable(final Throwable throwable) {
|
||||
return this;
|
||||
|
|
|
@ -22,7 +22,6 @@ dependencies {
|
|||
|
||||
compile project(':dd-trace-ot')
|
||||
|
||||
testCompile deps.opentracing
|
||||
testCompile project(':dd-java-agent:testing')
|
||||
testCompile project(':utils:gc-utils')
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package datadog.trace.agent.decorator;
|
|||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.api.AgentScope;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import io.opentracing.tag.Tags;
|
||||
import datadog.trace.instrumentation.api.Tags;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
|
@ -26,7 +26,7 @@ public abstract class BaseDecorator {
|
|||
if (spanType() != null) {
|
||||
span.setTag(DDTags.SPAN_TYPE, spanType());
|
||||
}
|
||||
span.setTag(Tags.COMPONENT.getKey(), component());
|
||||
span.setTag(Tags.COMPONENT, component());
|
||||
return span;
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ public abstract class BaseDecorator {
|
|||
if (remoteConnection != null) {
|
||||
onPeerConnection(span, remoteConnection.getAddress());
|
||||
|
||||
span.setTag(Tags.PEER_HOSTNAME.getKey(), remoteConnection.getHostName());
|
||||
span.setTag(Tags.PEER_PORT.getKey(), remoteConnection.getPort());
|
||||
span.setTag(Tags.PEER_HOSTNAME, remoteConnection.getHostName());
|
||||
span.setTag(Tags.PEER_PORT, remoteConnection.getPort());
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
@ -71,11 +71,11 @@ public abstract class BaseDecorator {
|
|||
public AgentSpan onPeerConnection(final AgentSpan span, final InetAddress remoteAddress) {
|
||||
assert span != null;
|
||||
if (remoteAddress != null) {
|
||||
span.setTag(Tags.PEER_HOSTNAME.getKey(), remoteAddress.getHostName());
|
||||
span.setTag(Tags.PEER_HOSTNAME, remoteAddress.getHostName());
|
||||
if (remoteAddress instanceof Inet4Address) {
|
||||
span.setTag(Tags.PEER_HOST_IPV4.getKey(), remoteAddress.getHostAddress());
|
||||
span.setTag(Tags.PEER_HOST_IPV4, remoteAddress.getHostAddress());
|
||||
} else if (remoteAddress instanceof Inet6Address) {
|
||||
span.setTag(Tags.PEER_HOST_IPV6.getKey(), remoteAddress.getHostAddress());
|
||||
span.setTag(Tags.PEER_HOST_IPV6, remoteAddress.getHostAddress());
|
||||
}
|
||||
}
|
||||
return span;
|
||||
|
|
|
@ -2,7 +2,7 @@ package datadog.trace.agent.decorator;
|
|||
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import io.opentracing.tag.Tags;
|
||||
import datadog.trace.instrumentation.api.Tags;
|
||||
|
||||
public abstract class ClientDecorator extends BaseDecorator {
|
||||
|
||||
|
@ -18,7 +18,7 @@ public abstract class ClientDecorator extends BaseDecorator {
|
|||
if (service() != null) {
|
||||
span.setTag(DDTags.SERVICE_NAME, service());
|
||||
}
|
||||
span.setTag(Tags.SPAN_KIND.getKey(), spanKind());
|
||||
span.setTag(Tags.SPAN_KIND, spanKind());
|
||||
return super.afterStart(span);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package datadog.trace.agent.decorator;
|
|||
import datadog.trace.api.Config;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import io.opentracing.tag.Tags;
|
||||
import datadog.trace.instrumentation.api.Tags;
|
||||
|
||||
public abstract class DatabaseClientDecorator<CONNECTION> extends ClientDecorator {
|
||||
|
||||
|
@ -16,7 +16,7 @@ public abstract class DatabaseClientDecorator<CONNECTION> extends ClientDecorato
|
|||
@Override
|
||||
public AgentSpan afterStart(final AgentSpan span) {
|
||||
assert span != null;
|
||||
span.setTag(Tags.DB_TYPE.getKey(), dbType());
|
||||
span.setTag(Tags.DB_TYPE, dbType());
|
||||
return super.afterStart(span);
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,9 @@ public abstract class DatabaseClientDecorator<CONNECTION> extends ClientDecorato
|
|||
public AgentSpan onConnection(final AgentSpan span, final CONNECTION connection) {
|
||||
assert span != null;
|
||||
if (connection != null) {
|
||||
span.setTag(Tags.DB_USER.getKey(), dbUser(connection));
|
||||
span.setTag(Tags.DB_USER, dbUser(connection));
|
||||
final String instanceName = dbInstance(connection);
|
||||
span.setTag(Tags.DB_INSTANCE.getKey(), instanceName);
|
||||
span.setTag(Tags.DB_INSTANCE, instanceName);
|
||||
|
||||
if (instanceName != null && Config.get().isDbClientSplitByInstance()) {
|
||||
span.setTag(DDTags.SERVICE_NAME, instanceName);
|
||||
|
@ -43,7 +43,7 @@ public abstract class DatabaseClientDecorator<CONNECTION> extends ClientDecorato
|
|||
|
||||
public AgentSpan onStatement(final AgentSpan span, final String statement) {
|
||||
assert span != null;
|
||||
span.setTag(Tags.DB_STATEMENT.getKey(), statement);
|
||||
span.setTag(Tags.DB_STATEMENT, statement);
|
||||
return span;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import datadog.trace.api.Config;
|
|||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import io.opentracing.tag.Tags;
|
||||
import datadog.trace.instrumentation.api.Tags;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -35,7 +35,7 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
|||
public AgentSpan onRequest(final AgentSpan span, final REQUEST request) {
|
||||
assert span != null;
|
||||
if (request != null) {
|
||||
span.setTag(Tags.HTTP_METHOD.getKey(), method(request));
|
||||
span.setTag(Tags.HTTP_METHOD, method(request));
|
||||
|
||||
// Copy of HttpServerDecorator url handling
|
||||
try {
|
||||
|
@ -60,7 +60,7 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
|||
urlNoParams.append(path);
|
||||
}
|
||||
|
||||
span.setTag(Tags.HTTP_URL.getKey(), urlNoParams.toString());
|
||||
span.setTag(Tags.HTTP_URL, urlNoParams.toString());
|
||||
|
||||
if (Config.get().isHttpClientTagQueryString()) {
|
||||
span.setTag(DDTags.HTTP_QUERY, url.getQuery());
|
||||
|
@ -71,11 +71,11 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
|||
log.debug("Error tagging url", e);
|
||||
}
|
||||
|
||||
span.setTag(Tags.PEER_HOSTNAME.getKey(), hostname(request));
|
||||
span.setTag(Tags.PEER_HOSTNAME, hostname(request));
|
||||
final Integer port = port(request);
|
||||
// Negative or Zero ports might represent an unset/null value for an int type. Skip setting.
|
||||
if (port != null && port > 0) {
|
||||
span.setTag(Tags.PEER_PORT.getKey(), port);
|
||||
span.setTag(Tags.PEER_PORT, port);
|
||||
}
|
||||
|
||||
if (Config.get().isHttpClientSplitByDomain()) {
|
||||
|
@ -90,7 +90,7 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
|||
if (response != null) {
|
||||
final Integer status = status(response);
|
||||
if (status != null) {
|
||||
span.setTag(Tags.HTTP_STATUS.getKey(), status);
|
||||
span.setTag(Tags.HTTP_STATUS, status);
|
||||
|
||||
if (Config.get().getHttpClientErrorStatuses().contains(status)) {
|
||||
span.setError(true);
|
||||
|
|
|
@ -4,7 +4,7 @@ import datadog.trace.api.Config;
|
|||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import io.opentracing.tag.Tags;
|
||||
import datadog.trace.instrumentation.api.Tags;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -39,7 +39,7 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
|||
public AgentSpan onRequest(final AgentSpan span, final REQUEST request) {
|
||||
assert span != null;
|
||||
if (request != null) {
|
||||
span.setTag(Tags.HTTP_METHOD.getKey(), method(request));
|
||||
span.setTag(Tags.HTTP_METHOD, method(request));
|
||||
|
||||
// Copy of HttpClientDecorator url handling
|
||||
try {
|
||||
|
@ -64,7 +64,7 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
|||
urlNoParams.append(path);
|
||||
}
|
||||
|
||||
span.setTag(Tags.HTTP_URL.getKey(), urlNoParams.toString());
|
||||
span.setTag(Tags.HTTP_URL, urlNoParams.toString());
|
||||
|
||||
if (Config.get().isHttpServerTagQueryString()) {
|
||||
span.setTag(DDTags.HTTP_QUERY, url.getQuery());
|
||||
|
@ -82,19 +82,19 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
|||
public AgentSpan onConnection(final AgentSpan span, final CONNECTION connection) {
|
||||
assert span != null;
|
||||
if (connection != null) {
|
||||
span.setTag(Tags.PEER_HOSTNAME.getKey(), peerHostname(connection));
|
||||
span.setTag(Tags.PEER_HOSTNAME, peerHostname(connection));
|
||||
final String ip = peerHostIP(connection);
|
||||
if (ip != null) {
|
||||
if (VALID_IPV4_ADDRESS.matcher(ip).matches()) {
|
||||
span.setTag(Tags.PEER_HOST_IPV4.getKey(), ip);
|
||||
span.setTag(Tags.PEER_HOST_IPV4, ip);
|
||||
} else if (ip.contains(":")) {
|
||||
span.setTag(Tags.PEER_HOST_IPV6.getKey(), ip);
|
||||
span.setTag(Tags.PEER_HOST_IPV6, ip);
|
||||
}
|
||||
}
|
||||
final Integer port = peerPort(connection);
|
||||
// Negative or Zero ports might represent an unset/null value for an int type. Skip setting.
|
||||
if (port != null && port > 0) {
|
||||
span.setTag(Tags.PEER_PORT.getKey(), port);
|
||||
span.setTag(Tags.PEER_PORT, port);
|
||||
}
|
||||
}
|
||||
return span;
|
||||
|
@ -105,7 +105,7 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
|||
if (response != null) {
|
||||
final Integer status = status(response);
|
||||
if (status != null) {
|
||||
span.setTag(Tags.HTTP_STATUS.getKey(), status);
|
||||
span.setTag(Tags.HTTP_STATUS, status);
|
||||
|
||||
if (Config.get().getHttpServerErrorStatuses().contains(status)) {
|
||||
span.setError(true);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package datadog.trace.agent.decorator;
|
||||
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import io.opentracing.tag.Tags;
|
||||
import datadog.trace.instrumentation.api.Tags;
|
||||
|
||||
public abstract class ServerDecorator extends BaseDecorator {
|
||||
|
||||
@Override
|
||||
public AgentSpan afterStart(final AgentSpan span) {
|
||||
assert span != null;
|
||||
span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
|
||||
span.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_SERVER);
|
||||
return super.afterStart(span);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,65 +1,62 @@
|
|||
package datadog.trace.agent.tooling;
|
||||
|
||||
import static io.opentracing.log.Fields.ERROR_OBJECT;
|
||||
import static io.opentracing.propagation.Format.Builtin.TEXT_MAP_EXTRACT;
|
||||
import static io.opentracing.propagation.Format.Builtin.TEXT_MAP_INJECT;
|
||||
import static java.util.Collections.singletonMap;
|
||||
|
||||
import datadog.opentracing.DDSpan;
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.opentracing.NoopSpan;
|
||||
import datadog.opentracing.Span;
|
||||
import datadog.opentracing.SpanContext;
|
||||
import datadog.opentracing.propagation.TextMapExtract;
|
||||
import datadog.opentracing.propagation.TextMapInject;
|
||||
import datadog.opentracing.scopemanager.DDScope;
|
||||
import datadog.trace.context.TraceScope;
|
||||
import datadog.trace.instrumentation.api.AgentPropagation;
|
||||
import datadog.trace.instrumentation.api.AgentPropagation.Getter;
|
||||
import datadog.trace.instrumentation.api.AgentScope;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import datadog.trace.instrumentation.api.AgentTracer.TracerAPI;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.log.Fields;
|
||||
import io.opentracing.noop.NoopSpan;
|
||||
import io.opentracing.propagation.TextMapExtract;
|
||||
import io.opentracing.propagation.TextMapInject;
|
||||
import io.opentracing.tag.Tags;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public final class OpenTracing32 implements TracerAPI {
|
||||
public final class AgentTracerImpl implements TracerAPI {
|
||||
|
||||
private final Tracer tracer = GlobalTracer.get();
|
||||
private final OT32AgentPropagation propagation = new OT32AgentPropagation();
|
||||
private final DDTracer tracer;
|
||||
private final AgentPropagationImpl propagation = new AgentPropagationImpl();
|
||||
|
||||
private final OT32Span NOOP_SPAN = new OT32Span("", NoopSpan.INSTANCE);
|
||||
private final AgentSpanImpl NOOP_SPAN = new AgentSpanImpl("", NoopSpan.INSTANCE);
|
||||
|
||||
public AgentTracerImpl(final DDTracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan startSpan(final String spanName) {
|
||||
return new OT32Span(spanName);
|
||||
return new AgentSpanImpl(spanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan startSpan(final String spanName, final long startTimeMicros) {
|
||||
return new OT32Span(spanName, startTimeMicros);
|
||||
return new AgentSpanImpl(spanName, startTimeMicros);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan startSpan(final String spanName, final AgentSpan.Context parent) {
|
||||
return new OT32Span(spanName, (OT32Context) parent);
|
||||
return new AgentSpanImpl(spanName, (AgentContextImpl) parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan startSpan(
|
||||
final String spanName, final AgentSpan.Context parent, final long startTimeMicros) {
|
||||
return new OT32Span(spanName, parent, startTimeMicros);
|
||||
return new AgentSpanImpl(spanName, parent, startTimeMicros);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentScope activateSpan(final AgentSpan span, final boolean finishSpanOnClose) {
|
||||
// when span is noopSpan(), the scope returned is not a TracerScope
|
||||
final Scope scope = tracer.scopeManager().activate(((OT32Span) span).span, finishSpanOnClose);
|
||||
return new OT32Scope(span, scope);
|
||||
final DDScope scope =
|
||||
tracer.scopeManager().activate(((AgentSpanImpl) span).span, finishSpanOnClose);
|
||||
return new AgentScopeImpl(span, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,12 +72,12 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
} else {
|
||||
spanName = "";
|
||||
}
|
||||
return new OT32Span(spanName, span);
|
||||
return new AgentSpanImpl(spanName, span);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceScope activeScope() {
|
||||
final Scope scope = tracer.scopeManager().active();
|
||||
final DDScope scope = tracer.scopeManager().active();
|
||||
if (scope instanceof TraceScope) {
|
||||
return (TraceScope) scope;
|
||||
} else {
|
||||
|
@ -98,37 +95,37 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
return NOOP_SPAN;
|
||||
}
|
||||
|
||||
private final class OT32Span implements AgentSpan {
|
||||
private final class AgentSpanImpl implements AgentSpan {
|
||||
|
||||
private final Span span;
|
||||
private volatile String spanName;
|
||||
|
||||
private OT32Span(final String spanName) {
|
||||
private AgentSpanImpl(final String spanName) {
|
||||
this(spanName, tracer.buildSpan(spanName).start());
|
||||
}
|
||||
|
||||
private OT32Span(final String spanName, final long startTimeMicros) {
|
||||
private AgentSpanImpl(final String spanName, final long startTimeMicros) {
|
||||
this(spanName, tracer.buildSpan(spanName).withStartTimestamp(startTimeMicros).start());
|
||||
}
|
||||
|
||||
private OT32Span(final String spanName, final OT32Context parent) {
|
||||
private AgentSpanImpl(final String spanName, final AgentContextImpl parent) {
|
||||
this(
|
||||
spanName,
|
||||
tracer.buildSpan(spanName).ignoreActiveSpan().asChildOf(parent.context).start());
|
||||
}
|
||||
|
||||
private OT32Span(final String spanName, final Context parent, final long startTimeMicros) {
|
||||
private AgentSpanImpl(final String spanName, final Context parent, final long startTimeMicros) {
|
||||
this(
|
||||
spanName,
|
||||
tracer
|
||||
.buildSpan(spanName)
|
||||
.ignoreActiveSpan()
|
||||
.asChildOf(((OT32Context) parent).context)
|
||||
.asChildOf(((AgentContextImpl) parent).context)
|
||||
.withStartTimestamp(startTimeMicros)
|
||||
.start());
|
||||
}
|
||||
|
||||
private OT32Span(final String spanName, final Span span) {
|
||||
private AgentSpanImpl(final String spanName, final Span span) {
|
||||
this.spanName = spanName;
|
||||
this.span = span;
|
||||
}
|
||||
|
@ -168,20 +165,16 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
if (span instanceof DDSpan) {
|
||||
((DDSpan) span).setError(error);
|
||||
} else {
|
||||
Tags.ERROR.set(span, error);
|
||||
span.setTag("error", error);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan setErrorMessage(final String errorMessage) {
|
||||
span.log(singletonMap(Fields.MESSAGE, errorMessage));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentSpan addThrowable(final Throwable throwable) {
|
||||
span.log(singletonMap(ERROR_OBJECT, throwable));
|
||||
if (span instanceof DDSpan) {
|
||||
((DDSpan) span).setErrorMeta(throwable);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -192,15 +185,15 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
if (root == span) {
|
||||
return this;
|
||||
}
|
||||
return new OT32Span(root.getOperationName(), (Span) root);
|
||||
return new AgentSpanImpl(root.getOperationName(), (Span) root);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OT32Context context() {
|
||||
public AgentContextImpl context() {
|
||||
final SpanContext context = span.context();
|
||||
return new OT32Context(context);
|
||||
return new AgentContextImpl(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -224,14 +217,14 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
}
|
||||
}
|
||||
|
||||
private final class OT32Scope implements AgentScope {
|
||||
private final class AgentScopeImpl implements AgentScope {
|
||||
|
||||
private final OT32Span span;
|
||||
private final Scope scope;
|
||||
private final AgentSpanImpl span;
|
||||
private final DDScope scope;
|
||||
|
||||
private OT32Scope(final AgentSpan span, final Scope scope) {
|
||||
assert span instanceof OT32Span;
|
||||
this.span = (OT32Span) span;
|
||||
private AgentScopeImpl(final AgentSpan span, final DDScope scope) {
|
||||
assert span instanceof AgentSpanImpl;
|
||||
this.span = (AgentSpanImpl) span;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
|
@ -254,11 +247,11 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
}
|
||||
}
|
||||
|
||||
private final class OT32AgentPropagation implements AgentPropagation {
|
||||
private final class AgentPropagationImpl implements AgentPropagation {
|
||||
|
||||
@Override
|
||||
public TraceScope.Continuation capture() {
|
||||
final Scope active = tracer.scopeManager().active();
|
||||
final DDScope active = tracer.scopeManager().active();
|
||||
if (active instanceof TraceScope) {
|
||||
return ((TraceScope) active).capture();
|
||||
} else {
|
||||
|
@ -268,11 +261,10 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
|
||||
@Override
|
||||
public <C> void inject(final AgentSpan span, final C carrier, final Setter<C> setter) {
|
||||
assert span instanceof OT32Span;
|
||||
assert span instanceof AgentSpanImpl;
|
||||
tracer.inject(
|
||||
((OT32Span) span).getSpan().context(),
|
||||
TEXT_MAP_INJECT,
|
||||
new OT32AgentPropagation.Injector<>(carrier, setter));
|
||||
((AgentSpanImpl) span).getSpan().context(),
|
||||
new AgentPropagationImpl.Injector<>(carrier, setter));
|
||||
}
|
||||
|
||||
private final class Injector<C> implements TextMapInject {
|
||||
|
@ -292,7 +284,7 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
|
||||
@Override
|
||||
public <C> AgentSpan.Context extract(final C carrier, final Getter<C> getter) {
|
||||
return new OT32Context(tracer.extract(TEXT_MAP_EXTRACT, new Extractor(carrier, getter)));
|
||||
return new AgentContextImpl(tracer.extract(new Extractor(carrier, getter)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,26 +304,11 @@ public final class OpenTracing32 implements TracerAPI {
|
|||
}
|
||||
}
|
||||
|
||||
private static final class OT32Context implements AgentSpan.Context, SpanContext {
|
||||
private static final class AgentContextImpl implements AgentSpan.Context, SpanContext {
|
||||
private final SpanContext context;
|
||||
|
||||
private OT32Context(final SpanContext context) {
|
||||
private AgentContextImpl(final SpanContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toTraceId() {
|
||||
return context.toTraceId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSpanId() {
|
||||
return context.toSpanId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Entry<String, String>> baggageItems() {
|
||||
return context.baggageItems();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import static datadog.trace.bootstrap.WeakMap.Provider.newWeakMap;
|
|||
import datadog.trace.bootstrap.DatadogClassLoader;
|
||||
import datadog.trace.bootstrap.PatchLogger;
|
||||
import datadog.trace.bootstrap.WeakMap;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -101,10 +100,6 @@ public class ClassLoaderMatcher {
|
|||
*/
|
||||
private boolean delegatesToBootstrap(final ClassLoader loader) {
|
||||
boolean delegates = true;
|
||||
if (!loadsExpectedClass(loader, GlobalTracer.class)) {
|
||||
log.debug("loader {} failed to delegate bootstrap opentracing class", loader);
|
||||
delegates = false;
|
||||
}
|
||||
if (!loadsExpectedClass(loader, PatchLogger.class)) {
|
||||
log.debug("loader {} failed to delegate bootstrap datadog class", loader);
|
||||
delegates = false;
|
||||
|
|
|
@ -18,8 +18,7 @@ public final class Constants {
|
|||
"datadog.trace.api",
|
||||
"datadog.trace.bootstrap",
|
||||
"datadog.trace.context",
|
||||
"datadog.trace.instrumentation.api",
|
||||
"io.opentracing",
|
||||
"datadog.trace.instrumentation.api"
|
||||
};
|
||||
|
||||
// This is used in IntegrationTestUtils.java
|
||||
|
@ -35,8 +34,6 @@ public final class Constants {
|
|||
"com.blogspot.mydailyjava.weaklockfree",
|
||||
// bytebuddy
|
||||
"net.bytebuddy",
|
||||
// OT contribs for dd trace resolver
|
||||
"io.opentracing.contrib",
|
||||
"org.yaml.snakeyaml",
|
||||
// disruptor
|
||||
"com.lmax.disruptor",
|
||||
|
|
|
@ -10,29 +10,20 @@ public class TracerInstaller {
|
|||
/** Register a global tracer if no global tracer is already registered. */
|
||||
public static synchronized void installGlobalTracer() {
|
||||
if (Config.get().isTraceEnabled()) {
|
||||
if (!io.opentracing.util.GlobalTracer.isRegistered()) {
|
||||
final DDTracer tracer = new DDTracer();
|
||||
try {
|
||||
io.opentracing.util.GlobalTracer.register(tracer);
|
||||
datadog.trace.api.GlobalTracer.registerIfAbsent(tracer);
|
||||
AgentTracer.registerIfAbsent(new OpenTracing32());
|
||||
} catch (final RuntimeException re) {
|
||||
log.warn("Failed to register tracer '" + tracer + "'", re);
|
||||
}
|
||||
} else {
|
||||
log.debug("GlobalTracer already registered.");
|
||||
final DDTracer tracer = new DDTracer();
|
||||
try {
|
||||
datadog.trace.api.GlobalTracer.registerIfAbsent(tracer);
|
||||
AgentTracer.registerIfAbsent(new AgentTracerImpl(tracer));
|
||||
} catch (final RuntimeException re) {
|
||||
log.warn("Failed to register tracer '" + tracer + "'", re);
|
||||
}
|
||||
} else {
|
||||
log.debug("Tracing is disabled, not installing GlobalTracer.");
|
||||
log.debug("Tracing is disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void logVersionInfo() {
|
||||
VersionLogger.logAllVersions();
|
||||
log.debug(
|
||||
io.opentracing.util.GlobalTracer.class.getName()
|
||||
+ " loaded on "
|
||||
+ io.opentracing.util.GlobalTracer.class.getClassLoader());
|
||||
log.debug(
|
||||
AgentInstaller.class.getName() + " loaded on " + AgentInstaller.class.getClassLoader());
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ package datadog.trace.agent.decorator
|
|||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.instrumentation.api.AgentScope
|
||||
import datadog.trace.instrumentation.api.AgentSpan
|
||||
import datadog.trace.instrumentation.api.Tags
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.tag.Tags
|
||||
import spock.lang.Shared
|
||||
|
||||
class BaseDecoratorTest extends DDSpecification {
|
||||
|
@ -21,7 +21,7 @@ class BaseDecoratorTest extends DDSpecification {
|
|||
|
||||
then:
|
||||
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())
|
||||
1 * span.setTag(Tags.COMPONENT.key, "test-component")
|
||||
1 * span.setTag(Tags.COMPONENT, "test-component")
|
||||
_ * span.setTag(_, _) // Want to allow other calls from child implementations.
|
||||
0 * _
|
||||
}
|
||||
|
@ -32,16 +32,16 @@ class BaseDecoratorTest extends DDSpecification {
|
|||
|
||||
then:
|
||||
if (connection.getAddress()) {
|
||||
2 * span.setTag(Tags.PEER_HOSTNAME.key, connection.hostName)
|
||||
2 * span.setTag(Tags.PEER_HOSTNAME, connection.hostName)
|
||||
} else {
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME.key, connection.hostName)
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME, connection.hostName)
|
||||
}
|
||||
1 * span.setTag(Tags.PEER_PORT.key, connection.port)
|
||||
1 * span.setTag(Tags.PEER_PORT, connection.port)
|
||||
if (connection.address instanceof Inet4Address) {
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV4.key, connection.address.hostAddress)
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV4, connection.address.hostAddress)
|
||||
}
|
||||
if (connection.address instanceof Inet6Address) {
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV6.key, connection.address.hostAddress)
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV6, connection.address.hostAddress)
|
||||
}
|
||||
0 * _
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package datadog.trace.agent.decorator
|
|||
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.instrumentation.api.AgentSpan
|
||||
import io.opentracing.tag.Tags
|
||||
import datadog.trace.instrumentation.api.Tags
|
||||
|
||||
class ClientDecoratorTest extends BaseDecoratorTest {
|
||||
|
||||
|
@ -19,8 +19,8 @@ class ClientDecoratorTest extends BaseDecoratorTest {
|
|||
if (serviceName != null) {
|
||||
1 * span.setTag(DDTags.SERVICE_NAME, serviceName)
|
||||
}
|
||||
1 * span.setTag(Tags.COMPONENT.key, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND.key, "client")
|
||||
1 * span.setTag(Tags.COMPONENT, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND, "client")
|
||||
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())
|
||||
_ * span.setTag(_, _) // Want to allow other calls from child implementations.
|
||||
0 * _
|
||||
|
|
|
@ -3,7 +3,7 @@ package datadog.trace.agent.decorator
|
|||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.instrumentation.api.AgentSpan
|
||||
import io.opentracing.tag.Tags
|
||||
import datadog.trace.instrumentation.api.Tags
|
||||
|
||||
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
|
||||
|
||||
|
@ -22,9 +22,9 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
|
|||
if (serviceName != null) {
|
||||
1 * span.setTag(DDTags.SERVICE_NAME, serviceName)
|
||||
}
|
||||
1 * span.setTag(Tags.COMPONENT.key, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND.key, "client")
|
||||
1 * span.setTag(Tags.DB_TYPE.key, "test-db")
|
||||
1 * span.setTag(Tags.COMPONENT, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND, "client")
|
||||
1 * span.setTag(Tags.DB_TYPE, "test-db")
|
||||
1 * span.setTag(DDTags.SPAN_TYPE, "test-type")
|
||||
0 * _
|
||||
|
||||
|
@ -43,8 +43,8 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
|
|||
|
||||
then:
|
||||
if (session) {
|
||||
1 * span.setTag(Tags.DB_USER.key, session.user)
|
||||
1 * span.setTag(Tags.DB_INSTANCE.key, session.instance)
|
||||
1 * span.setTag(Tags.DB_USER, session.user)
|
||||
1 * span.setTag(Tags.DB_INSTANCE, session.instance)
|
||||
if (renameService && session.instance) {
|
||||
1 * span.setTag(DDTags.SERVICE_NAME, session.instance)
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
|
|||
decorator.onStatement(span, statement)
|
||||
|
||||
then:
|
||||
1 * span.setTag(Tags.DB_STATEMENT.key, statement)
|
||||
1 * span.setTag(Tags.DB_STATEMENT, statement)
|
||||
0 * _
|
||||
|
||||
where:
|
||||
|
|
|
@ -3,7 +3,7 @@ package datadog.trace.agent.decorator
|
|||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.instrumentation.api.AgentSpan
|
||||
import io.opentracing.tag.Tags
|
||||
import datadog.trace.instrumentation.api.Tags
|
||||
import spock.lang.Shared
|
||||
|
||||
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
|
||||
|
@ -26,10 +26,10 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
|
|||
|
||||
then:
|
||||
if (req) {
|
||||
1 * span.setTag(Tags.HTTP_METHOD.key, req.method)
|
||||
1 * span.setTag(Tags.HTTP_URL.key, "$req.url")
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME.key, req.host)
|
||||
1 * span.setTag(Tags.PEER_PORT.key, req.port)
|
||||
1 * span.setTag(Tags.HTTP_METHOD, req.method)
|
||||
1 * span.setTag(Tags.HTTP_URL, "$req.url")
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME, req.host)
|
||||
1 * span.setTag(Tags.PEER_PORT, req.port)
|
||||
if (renameService) {
|
||||
1 * span.setTag(DDTags.SERVICE_NAME, req.host)
|
||||
}
|
||||
|
@ -55,14 +55,14 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
|
|||
|
||||
then:
|
||||
if (expectedUrl) {
|
||||
1 * span.setTag(Tags.HTTP_URL.key, expectedUrl)
|
||||
1 * span.setTag(Tags.HTTP_URL, expectedUrl)
|
||||
}
|
||||
if (expectedUrl && tagQueryString) {
|
||||
1 * span.setTag(DDTags.HTTP_QUERY, expectedQuery)
|
||||
1 * span.setTag(DDTags.HTTP_FRAGMENT, expectedFragment)
|
||||
}
|
||||
1 * span.setTag(Tags.HTTP_METHOD.key, null)
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME.key, null)
|
||||
1 * span.setTag(Tags.HTTP_METHOD, null)
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME, null)
|
||||
0 * _
|
||||
|
||||
where:
|
||||
|
@ -94,7 +94,7 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
|
|||
|
||||
then:
|
||||
if (status) {
|
||||
1 * span.setTag(Tags.HTTP_STATUS.key, status)
|
||||
1 * span.setTag(Tags.HTTP_STATUS, status)
|
||||
}
|
||||
if (error) {
|
||||
1 * span.setError(true)
|
||||
|
|
|
@ -3,7 +3,7 @@ package datadog.trace.agent.decorator
|
|||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.instrumentation.api.AgentSpan
|
||||
import io.opentracing.tag.Tags
|
||||
import datadog.trace.instrumentation.api.Tags
|
||||
|
||||
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
|
||||
|
||||
|
@ -20,8 +20,8 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
|||
|
||||
then:
|
||||
if (req) {
|
||||
1 * span.setTag(Tags.HTTP_METHOD.key, "test-method")
|
||||
1 * span.setTag(Tags.HTTP_URL.key, url)
|
||||
1 * span.setTag(Tags.HTTP_METHOD, "test-method")
|
||||
1 * span.setTag(Tags.HTTP_URL, url)
|
||||
}
|
||||
0 * _
|
||||
|
||||
|
@ -46,13 +46,13 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
|||
|
||||
then:
|
||||
if (expectedUrl) {
|
||||
1 * span.setTag(Tags.HTTP_URL.key, expectedUrl)
|
||||
1 * span.setTag(Tags.HTTP_URL, expectedUrl)
|
||||
}
|
||||
if (expectedUrl && tagQueryString) {
|
||||
1 * span.setTag(DDTags.HTTP_QUERY, expectedQuery)
|
||||
1 * span.setTag(DDTags.HTTP_FRAGMENT, expectedFragment)
|
||||
}
|
||||
1 * span.setTag(Tags.HTTP_METHOD.key, null)
|
||||
1 * span.setTag(Tags.HTTP_METHOD, null)
|
||||
0 * _
|
||||
|
||||
where:
|
||||
|
@ -83,12 +83,12 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
|||
|
||||
then:
|
||||
if (conn) {
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME.key, "test-host")
|
||||
1 * span.setTag(Tags.PEER_PORT.key, 555)
|
||||
1 * span.setTag(Tags.PEER_HOSTNAME, "test-host")
|
||||
1 * span.setTag(Tags.PEER_PORT, 555)
|
||||
if (ipv4) {
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV4.key, "10.0.0.1")
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV4, "10.0.0.1")
|
||||
} else if (ipv4 != null) {
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV6.key, "3ffe:1900:4545:3:200:f8ff:fe21:67cf")
|
||||
1 * span.setTag(Tags.PEER_HOST_IPV6, "3ffe:1900:4545:3:200:f8ff:fe21:67cf")
|
||||
}
|
||||
}
|
||||
0 * _
|
||||
|
@ -112,7 +112,7 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
|||
|
||||
then:
|
||||
if (status) {
|
||||
1 * span.setTag(Tags.HTTP_STATUS.key, status)
|
||||
1 * span.setTag(Tags.HTTP_STATUS, status)
|
||||
}
|
||||
if (error) {
|
||||
1 * span.setError(true)
|
||||
|
|
|
@ -3,7 +3,7 @@ package datadog.trace.agent.decorator
|
|||
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.instrumentation.api.AgentSpan
|
||||
import io.opentracing.tag.Tags
|
||||
import datadog.trace.instrumentation.api.Tags
|
||||
|
||||
class ServerDecoratorTest extends BaseDecoratorTest {
|
||||
|
||||
|
@ -15,8 +15,8 @@ class ServerDecoratorTest extends BaseDecoratorTest {
|
|||
decorator.afterStart(span)
|
||||
|
||||
then:
|
||||
1 * span.setTag(Tags.COMPONENT.key, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND.key, "server")
|
||||
1 * span.setTag(Tags.COMPONENT, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND, "server")
|
||||
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())
|
||||
0 * _
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
dependencies {
|
||||
compile project(':dd-trace-api')
|
||||
compile project(':dd-java-agent:agent-bootstrap')
|
||||
compile project(':dd-java-agent:benchmark-integration')
|
||||
compile deps.opentracing
|
||||
|
||||
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.4.1.v20170120'
|
||||
compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '9.4.1.v20170120'
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package datadog.perftest;
|
||||
|
||||
import static datadog.trace.instrumentation.api.AgentTracer.activeSpan;
|
||||
|
||||
import datadog.trace.api.Trace;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Worker {
|
||||
|
@ -10,7 +11,7 @@ public class Worker {
|
|||
@Trace
|
||||
/** Simulate work for the give number of milliseconds. */
|
||||
public static void doWork(final long workTimeMS) {
|
||||
final Span span = GlobalTracer.get().activeSpan();
|
||||
final AgentSpan span = activeSpan();
|
||||
if (span != null) {
|
||||
span.setTag("work-time", workTimeMS);
|
||||
span.setTag("info", "interesting stuff");
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package datadog.perftest.jetty;
|
||||
|
||||
import static datadog.trace.instrumentation.api.AgentTracer.activeSpan;
|
||||
|
||||
import datadog.perftest.Worker;
|
||||
import datadog.trace.api.Trace;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
|
@ -58,7 +59,7 @@ public class JettyPerftest {
|
|||
|
||||
@Trace
|
||||
private void scheduleWork(final long workTimeMS) {
|
||||
final Span span = GlobalTracer.get().activeSpan();
|
||||
final AgentSpan span = activeSpan();
|
||||
if (span != null) {
|
||||
span.setTag("work-time", workTimeMS);
|
||||
span.setTag("info", "interesting stuff");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package controllers
|
||||
|
||||
import datadog.trace.instrumentation.api.AgentTracer.activeSpan
|
||||
|
||||
import datadog.trace.api.Trace
|
||||
import io.opentracing.Span
|
||||
import io.opentracing.util.GlobalTracer
|
||||
import javax.inject.Inject
|
||||
|
||||
import play.api.mvc._
|
||||
|
@ -30,7 +30,7 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
|
|||
|
||||
@Trace
|
||||
private def scheduleWork(workTimeMS: Long) {
|
||||
val span = GlobalTracer.get().activeSpan
|
||||
val span = activeSpan
|
||||
if (span != null) {
|
||||
span.setTag("work-time", workTimeMS)
|
||||
span.setTag("info", "interesting stuff")
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package controllers
|
||||
|
||||
import datadog.trace.instrumentation.api.AgentTracer.activeSpan
|
||||
|
||||
import datadog.trace.api.Trace
|
||||
import io.opentracing.Span
|
||||
import io.opentracing.util.GlobalTracer
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object Worker {
|
||||
@Trace
|
||||
def doWork(workTimeMS: Long) = {
|
||||
val span = GlobalTracer.get.activeSpan
|
||||
val span = activeSpan
|
||||
if (span != null) {
|
||||
span.setTag("work-time", workTimeMS)
|
||||
span.setTag("info", "interesting stuff")
|
||||
|
|
|
@ -21,8 +21,8 @@ dependencies {
|
|||
play "com.typesafe.play:filters-helpers_$scalaVersion:$playVersion"
|
||||
|
||||
play project(':dd-trace-api')
|
||||
play project(':dd-java-agent:agent-bootstrap')
|
||||
play project(':dd-java-agent:benchmark-integration')
|
||||
play deps.opentracing
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
@ -6,6 +6,7 @@ apply from: "${rootDir}/gradle/java.gradle"
|
|||
|
||||
dependencies {
|
||||
jmh project(':dd-trace-api')
|
||||
jmh project(':dd-trace-ot')
|
||||
jmh group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.7.6'
|
||||
|
||||
// Add a bunch of dependencies so instrumentation is not disabled.
|
||||
|
|
|
@ -2,10 +2,10 @@ package datadog.benchmark;
|
|||
|
||||
import datadog.benchmark.classes.TracedClass;
|
||||
import datadog.benchmark.classes.UntracedClass;
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.trace.api.GlobalTracer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Paths;
|
||||
import net.bytebuddy.agent.ByteBuddyAgent;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
|
@ -37,15 +37,7 @@ public class ClassRetransformingBenchmark {
|
|||
|
||||
@TearDown
|
||||
public void stopAgent() {
|
||||
try {
|
||||
final Class<?> gt = Class.forName("io.opentracing.util.GlobalTracer");
|
||||
final Field tracerField = gt.getDeclaredField("tracer");
|
||||
tracerField.setAccessible(true);
|
||||
final Object tracer = tracerField.get(null);
|
||||
final Method close = tracer.getClass().getMethod("close");
|
||||
close.invoke(tracer);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
((DDTracer) GlobalTracer.get()).close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,6 @@ dependencies {
|
|||
testCompile project(':dd-trace-ot')
|
||||
testCompile project(':utils:gc-utils')
|
||||
|
||||
testCompile deps.opentracingMock
|
||||
testCompile deps.testLogging
|
||||
testCompile deps.guava
|
||||
|
||||
|
|
|
@ -74,7 +74,6 @@ dependencies {
|
|||
|
||||
compile project(':dd-trace-api')
|
||||
compile project(':dd-java-agent:agent-tooling')
|
||||
compile deps.opentracing
|
||||
compile deps.autoservice
|
||||
annotationProcessor deps.autoservice
|
||||
|
||||
|
|
|
@ -121,7 +121,6 @@ public class GoogleHttpClientInstrumentation extends Instrumenter.Default {
|
|||
// for a failed request. Thus, check the response code
|
||||
if (response != null && !response.isSuccessStatusCode()) {
|
||||
span.setError(true);
|
||||
span.setErrorMessage(response.getStatusMessage());
|
||||
}
|
||||
|
||||
DECORATE.beforeFinish(span);
|
||||
|
|
|
@ -10,7 +10,7 @@ class OSGIClassloadingTest extends AgentTestRunner {
|
|||
@Rule
|
||||
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties()
|
||||
|
||||
static final String BOOT_DELEGATION_ADDITION = "datadog.slf4j.*,datadog.slf4j,datadog.trace.api.*,datadog.trace.api,datadog.trace.bootstrap.*,datadog.trace.bootstrap,datadog.trace.context.*,datadog.trace.context,datadog.trace.instrumentation.api.*,datadog.trace.instrumentation.api,io.opentracing.*,io.opentracing"
|
||||
static final String BOOT_DELEGATION_ADDITION = "datadog.slf4j.*,datadog.slf4j,datadog.trace.api.*,datadog.trace.api,datadog.trace.bootstrap.*,datadog.trace.bootstrap,datadog.trace.context.*,datadog.trace.context,datadog.trace.instrumentation.api.*,datadog.trace.instrumentation.api"
|
||||
|
||||
def "delegation property set on module load"() {
|
||||
when:
|
||||
|
|
|
@ -3,6 +3,7 @@ apply from: "${rootDir}/gradle/java.gradle"
|
|||
dependencies {
|
||||
compile project(':dd-trace-api')
|
||||
compile project(':dd-trace-ot')
|
||||
compile project(':dd-java-agent:agent-bootstrap')
|
||||
|
||||
compile 'info.picocli:picocli:4.0.4'
|
||||
compile deps.guava
|
||||
|
@ -13,6 +14,6 @@ task launch(type: JavaExec) {
|
|||
main = 'datadog.loadgenerator.LoadGenerator'
|
||||
jvmArgs = ["-javaagent:${project(':dd-java-agent').shadowJar.archivePath}", "-Ddd.service.name=loadtest"]
|
||||
systemProperties System.properties
|
||||
|
||||
|
||||
dependsOn project(':dd-java-agent').shadowJar
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package datadog.loadgenerator;
|
||||
|
||||
import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
|
||||
import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
|
||||
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import datadog.trace.instrumentation.api.AgentScope;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
@ -90,19 +91,18 @@ public class LoadGenerator implements Callable<Integer> {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
final Tracer tracer = GlobalTracer.get();
|
||||
|
||||
while (true) {
|
||||
rateLimiter.acquire();
|
||||
final Span parent = tracer.buildSpan("parentSpan").start();
|
||||
final AgentSpan parent = startSpan("parentSpan");
|
||||
|
||||
try (final Scope scope = tracer.activateSpan(parent)) {
|
||||
try (final AgentScope scope = activateSpan(parent, true)) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
final Span widthSpan = tracer.buildSpan("span-" + i).start();
|
||||
try (final Scope widthScope = tracer.activateSpan(widthSpan)) {
|
||||
final AgentSpan widthSpan = startSpan("span-" + i);
|
||||
try (final AgentScope widthScope = activateSpan(widthSpan, true)) {
|
||||
for (int j = 0; j < depth - 2; j++) {
|
||||
final Span depthSpan = tracer.buildSpan("span-" + i + "-" + j).start();
|
||||
try (final Scope depthScope = tracer.activateSpan(depthSpan)) {
|
||||
final AgentSpan depthSpan = startSpan("span-" + i + "-" + j);
|
||||
try (final AgentScope depthScope = activateSpan(depthSpan, true)) {
|
||||
// do nothing. Maybe sleep? but that will mean we need more threads to keep the
|
||||
// effective rate
|
||||
} finally {
|
||||
|
|
|
@ -3,12 +3,8 @@ package datadog.trace.agent.integration.classloading
|
|||
import com.google.common.collect.MapMaker
|
||||
import com.google.common.reflect.ClassPath
|
||||
import datadog.trace.agent.test.IntegrationTestUtils
|
||||
import io.opentracing.util.GlobalTracer
|
||||
import spock.lang.Ignore
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class ShadowPackageRenamingTest extends Specification {
|
||||
def "agent dependencies renamed"() {
|
||||
setup:
|
||||
|
@ -34,20 +30,6 @@ class ShadowPackageRenamingTest extends Specification {
|
|||
agentSource.getFile() != userGuava.getFile()
|
||||
}
|
||||
|
||||
@Ignore("OT 0.32 removed this field. Need to find another option.")
|
||||
def "java getLogger rewritten to safe logger"() {
|
||||
setup:
|
||||
Field logField = GlobalTracer.getDeclaredField("LOGGER")
|
||||
logField.setAccessible(true)
|
||||
Object logger = logField.get(null)
|
||||
|
||||
expect:
|
||||
!logger.getClass().getName().startsWith("java.util.logging")
|
||||
|
||||
cleanup:
|
||||
logField?.setAccessible(false)
|
||||
}
|
||||
|
||||
def "agent classes not visible"() {
|
||||
when:
|
||||
ClassLoader.getSystemClassLoader().loadClass("datadog.trace.agent.tooling.AgentInstaller")
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package datadog.trace.agent.test;
|
||||
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -129,30 +127,6 @@ public class IntegrationTestUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void registerOrReplaceGlobalTracer(final Tracer tracer) {
|
||||
try {
|
||||
GlobalTracer.register(tracer);
|
||||
} catch (final Exception e) {
|
||||
// Force it anyway using reflection
|
||||
Field field = null;
|
||||
try {
|
||||
field = GlobalTracer.class.getDeclaredField("tracer");
|
||||
field.setAccessible(true);
|
||||
field.set(null, tracer);
|
||||
} catch (final Exception e2) {
|
||||
throw new IllegalStateException(e2);
|
||||
} finally {
|
||||
if (null != field) {
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!GlobalTracer.isRegistered()) {
|
||||
throw new RuntimeException("Unable to register the global tracer.");
|
||||
}
|
||||
}
|
||||
|
||||
/** com.foo.Bar -> com/foo/Bar.class */
|
||||
public static String getResourceName(final String className) {
|
||||
return className.replace('.', '/') + ".class";
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.google.common.collect.Sets;
|
|||
import datadog.opentracing.DDSpan;
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.opentracing.PendingTrace;
|
||||
import datadog.opentracing.Span;
|
||||
import datadog.trace.agent.test.asserts.ListWriterAssert;
|
||||
import datadog.trace.agent.test.utils.GlobalTracerUtils;
|
||||
import datadog.trace.agent.tooling.AgentInstaller;
|
||||
|
@ -18,8 +19,6 @@ import groovy.lang.Closure;
|
|||
import groovy.lang.DelegatesTo;
|
||||
import groovy.transform.stc.ClosureParams;
|
||||
import groovy.transform.stc.SimpleType;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.List;
|
||||
|
@ -69,10 +68,7 @@ public abstract class AgentTestRunner extends DDSpecification {
|
|||
*/
|
||||
public static final ListWriter TEST_WRITER;
|
||||
|
||||
// having a reference to io.opentracing.Tracer in test field
|
||||
// loads opentracing before bootstrap classpath is setup
|
||||
// so we declare tracer as an object and cast when needed.
|
||||
protected static final Object TEST_TRACER;
|
||||
protected static final DDTracer TEST_TRACER;
|
||||
|
||||
protected static final Set<String> TRANSFORMED_CLASSES = Sets.newConcurrentHashSet();
|
||||
private static final AtomicInteger INSTRUMENTATION_ERROR_COUNT = new AtomicInteger();
|
||||
|
@ -96,12 +92,12 @@ public abstract class AgentTestRunner extends DDSpecification {
|
|||
}
|
||||
};
|
||||
TEST_TRACER = new DDTracer(TEST_WRITER);
|
||||
GlobalTracerUtils.registerOrReplaceGlobalTracer((Tracer) TEST_TRACER);
|
||||
GlobalTracer.registerIfAbsent((datadog.trace.api.Tracer) TEST_TRACER);
|
||||
GlobalTracerUtils.registerOrReplaceGlobalTracer(TEST_TRACER);
|
||||
GlobalTracer.registerIfAbsent(TEST_TRACER);
|
||||
}
|
||||
|
||||
protected static Tracer getTestTracer() {
|
||||
return (Tracer) TEST_TRACER;
|
||||
protected static DDTracer getTestTracer() {
|
||||
return TEST_TRACER;
|
||||
}
|
||||
|
||||
protected static Writer getTestWriter() {
|
||||
|
@ -204,7 +200,7 @@ public abstract class AgentTestRunner extends DDSpecification {
|
|||
|
||||
@SneakyThrows
|
||||
public static void blockUntilChildSpansFinished(final int numberOfSpans) {
|
||||
final Span span = io.opentracing.util.GlobalTracer.get().activeSpan();
|
||||
final Span span = ((DDTracer) GlobalTracer.get()).activeSpan();
|
||||
final long deadline = System.currentTimeMillis() + TIMEOUT_MILLIS;
|
||||
if (span instanceof DDSpan) {
|
||||
final PendingTrace pendingTrace = ((DDSpan) span).context().getTrace();
|
||||
|
|
|
@ -35,8 +35,7 @@ public class SpockRunner extends Sputnik {
|
|||
"datadog.trace.api",
|
||||
"datadog.trace.bootstrap",
|
||||
"datadog.trace.context",
|
||||
"datadog.trace.instrumentation.api",
|
||||
"io.opentracing",
|
||||
"datadog.trace.instrumentation.api"
|
||||
};
|
||||
|
||||
private static final String[] TEST_BOOTSTRAP_PREFIXES;
|
||||
|
@ -44,7 +43,6 @@ public class SpockRunner extends Sputnik {
|
|||
static {
|
||||
ByteBuddyAgent.install();
|
||||
final String[] testBS = {
|
||||
"io.opentracing",
|
||||
"org.slf4j",
|
||||
"ch.qos.logback",
|
||||
// Tomcat's servlet classes must be on boostrap
|
||||
|
|
|
@ -1,50 +1,11 @@
|
|||
package datadog.trace.agent.test.utils;
|
||||
|
||||
import datadog.trace.agent.tooling.OpenTracing32;
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.trace.agent.tooling.AgentTracerImpl;
|
||||
import datadog.trace.instrumentation.api.AgentTracer;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class GlobalTracerUtils {
|
||||
public static void registerOrReplaceGlobalTracer(final Tracer tracer) {
|
||||
try {
|
||||
GlobalTracer.register(tracer);
|
||||
AgentTracer.registerIfAbsent(new OpenTracing32());
|
||||
} catch (final Exception e) {
|
||||
// Force it anyway using reflection
|
||||
Field field = null;
|
||||
try {
|
||||
field = GlobalTracer.class.getDeclaredField("tracer");
|
||||
field.setAccessible(true);
|
||||
field.set(null, tracer);
|
||||
} catch (final Exception e2) {
|
||||
throw new IllegalStateException(e2);
|
||||
} finally {
|
||||
if (null != field) {
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!GlobalTracer.isRegistered()) {
|
||||
throw new RuntimeException("Unable to register the global tracer.");
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the tracer implementation out of the GlobalTracer */
|
||||
public static Tracer getUnderlyingGlobalTracer() {
|
||||
Field field = null;
|
||||
try {
|
||||
field = GlobalTracer.class.getDeclaredField("tracer");
|
||||
field.setAccessible(true);
|
||||
return (Tracer) field.get(GlobalTracer.get());
|
||||
} catch (final Exception e2) {
|
||||
throw new IllegalStateException(e2);
|
||||
} finally {
|
||||
if (null != field) {
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
public static void registerOrReplaceGlobalTracer(final DDTracer tracer) {
|
||||
AgentTracer.registerIfAbsent(new AgentTracerImpl(tracer));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,7 @@ import datadog.trace.agent.test.AgentTestRunner
|
|||
import datadog.trace.agent.test.SpockRunner
|
||||
import datadog.trace.agent.test.utils.ClasspathUtils
|
||||
import datadog.trace.agent.test.utils.ConfigUtils
|
||||
import datadog.trace.agent.test.utils.GlobalTracerUtils
|
||||
import datadog.trace.agent.tooling.Constants
|
||||
import io.opentracing.Span
|
||||
import io.opentracing.Tracer
|
||||
import spock.lang.Shared
|
||||
|
||||
import java.lang.reflect.Field
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
@ -17,26 +13,16 @@ import static datadog.trace.api.Config.TRACE_CLASSES_EXCLUDE
|
|||
|
||||
class AgentTestRunnerTest extends AgentTestRunner {
|
||||
private static final ClassLoader BOOTSTRAP_CLASSLOADER = null
|
||||
private static final ClassLoader OT_LOADER
|
||||
private static final boolean AGENT_INSTALLED_IN_CLINIT
|
||||
|
||||
@Shared
|
||||
private Class sharedSpanClass
|
||||
|
||||
static {
|
||||
ConfigUtils.updateConfig {
|
||||
System.setProperty("dd." + TRACE_CLASSES_EXCLUDE, "config.exclude.packagename.*, config.exclude.SomeClass,config.exclude.SomeClass\$NestedClass")
|
||||
}
|
||||
|
||||
// when test class initializes, opentracing should be set up, but not the agent.
|
||||
OT_LOADER = io.opentracing.Tracer.getClassLoader()
|
||||
AGENT_INSTALLED_IN_CLINIT = getAgentTransformer() != null
|
||||
}
|
||||
|
||||
def setupSpec() {
|
||||
sharedSpanClass = Span
|
||||
}
|
||||
|
||||
def "spock runner bootstrap prefixes correct for test setup"() {
|
||||
expect:
|
||||
SpockRunner.BOOTSTRAP_PACKAGE_PREFIXES_COPY == Constants.BOOTSTRAP_PACKAGE_PREFIXES
|
||||
|
@ -58,13 +44,9 @@ class AgentTestRunnerTest extends AgentTestRunner {
|
|||
}
|
||||
|
||||
expect:
|
||||
// shared OT classes should cause no trouble
|
||||
sharedSpanClass.getClassLoader() == BOOTSTRAP_CLASSLOADER
|
||||
Tracer.getClassLoader() == BOOTSTRAP_CLASSLOADER
|
||||
!AGENT_INSTALLED_IN_CLINIT
|
||||
getTestTracer() == GlobalTracerUtils.getUnderlyingGlobalTracer()
|
||||
getTestTracer() == datadog.trace.api.GlobalTracer.get()
|
||||
getAgentTransformer() != null
|
||||
GlobalTracerUtils.getUnderlyingGlobalTracer() == datadog.trace.api.GlobalTracer.get()
|
||||
bootstrapClassesIncorrectlyLoaded == []
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import datadog.opentracing.DDSpan
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.scopemanager.DDScope
|
||||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.api.CorrelationIdentifier
|
||||
import io.opentracing.Scope
|
||||
import io.opentracing.util.GlobalTracer
|
||||
import datadog.trace.api.GlobalTracer
|
||||
|
||||
class TraceCorrelationTest extends AgentTestRunner {
|
||||
|
||||
def "access trace correlation only under trace"() {
|
||||
when:
|
||||
Scope scope = GlobalTracer.get().buildSpan("myspan").startActive(true)
|
||||
DDScope scope = ((DDTracer) GlobalTracer.get()).buildSpan("myspan").startActive(true)
|
||||
DDSpan span = (DDSpan) scope.span()
|
||||
|
||||
then:
|
||||
|
|
|
@ -16,7 +16,6 @@ dependencies {
|
|||
compile deps.bytebuddy
|
||||
compile deps.bytebuddyagent
|
||||
compile deps.slf4j
|
||||
compile deps.opentracing
|
||||
compile deps.spock
|
||||
compile deps.testLogging
|
||||
compile deps.guava
|
||||
|
|
|
@ -50,7 +50,6 @@ dependencies {
|
|||
play "com.typesafe.play:filters-helpers_$scalaVersion:$playVersion"
|
||||
|
||||
play project(':dd-trace-api')
|
||||
play deps.opentracing
|
||||
|
||||
testCompile project(':dd-smoke-tests')
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ excludedClassesCoverage += [
|
|||
'datadog.trace.api.GlobalTracer*',
|
||||
'datadog.trace.api.CorrelationIdentifier',
|
||||
'datadog.trace.api.DDTags',
|
||||
'datadog.trace.api.LogFields',
|
||||
'datadog.trace.api.Config'
|
||||
]
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ public class Config {
|
|||
public static final String TRACE_ENABLED = "trace.enabled";
|
||||
public static final String INTEGRATIONS_ENABLED = "integrations.enabled";
|
||||
public static final String WRITER_TYPE = "writer.type";
|
||||
public static final String TRACE_RESOLVER_ENABLED = "trace.resolver.enabled";
|
||||
public static final String TRACE_ANNOTATIONS = "trace.annotations";
|
||||
public static final String TRACE_EXECUTORS_ALL = "trace.executors.all";
|
||||
public static final String TRACE_EXECUTORS = "trace.executors";
|
||||
|
@ -65,7 +64,6 @@ public class Config {
|
|||
|
||||
private static final boolean DEFAULT_RUNTIME_CONTEXT_FIELD_INJECTION = true;
|
||||
|
||||
private static final boolean DEFAULT_TRACE_RESOLVER_ENABLED = true;
|
||||
private static final Set<Integer> DEFAULT_HTTP_SERVER_ERROR_STATUSES =
|
||||
parseIntegerRangeSet("500-599", "default");
|
||||
private static final Set<Integer> DEFAULT_HTTP_CLIENT_ERROR_STATUSES =
|
||||
|
@ -88,7 +86,6 @@ public class Config {
|
|||
@Getter private final boolean traceEnabled;
|
||||
@Getter private final boolean integrationsEnabled;
|
||||
@Getter private final String writerType;
|
||||
@Getter private final boolean traceResolverEnabled;
|
||||
@Getter private final List<String> excludedClasses;
|
||||
@Getter private final Set<Integer> httpServerErrorStatuses;
|
||||
@Getter private final Set<Integer> httpClientErrorStatuses;
|
||||
|
@ -120,8 +117,6 @@ public class Config {
|
|||
integrationsEnabled =
|
||||
getBooleanSettingFromEnvironment(INTEGRATIONS_ENABLED, DEFAULT_INTEGRATIONS_ENABLED);
|
||||
writerType = getSettingFromEnvironment(WRITER_TYPE, DEFAULT_WRITER_TYPE);
|
||||
traceResolverEnabled =
|
||||
getBooleanSettingFromEnvironment(TRACE_RESOLVER_ENABLED, DEFAULT_TRACE_RESOLVER_ENABLED);
|
||||
|
||||
excludedClasses = getListSettingFromEnvironment(TRACE_CLASSES_EXCLUDE, null);
|
||||
|
||||
|
@ -178,8 +173,6 @@ public class Config {
|
|||
integrationsEnabled =
|
||||
getPropertyBooleanValue(properties, INTEGRATIONS_ENABLED, parent.integrationsEnabled);
|
||||
writerType = properties.getProperty(WRITER_TYPE, parent.writerType);
|
||||
traceResolverEnabled =
|
||||
getPropertyBooleanValue(properties, TRACE_RESOLVER_ENABLED, parent.traceResolverEnabled);
|
||||
|
||||
excludedClasses =
|
||||
getPropertyListValue(properties, TRACE_CLASSES_EXCLUDE, parent.excludedClasses);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package datadog.trace.api;
|
||||
|
||||
// standard log field names from OpenTracing (see io.opentracing.log.Fields)
|
||||
public class LogFields {
|
||||
|
||||
public static final String ERROR_OBJECT = "error.object";
|
||||
|
||||
public static final String MESSAGE = "message";
|
||||
}
|
|
@ -14,7 +14,6 @@ import static datadog.trace.api.Config.PARTIAL_FLUSH_MIN_SPANS
|
|||
import static datadog.trace.api.Config.PREFIX
|
||||
import static datadog.trace.api.Config.RUNTIME_CONTEXT_FIELD_INJECTION
|
||||
import static datadog.trace.api.Config.TRACE_ENABLED
|
||||
import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED
|
||||
import static datadog.trace.api.Config.WRITER_TYPE
|
||||
|
||||
class ConfigTest extends DDSpecification {
|
||||
|
@ -33,7 +32,6 @@ class ConfigTest extends DDSpecification {
|
|||
then:
|
||||
config.traceEnabled == true
|
||||
config.writerType == "LoggingWriter"
|
||||
config.traceResolverEnabled == true
|
||||
config.httpServerErrorStatuses == (500..599).toSet()
|
||||
config.httpClientErrorStatuses == (400..599).toSet()
|
||||
config.httpClientSplitByDomain == false
|
||||
|
@ -55,7 +53,6 @@ class ConfigTest extends DDSpecification {
|
|||
def prop = new Properties()
|
||||
prop.setProperty(TRACE_ENABLED, "false")
|
||||
prop.setProperty(WRITER_TYPE, "LoggingWriter")
|
||||
prop.setProperty(TRACE_RESOLVER_ENABLED, "false")
|
||||
prop.setProperty(HTTP_SERVER_ERROR_STATUSES, "123-456,457,124-125,122")
|
||||
prop.setProperty(HTTP_CLIENT_ERROR_STATUSES, "111")
|
||||
prop.setProperty(HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
|
||||
|
@ -69,7 +66,6 @@ class ConfigTest extends DDSpecification {
|
|||
then:
|
||||
config.traceEnabled == false
|
||||
config.writerType == "LoggingWriter"
|
||||
config.traceResolverEnabled == false
|
||||
config.httpServerErrorStatuses == (122..457).toSet()
|
||||
config.httpClientErrorStatuses == (111..111).toSet()
|
||||
config.httpClientSplitByDomain == true
|
||||
|
@ -82,7 +78,6 @@ class ConfigTest extends DDSpecification {
|
|||
setup:
|
||||
System.setProperty(PREFIX + TRACE_ENABLED, "false")
|
||||
System.setProperty(PREFIX + WRITER_TYPE, "LoggingWriter")
|
||||
System.setProperty(PREFIX + TRACE_RESOLVER_ENABLED, "false")
|
||||
System.setProperty(PREFIX + HTTP_SERVER_ERROR_STATUSES, "123-456,457,124-125,122")
|
||||
System.setProperty(PREFIX + HTTP_CLIENT_ERROR_STATUSES, "111")
|
||||
System.setProperty(PREFIX + HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
|
||||
|
@ -96,7 +91,6 @@ class ConfigTest extends DDSpecification {
|
|||
then:
|
||||
config.traceEnabled == false
|
||||
config.writerType == "LoggingWriter"
|
||||
config.traceResolverEnabled == false
|
||||
config.httpServerErrorStatuses == (122..457).toSet()
|
||||
config.httpClientErrorStatuses == (111..111).toSet()
|
||||
config.httpClientSplitByDomain == true
|
||||
|
@ -135,7 +129,6 @@ class ConfigTest extends DDSpecification {
|
|||
setup:
|
||||
System.setProperty(PREFIX + TRACE_ENABLED, " ")
|
||||
System.setProperty(PREFIX + WRITER_TYPE, " ")
|
||||
System.setProperty(PREFIX + TRACE_RESOLVER_ENABLED, " ")
|
||||
System.setProperty(PREFIX + HTTP_SERVER_ERROR_STATUSES, "1111")
|
||||
System.setProperty(PREFIX + HTTP_CLIENT_ERROR_STATUSES, "1:1")
|
||||
System.setProperty(PREFIX + HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "invalid")
|
||||
|
@ -147,7 +140,6 @@ class ConfigTest extends DDSpecification {
|
|||
then:
|
||||
config.traceEnabled == true
|
||||
config.writerType == " "
|
||||
config.traceResolverEnabled == true
|
||||
config.httpServerErrorStatuses == (500..599).toSet()
|
||||
config.httpClientErrorStatuses == (400..599).toSet()
|
||||
config.httpClientSplitByDomain == false
|
||||
|
@ -159,7 +151,6 @@ class ConfigTest extends DDSpecification {
|
|||
Properties properties = new Properties()
|
||||
properties.setProperty(TRACE_ENABLED, "false")
|
||||
properties.setProperty(WRITER_TYPE, "LoggingWriter")
|
||||
properties.setProperty(TRACE_RESOLVER_ENABLED, "false")
|
||||
properties.setProperty(HTTP_SERVER_ERROR_STATUSES, "123-456,457,124-125,122")
|
||||
properties.setProperty(HTTP_CLIENT_ERROR_STATUSES, "111")
|
||||
properties.setProperty(HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
|
||||
|
@ -172,7 +163,6 @@ class ConfigTest extends DDSpecification {
|
|||
then:
|
||||
config.traceEnabled == false
|
||||
config.writerType == "LoggingWriter"
|
||||
config.traceResolverEnabled == false
|
||||
config.httpServerErrorStatuses == (122..457).toSet()
|
||||
config.httpClientErrorStatuses == (111..111).toSet()
|
||||
config.httpClientSplitByDomain == true
|
||||
|
|
|
@ -10,24 +10,18 @@ apply from: "${rootDir}/gradle/publish.gradle"
|
|||
minimumBranchCoverage = 0.5
|
||||
minimumInstructionCoverage = 0.5
|
||||
excludedClassesCoverage += [
|
||||
'datadog.opentracing.NoopSpan',
|
||||
'datadog.trace.common.writer.ListWriter',
|
||||
'datadog.trace.common.writer.LoggingWriter'
|
||||
]
|
||||
|
||||
apply plugin: 'org.unbroken-dome.test-sets'
|
||||
|
||||
testSets {
|
||||
ot31CompatabilityTest
|
||||
ot33CompatabilityTest
|
||||
}
|
||||
|
||||
dependencies {
|
||||
annotationProcessor deps.autoservice
|
||||
implementation deps.autoservice
|
||||
|
||||
compile project(':dd-trace-api')
|
||||
compile deps.opentracing
|
||||
compile group: 'io.opentracing.contrib', name: 'opentracing-tracerresolver', version: '0.1.0'
|
||||
|
||||
compile deps.slf4j
|
||||
compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0' // Last version to support Java7
|
||||
|
@ -41,34 +35,8 @@ dependencies {
|
|||
testCompile project(":dd-java-agent:testing")
|
||||
testCompile project(':utils:gc-utils')
|
||||
testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.17.1'
|
||||
|
||||
ot31CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-api', version: '0.31.0'
|
||||
ot31CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-util', version: '0.31.0'
|
||||
ot31CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-noop', version: '0.31.0'
|
||||
|
||||
ot33CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-api', version: '0.33.0'
|
||||
ot33CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-util', version: '0.33.0'
|
||||
ot33CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-noop', version: '0.33.0'
|
||||
}
|
||||
|
||||
[configurations.ot31CompatabilityTestCompile, configurations.ot31CompatabilityTestRuntime].each {
|
||||
it.resolutionStrategy {
|
||||
force group: 'io.opentracing', name: 'opentracing-api', version: '0.31.0'
|
||||
force group: 'io.opentracing', name: 'opentracing-util', version: '0.31.0'
|
||||
force group: 'io.opentracing', name: 'opentracing-noop', version: '0.31.0'
|
||||
}
|
||||
}
|
||||
[configurations.ot33CompatabilityTestCompile, configurations.ot33CompatabilityTestRuntime].each {
|
||||
it.resolutionStrategy {
|
||||
force group: 'io.opentracing', name: 'opentracing-api', version: '0.33.0'
|
||||
force group: 'io.opentracing', name: 'opentracing-util', version: '0.33.0'
|
||||
force group: 'io.opentracing', name: 'opentracing-noop', version: '0.33.0'
|
||||
}
|
||||
}
|
||||
|
||||
test.finalizedBy ot31CompatabilityTest
|
||||
test.finalizedBy ot33CompatabilityTest
|
||||
|
||||
jmh {
|
||||
// include = [".*URLAsResourceNameBenchmark"]
|
||||
// include = ['some regular expression'] // include pattern (regular expression) for benchmarks to be executed
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package datadog.trace;
|
||||
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.opentracing.Span;
|
||||
import datadog.opentracing.scopemanager.DDScope;
|
||||
import datadog.trace.common.writer.ListWriter;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
|
||||
|
@ -13,9 +13,8 @@ public class DDTraceBenchmark {
|
|||
@State(org.openjdk.jmh.annotations.Scope.Thread)
|
||||
public static class TraceState {
|
||||
public ListWriter traceCollector = new ListWriter();
|
||||
public Tracer tracer = new DDTracer(traceCollector);
|
||||
// TODO: this will need to be fixed if we want backwards compatibility for older versions...
|
||||
public io.opentracing.Scope scope = tracer.buildSpan(SPAN_NAME).startActive(true);
|
||||
public DDTracer tracer = new DDTracer(traceCollector);
|
||||
public DDScope scope = tracer.buildSpan(SPAN_NAME).startActive(true);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
|
@ -42,7 +41,7 @@ public class DDTraceBenchmark {
|
|||
|
||||
@Benchmark
|
||||
public Object testFullActiveSpan(final TraceState state) {
|
||||
final io.opentracing.Scope scope = state.tracer.buildSpan(SPAN_NAME).startActive(true);
|
||||
final DDScope scope = state.tracer.buildSpan(SPAN_NAME).startActive(true);
|
||||
scope.close();
|
||||
return scope;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package datadog.opentracing;
|
||||
|
||||
import static io.opentracing.log.Fields.ERROR_OBJECT;
|
||||
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.common.util.Clock;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.tag.Tag;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -95,7 +91,6 @@ public class DDSpan implements Span {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void finish(final long stoptimeMicros) {
|
||||
finishAndAddToTrace(TimeUnit.MICROSECONDS.toNanos(stoptimeMicros - startTimeMicro));
|
||||
}
|
||||
|
@ -136,132 +131,37 @@ public class DDSpan implements Span {
|
|||
setTag(DDTags.ERROR_STACK, errorString.toString());
|
||||
}
|
||||
|
||||
private boolean extractError(final Map<String, ?> map) {
|
||||
if (map.get(ERROR_OBJECT) instanceof Throwable) {
|
||||
final Throwable error = (Throwable) map.get(ERROR_OBJECT);
|
||||
setErrorMeta(error);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#setTag(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan setTag(final String tag, final String value) {
|
||||
context().setTag(tag, (Object) value);
|
||||
context().setTag(tag, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#setTag(java.lang.String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan setTag(final String tag, final boolean value) {
|
||||
context().setTag(tag, (Object) value);
|
||||
context().setTag(tag, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#setTag(java.lang.String, java.lang.Number)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan setTag(final String tag, final Number value) {
|
||||
context().setTag(tag, (Object) value);
|
||||
context().setTag(tag, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Span setTag(final Tag<T> tag, final T value) {
|
||||
context().setTag(tag.getKey(), value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#context()
|
||||
*/
|
||||
@Override
|
||||
public final DDSpanContext context() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#getBaggageItem(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final String getBaggageItem(final String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#setBaggageItem(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan setBaggageItem(final String key, final String value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#setOperationName(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan setOperationName(final String operationName) {
|
||||
context().setOperationName(operationName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#log(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan log(final Map<String, ?> map) {
|
||||
if (!extractError(map)) {
|
||||
log.debug("`log` method is not implemented. Doing nothing");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#log(long, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan log(final long l, final Map<String, ?> map) {
|
||||
if (!extractError(map)) {
|
||||
log.debug("`log` method is not implemented. Doing nothing");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#log(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan log(final String s) {
|
||||
log.debug("`log` method is not implemented. Provided log: {}", s);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.BaseSpan#log(long, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan log(final long l, final String s) {
|
||||
log.debug("`log` method is not implemented. Provided log: {}", s);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/**
|
||||
* Span metrics.
|
||||
*
|
||||
* @return metrics for this span
|
||||
*/
|
||||
public Map<String, Number> getMetrics() {
|
||||
return context.getMetrics();
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTimeNano > 0 ? startTimeNano : TimeUnit.MICROSECONDS.toNanos(startTimeMicro);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
* associated Span instance
|
||||
*/
|
||||
@Slf4j
|
||||
public class DDSpanContext implements io.opentracing.SpanContext {
|
||||
public class DDSpanContext implements SpanContext {
|
||||
|
||||
private static final Map<String, Number> EMPTY_METRICS = Collections.emptyMap();
|
||||
|
||||
|
@ -76,11 +76,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
return traceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toTraceId() {
|
||||
return traceId.toString();
|
||||
}
|
||||
|
||||
public BigInteger getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
@ -89,11 +84,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
return spanId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSpanId() {
|
||||
return spanId.toString();
|
||||
}
|
||||
|
||||
public String getOperationName() {
|
||||
return operationName;
|
||||
}
|
||||
|
@ -110,22 +100,10 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
this.errorFlag = errorFlag;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see io.opentracing.SpanContext#baggageItems()
|
||||
*/
|
||||
@Override
|
||||
public Iterable<Map.Entry<String, String>> baggageItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public PendingTrace getTrace() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
public DDTracer getTracer() {
|
||||
return tracer;
|
||||
}
|
||||
|
||||
public Map<String, Number> getMetrics() {
|
||||
final Map<String, Number> metrics = this.metrics.get();
|
||||
return metrics == null ? EMPTY_METRICS : metrics;
|
||||
|
|
|
@ -2,20 +2,13 @@ package datadog.opentracing;
|
|||
|
||||
import datadog.opentracing.propagation.ExtractedContext;
|
||||
import datadog.opentracing.propagation.HttpCodec;
|
||||
import datadog.opentracing.propagation.TextMapExtract;
|
||||
import datadog.opentracing.propagation.TextMapInject;
|
||||
import datadog.opentracing.scopemanager.ContextualScopeManager;
|
||||
import datadog.opentracing.scopemanager.ScopeContext;
|
||||
import datadog.opentracing.scopemanager.DDScope;
|
||||
import datadog.trace.api.Config;
|
||||
import datadog.trace.common.writer.Writer;
|
||||
import datadog.trace.context.ScopeListener;
|
||||
import io.opentracing.References;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.ScopeManager;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.propagation.Format;
|
||||
import io.opentracing.propagation.TextMapExtract;
|
||||
import io.opentracing.propagation.TextMapInject;
|
||||
import io.opentracing.tag.Tag;
|
||||
import java.io.Closeable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.math.BigInteger;
|
||||
|
@ -23,14 +16,13 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** DDTracer makes it easy to send traces and span to DD using the OpenTracing API. */
|
||||
@Slf4j
|
||||
public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace.api.Tracer {
|
||||
public class DDTracer implements Closeable, datadog.trace.api.Tracer {
|
||||
// UINT64 max value
|
||||
public static final BigInteger TRACE_ID_MAX =
|
||||
BigInteger.valueOf(2).pow(64).subtract(BigInteger.ONE);
|
||||
|
@ -58,10 +50,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
this(Config.get());
|
||||
}
|
||||
|
||||
public DDTracer(final Properties config) {
|
||||
this(Config.get(config));
|
||||
}
|
||||
|
||||
private DDTracer(final Config config) {
|
||||
this(Writer.Builder.forConfig(config), config.getPartialFlushMinSpans());
|
||||
log.debug("Using config: {}", config);
|
||||
|
@ -109,48 +97,24 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addScopeContext(final ScopeContext context) {
|
||||
scopeManager.addScopeContext(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextualScopeManager scopeManager() {
|
||||
return scopeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span activeSpan() {
|
||||
return scopeManager.activeSpan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scope activateSpan(final Span span) {
|
||||
return scopeManager.activate(span);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder buildSpan(final String operationName) {
|
||||
return new DDSpanBuilder(operationName, scopeManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void inject(final SpanContext spanContext, final Format<T> format, final T carrier) {
|
||||
if (carrier instanceof TextMapInject) {
|
||||
injector.inject((DDSpanContext) spanContext, (TextMapInject) carrier);
|
||||
} else {
|
||||
log.debug("Unsupported format for propagation - {}", format.getClass().getName());
|
||||
}
|
||||
public void inject(final SpanContext spanContext, final TextMapInject carrier) {
|
||||
injector.inject((DDSpanContext) spanContext, carrier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> SpanContext extract(final Format<T> format, final T carrier) {
|
||||
if (carrier instanceof TextMapExtract) {
|
||||
return extractor.extract((TextMapExtract) carrier);
|
||||
} else {
|
||||
log.debug("Unsupported format for propagation - {}", format.getClass().getName());
|
||||
return null;
|
||||
}
|
||||
public SpanContext extract(final TextMapExtract carrier) {
|
||||
return extractor.extract(carrier);
|
||||
}
|
||||
|
||||
/** @param trace a list of the spans related to the same trace */
|
||||
|
@ -207,8 +171,8 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
}
|
||||
|
||||
/** Spans are built using this builder */
|
||||
public class DDSpanBuilder implements SpanBuilder {
|
||||
private final ScopeManager scopeManager;
|
||||
public class DDSpanBuilder {
|
||||
private final ContextualScopeManager scopeManager;
|
||||
|
||||
/** Each span must have an operationName according to the opentracing specification */
|
||||
private final String operationName;
|
||||
|
@ -220,13 +184,12 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
private boolean errorFlag;
|
||||
private boolean ignoreScope = false;
|
||||
|
||||
public DDSpanBuilder(final String operationName, final ScopeManager scopeManager) {
|
||||
public DDSpanBuilder(final String operationName, final ContextualScopeManager scopeManager) {
|
||||
this.operationName = operationName;
|
||||
this.scopeManager = scopeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpanBuilder ignoreActiveSpan() {
|
||||
public DDSpanBuilder ignoreActiveSpan() {
|
||||
ignoreScope = true;
|
||||
return this;
|
||||
}
|
||||
|
@ -235,48 +198,32 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
return new DDSpan(timestampMicro, buildSpanContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scope startActive(final boolean finishSpanOnClose) {
|
||||
public DDScope startActive(final boolean finishSpanOnClose) {
|
||||
final DDSpan span = startSpan();
|
||||
final Scope scope = scopeManager.activate(span, finishSpanOnClose);
|
||||
final DDScope scope = scopeManager.activate(span, finishSpanOnClose);
|
||||
log.debug("Starting a new active span: {}", span);
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public DDSpan startManual() {
|
||||
return start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpan start() {
|
||||
final DDSpan span = startSpan();
|
||||
log.debug("Starting a new span: {}", span);
|
||||
return span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder withTag(final String tag, final Number number) {
|
||||
return withTag(tag, (Object) number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder withTag(final String tag, final String string) {
|
||||
return withTag(tag, (Object) string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder withTag(final String tag, final boolean bool) {
|
||||
return withTag(tag, (Object) bool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> SpanBuilder withTag(final Tag<T> tag, final T value) {
|
||||
return withTag(tag.getKey(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder withStartTimestamp(final long timestampMicroseconds) {
|
||||
timestampMicro = timestampMicroseconds;
|
||||
return this;
|
||||
|
@ -287,37 +234,15 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder asChildOf(final Span span) {
|
||||
return asChildOf(span == null ? null : span.context());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder asChildOf(final SpanContext spanContext) {
|
||||
parent = spanContext;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDSpanBuilder addReference(final String referenceType, final SpanContext spanContext) {
|
||||
if (spanContext == null) {
|
||||
return this;
|
||||
}
|
||||
if (!(spanContext instanceof ExtractedContext) && !(spanContext instanceof DDSpanContext)) {
|
||||
log.debug(
|
||||
"Expected to have a DDSpanContext or ExtractedContext but got "
|
||||
+ spanContext.getClass().getName());
|
||||
return this;
|
||||
}
|
||||
if (References.CHILD_OF.equals(referenceType)
|
||||
|| References.FOLLOWS_FROM.equals(referenceType)) {
|
||||
return asChildOf(spanContext);
|
||||
} else {
|
||||
log.debug("Only support reference type of CHILD_OF and FOLLOWS_FROM");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// Private methods
|
||||
private DDSpanBuilder withTag(final String tag, final Object value) {
|
||||
if (value == null || (value instanceof String && ((String) value).isEmpty())) {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package datadog.opentracing;
|
||||
|
||||
public class NoopSpan implements Span {
|
||||
public static final NoopSpan INSTANCE = new NoopSpan();
|
||||
|
||||
@Override
|
||||
public SpanContext context() {
|
||||
return NoopSpanContext.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
|
||||
@Override
|
||||
public NoopSpan setTag(final String key, final String value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoopSpan setTag(final String key, final boolean value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoopSpan setTag(final String key, final Number value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoopSpan setOperationName(final String operationName) {
|
||||
return this;
|
||||
}
|
||||
|
||||
static final class NoopSpanContext implements SpanContext {
|
||||
static final NoopSpanContext INSTANCE = new NoopSpanContext();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package datadog.opentracing;
|
||||
|
||||
// temporary replacement for io.opentracing.Span
|
||||
// this is currently needed as superclass for DDSpan and NoopSpan
|
||||
public interface Span {
|
||||
|
||||
SpanContext context();
|
||||
|
||||
Span setTag(String key, String value);
|
||||
|
||||
Span setTag(String key, boolean value);
|
||||
|
||||
Span setTag(String key, Number value);
|
||||
|
||||
Span setOperationName(String operationName);
|
||||
|
||||
void finish();
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package datadog.opentracing;
|
||||
|
||||
// temporary replacement for io.opentracing.SpanContext
|
||||
public interface SpanContext {}
|
|
@ -3,8 +3,6 @@ package datadog.opentracing.propagation;
|
|||
import static datadog.opentracing.propagation.HttpCodec.validateUInt64BitsID;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import io.opentracing.propagation.TextMapExtract;
|
||||
import io.opentracing.propagation.TextMapInject;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package datadog.opentracing.propagation;
|
||||
|
||||
import io.opentracing.SpanContext;
|
||||
import datadog.opentracing.SpanContext;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Propagated data resulting from calling tracer.extract with header data from an incoming request.
|
||||
|
@ -17,21 +15,6 @@ public class ExtractedContext implements SpanContext {
|
|||
this.spanId = spanId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toTraceId() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSpanId() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Map.Entry<String, String>> baggageItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public BigInteger getTraceId() {
|
||||
return traceId;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package datadog.opentracing.propagation;
|
|||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.opentracing.DDTracer;
|
||||
import io.opentracing.propagation.TextMapExtract;
|
||||
import io.opentracing.propagation.TextMapInject;
|
||||
import java.math.BigInteger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package datadog.opentracing.propagation;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
// temporary replacement for io.opentracing.propagation.TextMapExtract
|
||||
public interface TextMapExtract extends Iterable<Map.Entry<String, String>> {
|
||||
@Override
|
||||
Iterator<Map.Entry<String, String>> iterator();
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package datadog.opentracing.propagation;
|
||||
|
||||
// temporary replacement for io.opentracing.propagation.TextMapInject
|
||||
public interface TextMapInject {
|
||||
void put(String key, String value);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package datadog.opentracing.resolver;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.trace.api.Config;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.contrib.tracerresolver.TracerResolver;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@AutoService(TracerResolver.class)
|
||||
public class DDTracerResolver extends TracerResolver {
|
||||
|
||||
@VisibleForTesting
|
||||
Tracer resolve(final Config config) {
|
||||
if (config.isTraceResolverEnabled()) {
|
||||
log.info("Creating DDTracer with DDTracerResolver");
|
||||
return new DDTracer();
|
||||
} else {
|
||||
log.info("DDTracerResolver disabled");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tracer resolve() {
|
||||
return resolve(Config.get());
|
||||
}
|
||||
}
|
|
@ -1,65 +1,33 @@
|
|||
package datadog.opentracing.scopemanager;
|
||||
|
||||
import datadog.opentracing.DDSpan;
|
||||
import datadog.opentracing.Span;
|
||||
import datadog.trace.context.ScopeListener;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.ScopeManager;
|
||||
import io.opentracing.Span;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class ContextualScopeManager implements ScopeManager {
|
||||
public class ContextualScopeManager {
|
||||
static final ThreadLocal<DDScope> tlsScope = new ThreadLocal<>();
|
||||
final Deque<ScopeContext> scopeContexts = new ConcurrentLinkedDeque<>();
|
||||
final List<ScopeListener> scopeListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
public Scope activate(final Span span, final boolean finishOnClose) {
|
||||
for (final ScopeContext context : scopeContexts) {
|
||||
if (context.inContext()) {
|
||||
return context.activate(span, finishOnClose);
|
||||
}
|
||||
}
|
||||
public DDScope activate(final Span span, final boolean finishOnClose) {
|
||||
if (span instanceof DDSpan) {
|
||||
return new ContinuableScope(this, (DDSpan) span, finishOnClose);
|
||||
} else {
|
||||
// NoopSpan
|
||||
return new SimpleScope(this, span, finishOnClose);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scope activate(final Span span) {
|
||||
return activate(span, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scope active() {
|
||||
for (final ScopeContext csm : scopeContexts) {
|
||||
if (csm.inContext()) {
|
||||
return csm.active();
|
||||
}
|
||||
}
|
||||
public DDScope active() {
|
||||
return tlsScope.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span activeSpan() {
|
||||
for (final ScopeContext csm : scopeContexts) {
|
||||
if (csm.inContext()) {
|
||||
return csm.activeSpan();
|
||||
}
|
||||
}
|
||||
final DDScope active = tlsScope.get();
|
||||
return active == null ? null : active.span();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addScopeContext(final ScopeContext context) {
|
||||
scopeContexts.addFirst(context);
|
||||
}
|
||||
|
||||
/** Attach a listener to scope activation events */
|
||||
public void addScopeListener(final ScopeListener listener) {
|
||||
scopeListeners.add(listener);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package datadog.opentracing.scopemanager;
|
||||
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import datadog.opentracing.Span;
|
||||
import java.io.Closeable;
|
||||
|
||||
public interface DDScope extends Closeable {
|
||||
|
||||
// Intentionally package private.
|
||||
interface DDScope extends Scope {
|
||||
@Override
|
||||
Span span();
|
||||
|
||||
@Override
|
||||
void close();
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package datadog.opentracing.scopemanager;
|
||||
|
||||
import io.opentracing.ScopeManager;
|
||||
|
||||
/** Represents a ScopeManager that is only valid in certain cases such as on a specific thread. */
|
||||
@Deprecated
|
||||
public interface ScopeContext extends ScopeManager {
|
||||
|
||||
/**
|
||||
* When multiple ScopeContexts are active, the first one to respond true will have control.
|
||||
*
|
||||
* @return true if this ScopeContext should be active
|
||||
*/
|
||||
boolean inContext();
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package datadog.opentracing.scopemanager;
|
||||
|
||||
import datadog.opentracing.Span;
|
||||
import datadog.trace.context.ScopeListener;
|
||||
import io.opentracing.Span;
|
||||
|
||||
/** Simple scope implementation which does not propagate across threads. */
|
||||
public class SimpleScope implements DDScope {
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
import datadog.opentracing.DDSpan
|
||||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.propagation.ExtractedContext
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.Tracer
|
||||
import io.opentracing.propagation.Format
|
||||
import io.opentracing.propagation.TextMap
|
||||
import spock.lang.Subject
|
||||
|
||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
|
||||
|
||||
// This test focuses on things that are different between OpenTracing API 0.31.0 and 0.32.0
|
||||
class OT31ApiTest extends DDSpecification {
|
||||
static final WRITER = new ListWriter()
|
||||
|
||||
@Subject
|
||||
Tracer tracer = new DDTracer(WRITER)
|
||||
|
||||
def "test startActive"() {
|
||||
when:
|
||||
def scope = tracer.buildSpan("some name").startActive(finishSpan)
|
||||
scope.close()
|
||||
|
||||
then:
|
||||
(scope.span() as DDSpan).isFinished() == finishSpan
|
||||
|
||||
where:
|
||||
finishSpan << [true, false]
|
||||
}
|
||||
|
||||
def "test startManual"() {
|
||||
when:
|
||||
tracer.buildSpan("some name").startManual().finish()
|
||||
|
||||
then:
|
||||
assertTraces(WRITER, 1) {
|
||||
trace(0, 1) {
|
||||
basicSpan(it, 0, "some name")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def "test scopemanager"() {
|
||||
setup:
|
||||
def span = tracer.buildSpan("some name").start()
|
||||
|
||||
when:
|
||||
tracer.scopeManager().activate(span, finishSpan) != null
|
||||
tracer.scopeManager().active().span() == span
|
||||
|
||||
then:
|
||||
tracer.scopeManager().active().close()
|
||||
(span as DDSpan).isFinished() == finishSpan
|
||||
|
||||
where:
|
||||
finishSpan << [true, false]
|
||||
}
|
||||
|
||||
def "test inject extract"() {
|
||||
setup:
|
||||
def context = tracer.buildSpan("some name").start().context() as DDSpanContext
|
||||
def textMap = [:]
|
||||
def adapter = new TextMapAdapter(textMap)
|
||||
|
||||
when:
|
||||
tracer.inject(context, Format.Builtin.TEXT_MAP, adapter)
|
||||
|
||||
then:
|
||||
textMap == [
|
||||
"x-datadog-trace-id" : context.toTraceId(),
|
||||
"x-datadog-parent-id": context.toSpanId(),
|
||||
]
|
||||
|
||||
when:
|
||||
def extract = tracer.extract(Format.Builtin.TEXT_MAP, adapter) as ExtractedContext
|
||||
|
||||
then:
|
||||
extract.traceId == context.traceId
|
||||
extract.spanId == context.spanId
|
||||
}
|
||||
|
||||
static class TextMapAdapter implements TextMap {
|
||||
private final Map<String, String> map
|
||||
|
||||
TextMapAdapter(Map<String, String> map) {
|
||||
this.map = map
|
||||
}
|
||||
|
||||
@Override
|
||||
Iterator<Map.Entry<String, String>> iterator() {
|
||||
return map.entrySet().iterator()
|
||||
}
|
||||
|
||||
@Override
|
||||
void put(String key, String value) {
|
||||
map.put(key, value)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
import datadog.opentracing.DDSpan
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.Tracer
|
||||
import spock.lang.Subject
|
||||
|
||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
|
||||
|
||||
// This test focuses on things that are different between OpenTracing API 0.32.0 and 0.33.0
|
||||
class OT33ApiTest extends DDSpecification {
|
||||
static final WRITER = new ListWriter()
|
||||
|
||||
@Subject
|
||||
Tracer tracer = new DDTracer(WRITER)
|
||||
|
||||
def "test start"() {
|
||||
when:
|
||||
def span = tracer.buildSpan("some name").start()
|
||||
def scope = tracer.activateSpan(span)
|
||||
scope.close()
|
||||
|
||||
then:
|
||||
(scope.span() as DDSpan).isFinished() == false
|
||||
assertTraces(WRITER, 0) {}
|
||||
|
||||
when:
|
||||
span.finish()
|
||||
|
||||
then:
|
||||
assertTraces(WRITER, 1) {
|
||||
trace(0, 1) {
|
||||
basicSpan(it, 0, "some name")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def "test scopemanager"() {
|
||||
setup:
|
||||
def span = tracer.buildSpan("some name").start()
|
||||
|
||||
when:
|
||||
tracer.scopeManager().activate(span) != null
|
||||
|
||||
then:
|
||||
tracer.activeSpan() == span
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package datadog.opentracing
|
||||
|
||||
import datadog.opentracing.propagation.ExtractedContext
|
||||
import datadog.opentracing.scopemanager.DDScope
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.Scope
|
||||
import io.opentracing.noop.NoopSpan
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS
|
||||
|
||||
|
@ -143,12 +142,12 @@ class DDSpanBuilderTest extends DDSpecification {
|
|||
|
||||
def "should link to parent span implicitly"() {
|
||||
setup:
|
||||
final Scope parent = noopParent ?
|
||||
final DDScope parent = noopParent ?
|
||||
tracer.scopeManager().activate(NoopSpan.INSTANCE, false) :
|
||||
tracer.buildSpan("parent")
|
||||
.startActive(false)
|
||||
|
||||
final BigInteger expectedParentId = noopParent ? 0G : new BigInteger(parent.span().context().toSpanId())
|
||||
final BigInteger expectedParentId = noopParent ? 0G : ((DDSpanContext) parent.span().context()).getSpanId()
|
||||
|
||||
final String expectedName = "fakeName"
|
||||
|
||||
|
@ -187,46 +186,6 @@ class DDSpanBuilderTest extends DDSpecification {
|
|||
span.getOperationName() == expectedName
|
||||
}
|
||||
|
||||
|
||||
def "should inherit the DD parent attributes addReference CHILD_OF"() {
|
||||
setup:
|
||||
def expectedName = "fakeName"
|
||||
|
||||
final DDSpan parent =
|
||||
tracer
|
||||
.buildSpan(expectedName)
|
||||
.start()
|
||||
|
||||
DDSpan span =
|
||||
tracer
|
||||
.buildSpan(expectedName)
|
||||
.addReference("child_of", parent.context())
|
||||
.start()
|
||||
|
||||
expect:
|
||||
span.getOperationName() == expectedName
|
||||
}
|
||||
|
||||
|
||||
def "should inherit the DD parent attributes add reference FOLLOWS_FROM"() {
|
||||
setup:
|
||||
def expectedName = "fakeName"
|
||||
|
||||
final DDSpan parent =
|
||||
tracer
|
||||
.buildSpan(expectedName)
|
||||
.start()
|
||||
|
||||
DDSpan span =
|
||||
tracer
|
||||
.buildSpan(expectedName)
|
||||
.addReference("follows_from", parent.context())
|
||||
.start()
|
||||
|
||||
expect:
|
||||
span.getOperationName() == expectedName
|
||||
}
|
||||
|
||||
def "should track all spans in trace"() {
|
||||
setup:
|
||||
List<DDSpan> spans = []
|
||||
|
|
|
@ -3,7 +3,6 @@ package datadog.opentracing
|
|||
import datadog.opentracing.propagation.ExtractedContext
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.SpanContext
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package datadog.opentracing.propagation
|
||||
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.SpanContext
|
||||
import io.opentracing.propagation.TextMapExtractAdapter
|
||||
|
||||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.SPAN_ID_KEY
|
||||
|
@ -46,7 +44,7 @@ class DatadogHttpExtractorTest extends DDSpecification {
|
|||
]
|
||||
|
||||
when:
|
||||
SpanContext context = extractor.extract(new TextMapExtractAdapter(headers))
|
||||
ExtractedContext context = extractor.extract(new TextMapExtractAdapter(headers))
|
||||
|
||||
then:
|
||||
context == null
|
||||
|
@ -61,7 +59,7 @@ class DatadogHttpExtractorTest extends DDSpecification {
|
|||
]
|
||||
|
||||
when:
|
||||
SpanContext context = extractor.extract(new TextMapExtractAdapter(headers))
|
||||
ExtractedContext context = extractor.extract(new TextMapExtractAdapter(headers))
|
||||
|
||||
then:
|
||||
context == null
|
||||
|
@ -75,7 +73,7 @@ class DatadogHttpExtractorTest extends DDSpecification {
|
|||
]
|
||||
|
||||
when:
|
||||
SpanContext context = extractor.extract(new TextMapExtractAdapter(headers))
|
||||
ExtractedContext context = extractor.extract(new TextMapExtractAdapter(headers))
|
||||
|
||||
then:
|
||||
context == null
|
||||
|
|
|
@ -5,7 +5,6 @@ import datadog.opentracing.DDTracer
|
|||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.propagation.TextMapInjectAdapter
|
||||
|
||||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.SPAN_ID_KEY
|
||||
|
|
|
@ -2,8 +2,6 @@ package datadog.opentracing.propagation
|
|||
|
||||
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.SpanContext
|
||||
import io.opentracing.propagation.TextMapExtractAdapter
|
||||
import spock.lang.Shared
|
||||
|
||||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
|
@ -26,7 +24,7 @@ class HttpExtractorTest extends DDSpecification {
|
|||
}
|
||||
|
||||
when:
|
||||
final SpanContext context = extractor.extract(new TextMapExtractAdapter(actual))
|
||||
final ExtractedContext context = extractor.extract(new TextMapExtractAdapter(actual))
|
||||
|
||||
then:
|
||||
if (expectedTraceId == null) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import datadog.opentracing.DDTracer
|
|||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.propagation.TextMapInjectAdapter
|
||||
|
||||
class HttpInjectorTest extends DDSpecification {
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package datadog.opentracing.propagation;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
// temporary replacement for io.opentracing.propagation.TextMapExtractAdapter
|
||||
public class TextMapExtractAdapter implements TextMapExtract {
|
||||
protected final Map<String, String> map;
|
||||
|
||||
public TextMapExtractAdapter(final Map<String, String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Map.Entry<String, String>> iterator() {
|
||||
return map.entrySet().iterator();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package datadog.opentracing.propagation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// temporary replacement for io.opentracing.propagation.TextMapInjectAdapter
|
||||
public class TextMapInjectAdapter implements TextMapInject {
|
||||
protected final Map<String, ? super String> map;
|
||||
|
||||
public TextMapInjectAdapter(final Map<String, ? super String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final String key, final String value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package datadog.opentracing.resolver
|
||||
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.contrib.tracerresolver.TracerResolver
|
||||
|
||||
class DDTracerResolverTest extends DDSpecification {
|
||||
|
||||
def resolver = new DDTracerResolver()
|
||||
|
||||
def "test resolveTracer"() {
|
||||
when:
|
||||
def tracer = TracerResolver.resolveTracer()
|
||||
|
||||
then:
|
||||
tracer instanceof DDTracer
|
||||
}
|
||||
|
||||
def "test disable DDTracerResolver"() {
|
||||
setup:
|
||||
System.setProperty("dd.trace.resolver.enabled", "false")
|
||||
|
||||
when:
|
||||
def tracer = resolver.resolve(new Config())
|
||||
|
||||
then:
|
||||
tracer == null
|
||||
|
||||
cleanup:
|
||||
System.clearProperty("dd.trace.resolver.enabled")
|
||||
}
|
||||
|
||||
}
|
|
@ -3,21 +3,17 @@ package datadog.opentracing.scopemanager
|
|||
import datadog.opentracing.DDSpan
|
||||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.NoopSpan
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.context.ScopeListener
|
||||
import datadog.trace.util.gc.GCUtils
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.Scope
|
||||
import io.opentracing.Span
|
||||
import io.opentracing.noop.NoopSpan
|
||||
import spock.lang.Subject
|
||||
import spock.lang.Timeout
|
||||
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS
|
||||
|
||||
|
@ -397,105 +393,6 @@ class ScopeManagerTest extends DDSpecification {
|
|||
writer == [[childSpan, span]]
|
||||
}
|
||||
|
||||
def "context takes control (#active)"() {
|
||||
setup:
|
||||
contexts.each {
|
||||
scopeManager.addScopeContext(it)
|
||||
}
|
||||
def builder = tracer.buildSpan("test")
|
||||
def scope = (AtomicReferenceScope) builder.startActive(true)
|
||||
|
||||
expect:
|
||||
scopeManager.tlsScope.get() == null
|
||||
scopeManager.active() == scope
|
||||
contexts[active].get() == scope.get()
|
||||
writer.empty
|
||||
|
||||
where:
|
||||
active | contexts
|
||||
0 | [new AtomicReferenceScope(true)]
|
||||
1 | [new AtomicReferenceScope(true), new AtomicReferenceScope(true)]
|
||||
3 | [new AtomicReferenceScope(false), new AtomicReferenceScope(true), new AtomicReferenceScope(false), new AtomicReferenceScope(true)]
|
||||
}
|
||||
|
||||
def "disabled context is ignored (#contexts.size)"() {
|
||||
setup:
|
||||
contexts.each {
|
||||
scopeManager.addScopeContext(it)
|
||||
}
|
||||
def builder = tracer.buildSpan("test")
|
||||
def scope = builder.startActive(true)
|
||||
|
||||
expect:
|
||||
contexts.findAll {
|
||||
it.get() != null
|
||||
} == []
|
||||
|
||||
scopeManager.tlsScope.get() == scope
|
||||
scopeManager.active() == scope
|
||||
writer.empty
|
||||
|
||||
where:
|
||||
contexts | _
|
||||
[] | _
|
||||
[new AtomicReferenceScope(false)] | _
|
||||
[new AtomicReferenceScope(false), new AtomicReferenceScope(false)] | _
|
||||
[new AtomicReferenceScope(false), new AtomicReferenceScope(false), new AtomicReferenceScope(false)] | _
|
||||
}
|
||||
|
||||
def "ContinuableScope put in threadLocal after continuation activation"() {
|
||||
setup:
|
||||
ContinuableScope scope = (ContinuableScope) tracer.buildSpan("parent").startActive(true)
|
||||
scope.setAsyncPropagation(true)
|
||||
|
||||
expect:
|
||||
scopeManager.tlsScope.get() == scope
|
||||
|
||||
when:
|
||||
def cont = scope.capture()
|
||||
scope.close()
|
||||
|
||||
then:
|
||||
scopeManager.tlsScope.get() == null
|
||||
|
||||
when:
|
||||
scopeManager.addScopeContext(new AtomicReferenceScope(true))
|
||||
def newScope = cont.activate()
|
||||
|
||||
then:
|
||||
newScope != scope
|
||||
scopeManager.tlsScope.get() == newScope
|
||||
}
|
||||
|
||||
def "context to threadlocal (#contexts.size)"() {
|
||||
setup:
|
||||
contexts.each {
|
||||
scopeManager.addScopeContext(it)
|
||||
}
|
||||
def scope = tracer.buildSpan("parent").startActive(false)
|
||||
def span = scope.span()
|
||||
|
||||
expect:
|
||||
scope instanceof AtomicReferenceScope
|
||||
scopeManager.tlsScope.get() == null
|
||||
|
||||
when:
|
||||
scope.close()
|
||||
contexts.each {
|
||||
((AtomicBoolean) it.enabled).set(false)
|
||||
}
|
||||
scope = scopeManager.activate(span, true)
|
||||
|
||||
then:
|
||||
scope instanceof ContinuableScope
|
||||
scopeManager.tlsScope.get() == scope
|
||||
|
||||
where:
|
||||
contexts | _
|
||||
[new AtomicReferenceScope(true)] | _
|
||||
[new AtomicReferenceScope(true), new AtomicReferenceScope(true)] | _
|
||||
}
|
||||
|
||||
def "add scope listener"() {
|
||||
setup:
|
||||
AtomicInteger activatedCount = new AtomicInteger(0)
|
||||
|
@ -514,14 +411,14 @@ class ScopeManagerTest extends DDSpecification {
|
|||
})
|
||||
|
||||
when:
|
||||
Scope scope1 = scopeManager.activate(NoopSpan.INSTANCE, true)
|
||||
DDScope scope1 = scopeManager.activate(NoopSpan.INSTANCE, true)
|
||||
|
||||
then:
|
||||
activatedCount.get() == 1
|
||||
closedCount.get() == 0
|
||||
|
||||
when:
|
||||
Scope scope2 = scopeManager.activate(NoopSpan.INSTANCE, true)
|
||||
DDScope scope2 = scopeManager.activate(NoopSpan.INSTANCE, true)
|
||||
|
||||
then:
|
||||
activatedCount.get() == 2
|
||||
|
@ -542,14 +439,14 @@ class ScopeManagerTest extends DDSpecification {
|
|||
closedCount.get() == 2
|
||||
|
||||
when:
|
||||
Scope continuableScope = tracer.buildSpan("foo").startActive(true)
|
||||
DDScope continuableScope = tracer.buildSpan("foo").startActive(true)
|
||||
|
||||
then:
|
||||
continuableScope instanceof ContinuableScope
|
||||
activatedCount.get() == 4
|
||||
|
||||
when:
|
||||
Scope childContinuableScope = tracer.buildSpan("child").startActive(true)
|
||||
DDScope childContinuableScope = tracer.buildSpan("child").startActive(true)
|
||||
|
||||
then:
|
||||
childContinuableScope instanceof ContinuableScope
|
||||
|
@ -571,56 +468,7 @@ class ScopeManagerTest extends DDSpecification {
|
|||
closedCount.get() == 4
|
||||
}
|
||||
|
||||
boolean spanFinished(Span span) {
|
||||
return ((DDSpan) span)?.isFinished()
|
||||
}
|
||||
|
||||
class AtomicReferenceScope extends AtomicReference<Span> implements ScopeContext, Scope {
|
||||
final AtomicBoolean enabled
|
||||
|
||||
AtomicReferenceScope(boolean enabled) {
|
||||
this.enabled = new AtomicBoolean(enabled)
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean inContext() {
|
||||
return enabled.get()
|
||||
}
|
||||
|
||||
@Override
|
||||
void close() {
|
||||
getAndSet(null).finish()
|
||||
}
|
||||
|
||||
@Override
|
||||
Span span() {
|
||||
return get()
|
||||
}
|
||||
|
||||
@Override
|
||||
Scope activate(Span span, boolean finishSpanOnClose) {
|
||||
set(span)
|
||||
return this
|
||||
}
|
||||
|
||||
@Override
|
||||
Scope activate(Span span) {
|
||||
set(span)
|
||||
return this
|
||||
}
|
||||
|
||||
@Override
|
||||
Scope active() {
|
||||
return get() == null ? null : this
|
||||
}
|
||||
|
||||
@Override
|
||||
Span activeSpan() {
|
||||
return active()?.span()
|
||||
}
|
||||
|
||||
String toString() {
|
||||
return "Ref: " + super.toString()
|
||||
}
|
||||
boolean spanFinished(DDSpan span) {
|
||||
return span?.isFinished()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,37 +3,26 @@ def spockGroovyVer = groovyVer.replaceAll(/\.\d+$/, '')
|
|||
|
||||
ext {
|
||||
versions = [
|
||||
opentracing: '0.32.0',
|
||||
slf4j : "1.7.29",
|
||||
guava : "20.0", // Last version to support Java 7
|
||||
|
||||
slf4j : "1.7.29",
|
||||
guava : "20.0", // Last version to support Java 7
|
||||
|
||||
spock : "1.3-groovy-$spockGroovyVer",
|
||||
groovy : groovyVer,
|
||||
logback : "1.2.3",
|
||||
lombok : "1.18.10",
|
||||
bytebuddy : "1.10.4",
|
||||
scala : "2.11.12", // Last version to support Java 7 (2.12+ require Java 8+)
|
||||
kotlin : "1.3.50",
|
||||
coroutines : "1.3.0"
|
||||
spock : "1.3-groovy-$spockGroovyVer",
|
||||
groovy : groovyVer,
|
||||
logback : "1.2.3",
|
||||
lombok : "1.18.10",
|
||||
bytebuddy : "1.10.4",
|
||||
scala : "2.11.12", // Last version to support Java 7 (2.12+ require Java 8+)
|
||||
kotlin : "1.3.50",
|
||||
coroutines: "1.3.0"
|
||||
]
|
||||
|
||||
deps = [
|
||||
// OpenTracing
|
||||
opentracingApi : dependencies.create(group: 'io.opentracing', name: 'opentracing-api', version: versions.opentracing),
|
||||
opentracing : [
|
||||
dependencies.create(group: 'io.opentracing', name: 'opentracing-api', version: versions.opentracing),
|
||||
dependencies.create(group: 'io.opentracing', name: 'opentracing-noop', version: versions.opentracing),
|
||||
dependencies.create(group: 'io.opentracing', name: 'opentracing-util', version: versions.opentracing),
|
||||
],
|
||||
opentracingMock: dependencies.create(group: 'io.opentracing', name: 'opentracing-mock', version: versions.opentracing),
|
||||
|
||||
// General
|
||||
slf4j : "org.slf4j:slf4j-api:${versions.slf4j}",
|
||||
guava : "com.google.guava:guava:$versions.guava",
|
||||
bytebuddy : dependencies.create(group: 'net.bytebuddy', name: 'byte-buddy', version: "${versions.bytebuddy}"),
|
||||
bytebuddyagent : dependencies.create(group: 'net.bytebuddy', name: 'byte-buddy-agent', version: "${versions.bytebuddy}"),
|
||||
autoservice : [
|
||||
slf4j : "org.slf4j:slf4j-api:${versions.slf4j}",
|
||||
guava : "com.google.guava:guava:$versions.guava",
|
||||
bytebuddy : dependencies.create(group: 'net.bytebuddy', name: 'byte-buddy', version: "${versions.bytebuddy}"),
|
||||
bytebuddyagent: dependencies.create(group: 'net.bytebuddy', name: 'byte-buddy-agent', version: "${versions.bytebuddy}"),
|
||||
autoservice : [
|
||||
dependencies.create(group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc3'),
|
||||
dependencies.create(group: 'com.google.auto', name: 'auto-common', version: '0.8'),
|
||||
// These are the last versions that support guava 20.0. Upgrading has odd interactions with shadow.
|
||||
|
@ -42,23 +31,23 @@ ext {
|
|||
|
||||
// Testing
|
||||
|
||||
spock : [
|
||||
spock : [
|
||||
dependencies.create("org.spockframework:spock-core:${versions.spock}", {
|
||||
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
|
||||
}),
|
||||
// Used by Spock for mocking:
|
||||
dependencies.create(group: 'org.objenesis', name: 'objenesis', version: '2.6') // Last version to support Java7
|
||||
],
|
||||
groovy : "org.codehaus.groovy:groovy-all:${versions.groovy}",
|
||||
testcontainers : "org.testcontainers:testcontainers:1.12.2",
|
||||
testLogging : [
|
||||
groovy : "org.codehaus.groovy:groovy-all:${versions.groovy}",
|
||||
testcontainers: "org.testcontainers:testcontainers:1.12.2",
|
||||
testLogging : [
|
||||
dependencies.create(group: 'ch.qos.logback', name: 'logback-classic', version: versions.logback),
|
||||
dependencies.create(group: 'org.slf4j', name: 'log4j-over-slf4j', version: versions.slf4j),
|
||||
dependencies.create(group: 'org.slf4j', name: 'jcl-over-slf4j', version: versions.slf4j),
|
||||
dependencies.create(group: 'org.slf4j', name: 'jul-to-slf4j', version: versions.slf4j),
|
||||
],
|
||||
scala : dependencies.create(group: 'org.scala-lang', name: 'scala-library', version: "${versions.scala}"),
|
||||
kotlin : dependencies.create(group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: "${versions.kotlin}"),
|
||||
coroutines : dependencies.create(group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: "${versions.coroutines}"),
|
||||
scala : dependencies.create(group: 'org.scala-lang', name: 'scala-library', version: "${versions.scala}"),
|
||||
kotlin : dependencies.create(group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: "${versions.kotlin}"),
|
||||
coroutines : dependencies.create(group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: "${versions.coroutines}"),
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue