Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public class OtelScope implements Scope, TraceScope {
this.delegate = delegate;
}

@Override
public Continuation capture() {
return delegate.capture();
}

@Override
public void close() {
delegate.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public Span span() {
return converter.toSpan(delegate.span());
}

@Override
public Continuation capture() {
return delegate.capture();
}

public boolean isFinishSpanOnClose() {
return finishSpanOnClose;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ public Span span() {
return converter.toSpan(delegate.span());
}

@Override
public Continuation capture() {
return delegate.capture();
}

public boolean isFinishSpanOnClose() {
return finishSpanOnClose;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package datadog.trace.instrumentation.playws1;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.capture;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.captureSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.setAsyncPropagationEnabled;
import static datadog.trace.instrumentation.playws.PlayWSClientDecorator.DECORATE;

Expand All @@ -22,7 +22,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
public AsyncHandlerWrapper(final AsyncHandler delegate, final AgentSpan span) {
this.delegate = delegate;
this.span = span;
continuation = capture();
continuation = captureSpan(span);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package datadog.trace.instrumentation.playws21;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.capture;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.captureSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.setAsyncPropagationEnabled;
import static datadog.trace.instrumentation.playws.PlayWSClientDecorator.DECORATE;

Expand All @@ -27,7 +27,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
public AsyncHandlerWrapper(final AsyncHandler delegate, final AgentSpan span) {
this.delegate = delegate;
this.span = span;
continuation = capture();
continuation = captureSpan(span);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package datadog.trace.instrumentation.playws2;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.capture;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.captureSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.setAsyncPropagationEnabled;
import static datadog.trace.instrumentation.playws.PlayWSClientDecorator.DECORATE;

Expand All @@ -26,7 +26,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
public AsyncHandlerWrapper(final AsyncHandler delegate, final AgentSpan span) {
this.delegate = delegate;
this.span = span;
continuation = capture();
continuation = captureSpan(span);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
*/
private class ParentContext {
final ContextMap contextMap = AsyncContext.context().copy()
final AgentScope.Continuation spanContinuation = AgentTracer.capture()
final AgentScope.Continuation spanContinuation = AgentTracer.captureActiveSpan()

def releaseParentSpan() {
spanContinuation.cancel()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package datadog.trace.instrumentation.zio.v2_0;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.capture;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.captureActiveSpan;

import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
Expand All @@ -16,7 +16,7 @@ private FiberContext(ScopeState state) {
this.state = state;
this.scope = null;
this.oldState = null;
this.continuation = capture();
this.continuation = captureActiveSpan();
}

public static FiberContext create() {
Expand Down
17 changes: 11 additions & 6 deletions dd-trace-api/src/main/java/datadog/trace/api/GlobalTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@ public String getSpanId() {
}

@Override
public boolean isAsyncPropagationEnabled() {
public boolean addTraceInterceptor(TraceInterceptor traceInterceptor) {
return false;
}

@Override
public void setAsyncPropagationEnabled(boolean asyncPropagationEnabled) {}
public TraceScope muteTracing() {
return NoopTraceScope.INSTANCE;
}

@Override
public boolean addTraceInterceptor(TraceInterceptor traceInterceptor) {
return false;
public TraceScope.Continuation captureActiveSpan() {
return NoopTraceScope.NoopContinuation.INSTANCE;
}

@Override
public TraceScope muteTracing() {
return NoopTraceScope.INSTANCE;
public boolean isAsyncPropagationEnabled() {
return false;
}

@Override
public void setAsyncPropagationEnabled(boolean asyncPropagationEnabled) {}
};

private static final Collection<Callback> installationCallbacks = new ArrayList<>();
Expand Down
36 changes: 25 additions & 11 deletions dd-trace-api/src/main/java/datadog/trace/api/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ public interface Tracer {
*/
String getSpanId();

/**
* Add a new interceptor to the tracer. Interceptors with duplicate priority to existing ones are
* ignored.
*
* @param traceInterceptor
* @return false if an interceptor with same priority exists.
*/
boolean addTraceInterceptor(TraceInterceptor traceInterceptor);

TraceScope muteTracing();

/**
* When asynchronous propagation is enabled, prevent the currently active trace from reporting
* until the returned Continuation is either activated (and the returned scope is closed) or the
* continuation is canceled.
*
* <p>Should be called on the parent thread.
*
* @deprecated Unstable API. Might be removed at any time.
* @return Continuation of the active span, no-op continuation if there's no active span or
* asynchronous propagation is disabled.
*/
@Deprecated
TraceScope.Continuation captureActiveSpan();

/**
* Checks whether asynchronous propagation is enabled, meaning this context will propagate across
* asynchronous boundaries.
Expand All @@ -36,15 +61,4 @@ public interface Tracer {
*/
@Deprecated
void setAsyncPropagationEnabled(boolean asyncPropagationEnabled);

/**
* Add a new interceptor to the tracer. Interceptors with duplicate priority to existing ones are
* ignored.
*
* @param traceInterceptor
* @return false if an interceptor with same priority exists.
*/
boolean addTraceInterceptor(TraceInterceptor traceInterceptor);

TraceScope muteTracing();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public void cancel() {}

private NoopTraceScope() {}

@Override
public Continuation capture() {
return NoopContinuation.INSTANCE;
}

@Override
public void close() {}
}
79 changes: 43 additions & 36 deletions dd-trace-api/src/main/java/datadog/trace/context/TraceScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,11 @@

/** An object which can propagate a datadog trace across multiple threads. */
public interface TraceScope extends Closeable {
/**
* Prevent the trace attached to this TraceScope from reporting until the returned Continuation is
* either activated (and the returned scope is closed), or canceled.
*
* <p>Should be called on the parent thread.
*/
Continuation capture();

/** @deprecated Replaced by {@code capture().hold()}. */
@Deprecated
default Continuation captureConcurrent() {
return capture().hold();
}

/** Close the activated context and allow any underlying spans to finish. */
@Override
void close();

/**
* @deprecated Replaced by {@link Tracer#isAsyncPropagationEnabled()}.
* <p>Calling this method will check whether asynchronous propagation is active <strong>for
* the active scope</strong>, not this scope instance.
* @return {@code true} if asynchronous propagation is enabled <strong>for the active
* scope</strong>, {@code false} otherwise.
*/
@Deprecated
default boolean isAsyncPropagating() {
return GlobalTracer.get().isAsyncPropagationEnabled();
}

/**
* @deprecated Replaced by {@link Tracer#setAsyncPropagationEnabled(boolean)}}.
* <p>Calling this method will enable or disable asynchronous propagation <strong>for the
* active scope</strong>, not this scope instance.
* @param value {@code true} to enable asynchronous propagation, {@code false} to disable it.
*/
@Deprecated
default void setAsyncPropagation(boolean value) {
GlobalTracer.get().setAsyncPropagationEnabled(value);
}

/**
* Used to pass async context between workers. A trace will not be reported until all spans and
* continuations are resolved. You must call activate (and close on the returned scope) or cancel
Expand Down Expand Up @@ -76,4 +40,47 @@ interface Continuation {
/** Allow trace to stop waiting on this continuation for reporting. */
void cancel();
}

/**
* @deprecated Replaced by {@link Tracer#captureActiveSpan()}.
* <p>When asynchronous propagation is enabled, prevent the <strong>currently active
* trace</strong>, which may differ from this scope instance, from reporting until the
* returned Continuation is either activated (and the returned scope is closed) or the
* continuation is canceled. Should be called on the parent thread.
* @return Continuation of the active span, no-op continuation if there's no active span or
* asynchronous propagation is disabled.
*/
@Deprecated
default Continuation capture() {
return GlobalTracer.get().captureActiveSpan();
}

/** @deprecated Replaced by {@code capture().hold()}. */
@Deprecated
default Continuation captureConcurrent() {
return capture().hold();
}

/**
* @deprecated Replaced by {@link Tracer#isAsyncPropagationEnabled()}.
* <p>Calling this method will check whether asynchronous propagation is enabled <strong>for
* the active scope</strong>, not this scope instance.
* @return {@code true} if asynchronous propagation is enabled <strong>for the active
* scope</strong>, {@code false} otherwise.
*/
@Deprecated
default boolean isAsyncPropagating() {
return GlobalTracer.get().isAsyncPropagationEnabled();
}

/**
* @deprecated Replaced by {@link Tracer#setAsyncPropagationEnabled(boolean)}}.
* <p>Calling this method will enable or disable asynchronous propagation <strong>for the
* active scope</strong>, not this scope instance.
* @param value {@code true} to enable asynchronous propagation, {@code false} to disable it.
*/
@Deprecated
default void setAsyncPropagation(boolean value) {
GlobalTracer.get().setAsyncPropagationEnabled(value);
}
}
10 changes: 10 additions & 0 deletions dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,16 @@ public AgentScope activateSpan(AgentSpan span, ScopeSource source, boolean isAsy
return scopeManager.activate(span, source, isAsyncPropagating);
}

@Override
public AgentScope.Continuation captureActiveSpan() {
AgentScope activeScope = this.scopeManager.active();
if (null != activeScope) {
return activeScope.capture();
} else {
return AgentTracer.noopContinuation();
}
}

@Override
public AgentScope.Continuation captureSpan(final AgentSpan span) {
return scopeManager.captureSpan(span);
Expand Down
21 changes: 13 additions & 8 deletions dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,23 +430,28 @@ public String getSpanId() {
}

@Override
public boolean isAsyncPropagationEnabled() {
return tracer.isAsyncPropagationEnabled();
public boolean addTraceInterceptor(final TraceInterceptor traceInterceptor) {
return tracer.addTraceInterceptor(traceInterceptor);
}

@Override
public void setAsyncPropagationEnabled(boolean asyncPropagationEnabled) {
tracer.setAsyncPropagationEnabled(asyncPropagationEnabled);
public TraceScope muteTracing() {
return tracer.muteTracing();
}

@Override
public boolean addTraceInterceptor(final TraceInterceptor traceInterceptor) {
return tracer.addTraceInterceptor(traceInterceptor);
public TraceScope.Continuation captureActiveSpan() {
return tracer.captureActiveSpan();
}

@Override
public TraceScope muteTracing() {
return tracer.muteTracing();
public boolean isAsyncPropagationEnabled() {
return tracer.isAsyncPropagationEnabled();
}

@Override
public void setAsyncPropagationEnabled(boolean asyncPropagationEnabled) {
tracer.setAsyncPropagationEnabled(asyncPropagationEnabled);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public int hashCode() {
return delegate.hashCode();
}

@Override
public Continuation capture() {
return delegate.capture();
}

boolean isFinishSpanOnClose() {
return finishSpanOnClose;
}
Expand Down
Loading
Loading