Skip to content

Commit a7ada65

Browse files
committed
Respect async propagation flag
1 parent b03363c commit a7ada65

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

dd-trace-api/src/main/java/datadog/trace/api/Tracer.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ public interface Tracer {
2626
TraceScope muteTracing();
2727

2828
/**
29-
* Prevent the currently active trace from reporting until the returned Continuation is either
30-
* activated (and the returned scope is closed), or canceled.
29+
* When asynchronous propagation is enabled, prevent the currently active trace from reporting
30+
* until the returned Continuation is either activated (and the returned scope is closed) or the
31+
* continuation is canceled.
3132
*
3233
* <p>Should be called on the parent thread.
3334
*
3435
* @deprecated Unstable API. Might be removed at any time.
35-
* @return Continuation of the active span, no-op continuation if there's no active span.
36+
* @return Continuation of the active span, no-op continuation if there's no active span or
37+
* asynchronous propagation is disabled.
3638
*/
3739
@Deprecated
3840
TraceScope.Continuation captureActiveSpan();

dd-trace-api/src/main/java/datadog/trace/context/TraceScope.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ interface Continuation {
4343

4444
/**
4545
* @deprecated Replaced by {@link Tracer#captureActiveSpan()}.
46-
* <p>Prevent the <strong>currently active trace</strong>, which may differ from this scope
47-
* instance, from reporting until the returned Continuation is either activated (and the
48-
* returned scope is closed), or canceled. Should be called on the parent thread.
49-
* @return Continuation of the active span, no-op continuation if there's no active span.
46+
* <p>When asynchronous propagation is enabled, prevent the <strong>currently active
47+
* trace</strong>, which may differ from this scope instance, from reporting until the
48+
* returned Continuation is either activated (and the returned scope is closed) or the
49+
* continuation is canceled. Should be called on the parent thread.
50+
* @return Continuation of the active span, no-op continuation if there's no active span or
51+
* asynchronous propagation is disabled.
5052
*/
5153
@Deprecated
5254
default Continuation capture() {
@@ -61,7 +63,7 @@ default Continuation captureConcurrent() {
6163

6264
/**
6365
* @deprecated Replaced by {@link Tracer#isAsyncPropagationEnabled()}.
64-
* <p>Calling this method will check whether asynchronous propagation is active <strong>for
66+
* <p>Calling this method will check whether asynchronous propagation is enabled <strong>for
6567
* the active scope</strong>, not this scope instance.
6668
* @return {@code true} if asynchronous propagation is enabled <strong>for the active
6769
* scope</strong>, {@code false} otherwise.

dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ public AgentScope activateSpan(AgentSpan span, ScopeSource source, boolean isAsy
931931

932932
@Override
933933
public AgentScope.Continuation captureActiveSpan() {
934-
AgentSpan span = scopeManager.activeSpan();
935-
if (null != span) {
936-
return scopeManager.captureSpan(span);
934+
AgentScope activeScope = this.scopeManager.active();
935+
if (null != activeScope && activeScope.isAsyncPropagating()) {
936+
return scopeManager.captureSpan(activeScope.span());
937937
} else {
938938
return AgentTracer.noopContinuation();
939939
}

0 commit comments

Comments
 (0)