Add AgentSpan.captureWithContext() and start removing deprecated internal scope API - #12285
Add AgentSpan.captureWithContext() and start removing deprecated internal scope API#12285mcculls wants to merge 5 commits into
AgentSpan.captureWithContext() and start removing deprecated internal scope API#12285Conversation
|
@codex review |
There was a problem hiding this comment.
Pull request overview
This PR extends the tracer/context propagation API by introducing AgentSpan.captureWithContext() and migrating call sites away from deprecated internal scope-continuation APIs toward Context.current().capture() / span-based capture. It also removes the deprecated internal AgentScope.Continuation type and related plumbing.
Changes:
- Add
AgentSpan.captureWithContext()(and documentAgentSpan.capture()as span-only capture) to support context+span continuation capture. - Replace usages of
AgentTracer.captureActiveSpan()/captureSpan(span)across core + instrumentations withContext.current().capture()andspan.captureWithContext(). - Remove deprecated internal continuation APIs (
AgentScope.Continuation,ContinuableScopeManager.capture*, CoreTracer overrides), and adapt deprecatedTraceScope.Continuationvia a wrapper.
Reviewed changes
Copilot reviewed 46 out of 46 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/NoopScope.java | Removes deprecated continuation capture override from noop scope. |
| internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/NoopContinuation.java | Reworks noop continuation to implement ContextContinuation directly. |
| internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/java/lang/ProcessImplInstrumentationHelpers.java | Switches async continuation capture to Context.current().capture(). |
| internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentTracer.java | Removes deprecated capture APIs and adds a deprecated TraceScope.Continuation adapter wrapper. |
| internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentSpan.java | Adds captureWithContext() and clarifies span-only vs span+context capture behavior. |
| internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentScope.java | Drops deprecated AgentScope.Continuation internal type. |
| dd-trace-core/src/test/java/datadog/trace/core/scopemanager/ScopeManagerForkedTest.java | Migrates tests to Context.current().capture() and span.captureWithContext(). |
| dd-trace-core/src/test/java/datadog/trace/core/PendingTraceTest.java | Updates test to use Context.current().capture() in place of tracer capture API. |
| dd-trace-core/src/test/java/datadog/trace/core/PendingTraceStrictWriteTest.java | Updates strict-write tests to use Context.current().capture(). |
| dd-trace-core/src/test/java/datadog/trace/core/PendingTraceBufferTest.java | Switches buffered continuation capture to span.captureWithContext(). |
| dd-trace-core/src/main/java/datadog/trace/core/scopemanager/ScopeContinuation.java | Switches continuation implementation from deprecated agent continuation type to ContextContinuation. |
| dd-trace-core/src/main/java/datadog/trace/core/scopemanager/ContinuableScopeManager.java | Removes deprecated captureActiveSpan() / captureSpan() APIs in favor of context API. |
| dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java | Removes now-unused overrides for deprecated capture APIs. |
| dd-java-agent/instrumentation/zio/zio-2.0/src/main/java/datadog/trace/instrumentation/zio/v2_0/FiberContext.java | Captures ContextContinuation from stored Context instead of deprecated tracer API. |
| dd-java-agent/instrumentation/vertx/vertx-sql-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_sql_client_39/QueryAdvice.java | Migrates parent continuation capture to parentSpan.captureWithContext(). |
| dd-java-agent/instrumentation/vertx/vertx-sql-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_sql_client_39/CursorReadAdvice.java | Migrates parent continuation capture to parentSpan.captureWithContext(). |
| dd-java-agent/instrumentation/vertx/vertx-redis-client/vertx-redis-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_redis_client/RedisSendAdvice.java | Switches parent continuation capture to span/context-based capture. |
| dd-java-agent/instrumentation/vertx/vertx-redis-client/vertx-redis-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_redis_client/RedisFutureSendAdvice.java | Switches parent continuation capture to span/context-based capture for futures. |
| dd-java-agent/instrumentation/vertx/vertx-redis-client/vertx-redis-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_redis_client/RedisAPICallAdvice.java | Switches parent continuation capture to span/context-based capture for Redis API calls. |
| dd-java-agent/instrumentation/undertow/undertow-2.0/src/main/java/datadog/trace/instrumentation/undertow/UndertowRunnableWrapper.java | Migrates runnable wrapper continuation capture to Context.current().capture(). |
| dd-java-agent/instrumentation/undertow/undertow-2.0/src/main/java/datadog/trace/instrumentation/undertow/HandlerInstrumentation.java | Captures continuation via span.captureWithContext() for exchange lifecycle. |
| dd-java-agent/instrumentation/synapse-3.0/src/main/java/datadog/trace/instrumentation/synapse3/SynapseServerWorkerInstrumentation.java | Uses Java8BytecodeBridge.currentContext().capture() for worker propagation. |
| dd-java-agent/instrumentation/synapse-3.0/src/main/java/datadog/trace/instrumentation/synapse3/SynapseClientWorkerInstrumentation.java | Uses Java8BytecodeBridge.currentContext().capture() for worker propagation. |
| dd-java-agent/instrumentation/spring/spring-scheduling-3.1/src/main/java/datadog/trace/instrumentation/springscheduling/SpringAsyncAdvice.java | Migrates async scheduling capture to currentContext().capture(). |
| dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.56/src/test/groovy/ContextPreservingInstrumentationTest.groovy | Updates tests to use Context.current().capture() instead of tracer capture API. |
| dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.0/src/test/groovy/ContextPreservingInstrumentationTest.groovy | Updates tests to use Context.current().capture() instead of tracer capture API. |
| dd-java-agent/instrumentation/redisson/redisson-3.10.3/src/main/java/datadog/trace/instrumentation/redisson30/RedissonInstrumentation.java | Migrates promise completion continuation capture to span.captureWithContext(). |
| dd-java-agent/instrumentation/redisson/redisson-2.3.0/src/main/java/datadog/trace/instrumentation/redisson23/RedissonInstrumentation.java | Migrates listener continuation capture to span.captureWithContext(). |
| dd-java-agent/instrumentation/redisson/redisson-2.0.0/src/main/java/datadog/trace/instrumentation/redisson/RedissonInstrumentation.java | Migrates listener continuation capture to span.captureWithContext(). |
| dd-java-agent/instrumentation/play-ws/play-ws-2.1/src/main/java/datadog/trace/instrumentation/playws21/AsyncHandlerWrapper.java | Switches handler wrapper continuation capture to span.captureWithContext(). |
| dd-java-agent/instrumentation/play-ws/play-ws-2.0/src/main/java/datadog/trace/instrumentation/playws2/AsyncHandlerWrapper.java | Switches handler wrapper continuation capture to span.captureWithContext(). |
| dd-java-agent/instrumentation/play-ws/play-ws-1.0/src/main/java/datadog/trace/instrumentation/playws1/AsyncHandlerWrapper.java | Switches handler wrapper continuation capture to span.captureWithContext(). |
| dd-java-agent/instrumentation/netty/netty-promise-4.0/src/main/java/datadog/trace/instrumentation/netty4/promise/ListenerWrapper.java | Migrates netty listener wrapper continuation capture to Context.current().capture(). |
| dd-java-agent/instrumentation/netty/netty-4.1/src/main/java/datadog/trace/instrumentation/netty41/NettyChannelPipelineInstrumentation.java | Uses currentContext().capture() for connect continuation propagation. |
| dd-java-agent/instrumentation/netty/netty-4.0/src/main/java/datadog/trace/instrumentation/netty40/NettyChannelPipelineInstrumentation.java | Uses currentContext().capture() for connect continuation propagation. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/NettyChannelInstrumentation.java | Uses currentContext().capture() for connect continuation propagation. |
| dd-java-agent/instrumentation/mongo/mongo-driver/mongo-driver-4.0/src/main/java/datadog/trace/instrumentation/mongo/CallbackWrapper.java | Migrates callback wrapper continuation capture to Context.current().capture(). |
| dd-java-agent/instrumentation/kotlin-coroutines-1.3/src/main/java/datadog/trace/instrumentation/kotlin/coroutines/DatadogThreadContextElement.java | Captures continuation from stored Context instead of deprecated tracer capture. |
| dd-java-agent/instrumentation/jetty/jetty-server/jetty-server-12.0/src/main/java17/datadog/trace/instrumentation/jetty12/JettyRunnableWrapper.java | Migrates runnable wrapper continuation capture to Context.current().capture(). |
| dd-java-agent/instrumentation/java/java-net/java-net-11.0/src/main/java11/datadog/trace/instrumentation/httpclient/BodyHandlerWrapper.java | Migrates body handler wrapper continuation capture to span.captureWithContext(). |
| dd-java-agent/instrumentation/java/java-lang/java-lang-21.0/src/main/java/datadog/trace/instrumentation/java/lang/jdk21/VirtualThreadInstrumentation.java | Uses currentContext() + context.capture() for virtual thread propagation. |
| dd-java-agent/instrumentation/axis2-1.3/src/main/java/datadog/trace/instrumentation/axis2/AxisEngineInstrumentation.java | Migrates Axis2 continuation storage to span.captureWithContext(). |
| dd-java-agent/instrumentation/apache-httpclient/apache-httpclient-5.0/src/main/java/datadog/trace/instrumentation/apachehttpclient5/ApacheHttpAsyncClientInstrumentation.java | Migrates async client parent continuation capture to currentContext().capture(). |
| dd-java-agent/instrumentation/apache-httpclient/apache-httpasyncclient-4.0/src/main/java/datadog/trace/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientInstrumentation.java | Migrates async client parent continuation capture to currentContext().capture(). |
| dd-java-agent/instrumentation/aerospike-4.0/src/main/java/datadog/trace/instrumentation/aerospike4/AerospikeClientInstrumentation.java | Migrates listener continuation capture to span.captureWithContext(). |
| dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/Wrapper.java | Migrates bootstrap runnable wrapper to Context.current().capture(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0310c1f455
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
f3753e0 to
2f46bce
Compare
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
…tion This captures a combination of the span with the current context so it can be resumed in another execution unit. Note: if this combination is alrady active the existing check in IndexedContent avoids allocating a new Context. ( this is the equivalent of attachWithContext() but for capturing, not attaching )
…pan(span) to span.captureWithContext()
…apper around Context.current().capture()
2f46bce to
fe5a608
Compare
What Does This Do
Add
AgentSpan.captureWithContext()to help with further context migrationThis captures a combination of the span with the current context so it can be resumed in another execution unit.
Note: if this combination is alrady active the existing check in
IndexedContentavoids allocating a newContext.( this is the equivalent of
attachWithContext()but for capturing, not attaching )Migrate
captureActiveSpan()toContext.current().capture()Migrate
captureSpan(span)tospan.captureWithContext()Remove unused
AgentTracer.TracerAPI.captureSpan(span)Replace
AgentTracer.TracerAPI.captureActiveSpan()with thin wrapper aroundContext.current().capture()Drop deprecated
AgentScope.Continuationtype (internal API)Motivation
Cleaning up and removing deprecated internal API
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]