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 @@ -16,7 +16,11 @@ public CapturedContext captureContext(CapturedContext underlying) {

@Override
public CapturedContext captureContextCopy(CapturedContext underlying) {
return new WithDatadogCapturedContext(AgentTracer.activeSpan(), underlying);
AgentSpan activeSpan = AgentTracer.activeSpan();
if (activeSpan == null) {
return underlying;
}
return new WithDatadogCapturedContext(activeSpan, underlying);
}

private static final class WithDatadogCapturedContext implements CapturedContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
assertParentChildTrace()
}

def "capturedContext without an active span"() {
when:
runInSeparateThread {
try (def _ = asyncContextProvider.captureContext().attachContext()) {
childSpan()
}
}

then:
assertTraces(1) {
trace(1) {
span {
operationName "child"
tags {
defaultTags()
}
}
}
}
}

def "wrapBiConsumer"() {
setup:
def parent = startParentContext()
Expand Down