Deprecate AgentScope.Continuation and migrate call sites to ContextContinuation#11951
Deprecate AgentScope.Continuation and migrate call sites to ContextContinuation#11951mcculls wants to merge 2 commits into
Conversation
…for proper swapping over to ThreadLocalContextManager.
…ntinuation AgentScope.Continuation was a bridging interface that extended both TraceScope.Continuation (public API) and ContextContinuation (modern context API). It is now @deprecated — internal call sites migrate to ContextContinuation directly. Key changes: - AgentScope.Continuation marked @deprecated - AgentTraceCollector.register/removeContinuation now accept ContextContinuation - AgentTracer.captureActiveSpan()/captureSpan() static methods return ContextContinuation (implementations still return AgentScope.Continuation for Tracer interface compat) - ScopeContinuation gains resume()/release() for the ContextContinuation contract - State, ConcurrentState, Wrapper, VirtualThreadState, AdviceUtils, TPEHelper all migrated from AgentScope.Continuation to ContextContinuation/ContextScope - ~85 instrumentation files updated: field types use ContextContinuation, activate()→resume(), cancel()→release(), scope types use ContextScope Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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: 4041cbed27
ℹ️ 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".
| StaticEventLogger.end("crashtracking"); | ||
| } | ||
|
|
||
| if (InstrumenterConfig.get().isLegacyContextManagerEnabled()) { |
There was a problem hiding this comment.
Preserve async propagation when legacy context is off
When DD_LEGACY_CONTEXT_MANAGER_ENABLED=false, this branch leaves Context.current() backed by the default ThreadLocalContextManager while AgentTracer.activeSpan()/captureActiveSpan() still read the ContinuableScopeManager. Context-tracking server advice attaches request spans with context.attach(), but executor propagation still captures via AdviceUtils.capture() → activeSpan(), so a request that submits work to an executor in non-legacy mode will see activeSpan == null and lose the parent span. Before this change the scope manager registered as the ContextManager, so those two views stayed in sync.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is the first step in a series of migrations, split into several PRs to help with reviewing - this particular concern is addressed in a later PR which refactors AgentTracer internals. The important thing in this PR is that the legacy=true behaviour is not disturbed.
| */ | ||
| @Nonnull | ||
| public static AgentScope.Continuation captureActiveSpan() { | ||
| public static ContextContinuation captureActiveSpan() { |
There was a problem hiding this comment.
Preserve AgentTracer capture helper descriptors
Changing the public static helper return type removes the old JVM descriptor captureActiveSpan():AgentScope$Continuation; any precompiled custom instrumentation or extension compiled against the existing bootstrap API will now fail with NoSuchMethodError, and source assigning the result to AgentScope.Continuation no longer compiles. The same applies to captureSpan below, and keeping the old covariant return type would still let migrated internal call sites store the result as ContextContinuation because AgentScope.Continuation extends it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is internal API with no binary compatibility guarantees so we can (and should) change the type to remove dependency on a deprecated type.
| public ContextScope attach(Context context) { | ||
| return noopScope(); |
There was a problem hiding this comment.
Keep Context attach functional without a tracer
When tracing and CI Visibility are disabled, TracerInstaller leaves AgentTracer as the no-op tracer while context-tracking instrumentations are still installed; with the new legacy ContextManager shim, Context.attach() then delegates here and gets a NoopScope, so Context.current() remains root and any non-tracing context propagation is dropped. The no-op tracer needs to preserve the normal thread-local Context behavior, or the shim should only be installed once a real tracer exists.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The legacy behaviour is that methods become "no-ops" when no tracer is installed.
Once migration to the Context API is complete(and legacy=false) we will no longer have that restriction because the context propagation will be fully independent of the tracer. We don't need to support this feature in legacy mode though because the goal is for legacy mode to go away.
There was a problem hiding this comment.
More details
The migration is behaviorally faithful: resume()/release() in ScopeContinuation are the new primary implementations with activate()/cancel() delegating to them, the (AgentScope) resume() cast is safe (both return paths give ContinuableScope or NoopScope), and ContinuableScopeManager's explicit installLegacyContextManager() call is correctly wired in Agent bootstrap, native-image activation, and all test bases. Two SQS test classes covering the non-legacy path are intentionally @Disabled pending the broader migration (APMLP-829).
📊 Validated against 23 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit 4041cbe · What is Autotest? · Any feedback? Reach out in #autotest
🟢 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. |
Kafka / consumer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 1 performance regressions! Performance is the same for 2 metrics, 0 unstable metrics.
See unchanged results
|
What Does This Do
Motivation
AgentScope.Continuation mixes a legacy public-API contract with the modern context API, forcing internal code to depend on a bridging type it doesn't need. Moving internal call sites onto ContextContinuation directly clears the path to eventually removing the legacy interface, without changing behavior.
Additional Notes
This is a mechanical migration with no intended behavior change — AgentScope.Continuation remains available (deprecated) for public API / Tracer interface compatibility. No release note required.
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]