8000 Move async propagation API from scope to tracer by PerfectSlayer · Pull Request #8231 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

Move async propagation API from scope to tracer #8231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 21, 2025
Prev Previous commit
Next Next commit
fix(core): Fix buildSpan deprecated use
  • Loading branch information
PerfectSlayer committed Jan 21, 2025
commit ae013ac2ce6ca674442f31156c4deacf9935c6ab
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "Continuation.cancel doesn't close parent scope"() {
when:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def scope = tracer.activateSpan(span)
tracer.setAsyncPropagationEnabled(true)
def continuation = concurrent ? scope.captureConcurrent() : scope.capture()
Expand All @@ -297,7 +297,7 @@ class ScopeManagerTest extends DDCoreSpecification {
// @Flaky("awaitGC is flaky")
def "test continuation doesn't have hard reference on scope"() {
when:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def scopeRef = new AtomicReference<AgentScope>(tracer.activateSpan(span))
tracer.setAsyncPropagationEnabled(true)
def continuation = concurrent ? scopeRef.get().captureConcurrent() : scopeRef.get().capture()
Expand Down Expand Up @@ -328,7 +328,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "hard reference on continuation does not prevent trace from reporting"() {
when:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def scope = tracer.activateSpan(span)
tracer.setAsyncPropagationEnabled(true)
def continuation = concurrent ? scope.captureConcurrent() : scope.capture()
Expand Down Expand Up @@ -363,9 +363,9 @@ class ScopeManagerTest extends DDCoreSpecification {

def "continuation restores trace"() {
when:
def parentSpan = tracer.buildSpan("parent").start()
def parentSpan = tracer.buildSpan("test", "parent").start()
def parentScope = tracer.activateSpan(parentSpan)
def childSpan = tracer.buildSpan("child").start()
def childSpan = tracer.buildSpan("test", "child").start()
def childScope = tracer.activateSpan(childSpan)
tracer.setAsyncPropagationEnabled(true)

Expand Down Expand Up @@ -432,7 +432,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "continuation allows adding spans even after other spans were completed"() {
when: "creating and activating a continuation"
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def scope = tracer.activateSpan(span)
tracer.setAsyncPropagationEnabled(true)
def continuation = concurrent ? scope.captureConcurrent() : scope.capture()
Expand All @@ -452,7 +452,7 @@ class ScopeManagerTest extends DDCoreSpecification {
writer == []

when: "creating a new child span under a continued scope"
def childSpan = tracer.buildSpan("child").start()
def childSpan = tracer.buildSpan("test", "child").start()
def childScope = tracer.activateSpan(childSpan)
childScope.close()
childSpan.finish()
Expand All @@ -476,7 +476,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "test activating same span multiple times"() {
setup:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def state = Mock(Stateful)

when:
Expand Down 8000 Expand Up @@ -510,15 +510,15 @@ class ScopeManagerTest extends DDCoreSpecification {

def "opening and closing multiple scopes"() {
when:
AgentSpan span = tracer.buildSpan("foo").start()
AgentSpan span = tracer.buildSpan("test", "foo").start()
AgentScope continuableScope = tracer.activateSpan(span)

then:
continuableScope instanceof ContinuableScope
assertEvents([ACTIVATE])

when:
AgentSpan childSpan = tracer.buildSpan("foo").start()
AgentSpan childSpan = tracer.buildSpan("test", "foo").start()
AgentScope childDDScope = tracer.activateSpan(childSpan)

then:
Expand All @@ -542,10 +542,10 @@ class ScopeManagerTest extends DDCoreSpecification {

def "closing scope out of order - simple"() {
when:
AgentSpan firstSpan = tracer.buildSpan("foo").start()
AgentSpan firstSpan = tracer.buildSpan("test", "foo").start()
AgentScope firstScope = tracer.activateSpan(firstSpan)

AgentSpan secondSpan = tracer.buildSpan("bar").start()
AgentSpan secondSpan = tracer.buildSpan("test", "bar").start()
AgentScope secondScope = tracer.activateSpan(secondSpan)

firstSpan.finish()
Expand Down Expand Up @@ -582,7 +582,7 @@ class ScopeManagerTest extends DDCoreSpecification {
// tracer.activeScope() or tracer.activeSpan() doesn't change the count

when:
AgentSpan firstSpan = tracer.buildSpan("foo").start()
AgentSpan firstSpan = tracer.buildSpan("test", "foo").start()
AgentScope firstScope = tracer.activateSpan(firstSpan)

then:
Expand All @@ -597,7 +597,7 @@ class ScopeManagerTest extends DDCoreSpecification {
0 * _

when:
AgentSpan secondSpan = tracer.buildSpan("bar").start()
AgentSpan secondSpan = tracer.buildSpan("test", "bar").start()
AgentScope secondScope = tracer.activateSpan(secondSpan)

then:
Expand All @@ -610,7 +610,7 @@ class ScopeManagerTest extends DDCoreSpecification {
0 * _

when:
AgentSpan thirdSpan = tracer.buildSpan("quux").start()
AgentSpan thirdSpan = tracer.buildSpan("test", "quux").start()
AgentScope thirdScope = tracer.activateSpan(thirdSpan)

then:
Expand Down Expand Up @@ -672,7 +672,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "closing scope out of order - multiple activations"() {
setup:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()

when:
AgentScope scope1 = scopeManager.activate(span, ScopeSource.INSTRUMENTATION)
Expand All @@ -687,7 +687,7 @@ class ScopeManagerTest extends DDCoreSpecification {
assertEvents([ACTIVATE])

when:
AgentSpan thirdSpan = tracer.buildSpan("quux").start()
AgentSpan thirdSpan = tracer.buildSpan("test", "quux").start()
AgentScope thirdScope = tracer.activateSpan(thirdSpan)
0 * _

Expand Down Expand Up @@ -724,7 +724,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "Closing a continued scope out of order cancels the continuation"() {
when:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def scope = tracer.activateSpan(span)
tracer.setAsyncPropagationEnabled(true)
def continuation = concurrent ? scope.captureConcurrent() : scope.capture()
Expand All @@ -741,7 +741,7 @@ class ScopeManagerTest extends DDCoreSpecification {
if (concurrent) {
continuation.cancel()
}
AgentSpan secondSpan = tracer.buildSpan("test2").start()
AgentSpan secondSpan = tracer.buildSpan("test", "test2").start()
AgentScope secondScope = (ContinuableScope) tracer.activateSpan(secondSpan)

then:
Expand Down Expand Up @@ -772,7 +772,7 @@ class ScopeManagerTest extends DDCoreSpecification {
tracer.addTraceInterceptor(interceptor)

when:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def scope = tracer.activateSpan(span)
scope.close()
span.finish()
Expand All @@ -787,7 +787,7 @@ class ScopeManagerTest extends DDCoreSpecification {
writer == [[span]]

when: "completing another scope lifecycle"
def span2 = tracer.buildSpan("test").start()
def span2 = tracer.buildSpan("test", "test").start()
def scope2 = tracer.activateSpan(span2)

then:
Expand All @@ -812,7 +812,7 @@ class ScopeManagerTest extends DDCoreSpecification {
tracer.addTraceInterceptor(interceptor)

when:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def scope = tracer.activateSpan(span)
tracer.setAsyncPropagationEnabled(true)
def continuation = concurrent ? scope.captureConcurrent() : scope.capture()
Expand All @@ -839,7 +839,7 @@ class ScopeManagerTest extends DDCoreSpecification {
writer == [[span]]

when: "completing another async scope lifecycle"
def span2 = tracer.buildSpan("test").start()
def span2 = tracer.buildSpan("test", "test").start()
def scope2 = tracer.activateSpan(span2)
tracer.setAsyncPropagationEnabled(true)
def continuation2 = concurrent ? scope2.captureConcurrent() : scope2.capture()
Expand Down Expand Up @@ -876,7 +876,7 @@ class ScopeManagerTest extends DDCoreSpecification {
long sendDelayNanos = TimeUnit.MILLISECONDS.toNanos(500 - 100)

when:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()
def start = System.nanoTime()
def scope = (ContinuableScope) tracer.activateSpan(span)
tracer.setAsyncPropagationEnabled(true)
Expand Down Expand Up @@ -918,7 +918,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "scope listener should be notified about the currently active scope"() {
setup:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()

when:
AgentScope scope = scopeManager.activate(span, ScopeSource.INSTRUMENTATION)
Expand Down Expand Up @@ -948,7 +948,7 @@ class ScopeManagerTest extends DDCoreSpecification {

def "extended scope listener should be notified about the currently active scope"() {
setup:
def span = tracer.buildSpan("test").start()
def span = tracer.buildSpan("test", "test").start()

when:
AgentScope scope = scopeManager.activate(span, ScopeSource.INSTRUMENTATION)
Expand Down Expand Up @@ -1001,15 +1001,15 @@ class ScopeManagerTest extends DDCoreSpecification {
scopeManager.addScopeListener(secondEventCountingListener)

when:
AgentSpan span = tracer.buildSpan("foo").start()
AgentSpan span = tracer.buildSpan("test", "foo").start()
AgentScope continuableScope = tracer.activateSpan(span)

then:
assertEvents([ACTIVATE])
secondEventCountingListener.events == [ACTIVATE]

when:
AgentSpan childSpan = tracer.buildSpan("foo").start()
AgentSpan childSpan = tracer.buildSpan("test", "foo").start()
AgentScope childDDScope = tracer.activateSpan(childSpan)

then:
Expand Down Expand Up @@ -1054,12 +1054,12 @@ class ScopeManagerTest extends DDCoreSpecification {
0 * profilingContext.onAttach()

when: "scopes activate on threads"
AgentSpan span = tracer.buildSpan("foo").start()
AgentSpan span = tracer.buildSpan("test", "foo").start()
def futures = new Future[numTasks]
for (int i = 0; i < numTasks; i++) {
futures[i] = executor.submit({
AgentScope scope = tracer.activateSpan(span)
def child = tracer.buildSpan("foo" + i).start()
def child = tracer.buildSpan("test", "foo" + i).start()
def childScope = tracer.activateSpan(child)
try {
Thread.sleep(100)
Expand Down
Loading
0