Skip to content

Restore instrumentation contexts without legacy scope APIs - #13454

Open
mcculls wants to merge 11 commits into
masterfrom
mcculls/cleanup-unscoped-contexts
Open

mcculls wants to merge 11 commits into
masterfrom
mcculls/cleanup-unscoped-contexts

Conversation

@mcculls

@mcculls mcculls commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Restore the caller's context after CI Visibility tests and suites, Karate steps, and AWS SDK requests when the non-legacy context manager is enabled. Handle nested tests and suites ending out of order, vetoed Karate steps, and asynchronous AWS signing without leaving the wrong context active.

For MongoDB DBM, hand command spans from connection advice to the command listener without activating them. Build DBM metadata from the command span explicitly, and finish unclaimed spans when the driver exits before command-start notification, including serialization failures.

Make closing the deprecated OpenTracing ScopeManager.active() view leave the context intact and warn once in non-legacy mode. Callers must close the scope returned by activation. Preserve legacy closure behavior.

Remove the static AgentTracer.activateSpanWithoutScope and AgentTracer.closeActive shortcuts, update their callers, and document the retained instance methods as deprecated, legacy-only scope management.

Motivation

Continue migrating instrumentation away from implicit scope-stack activation and closure. Explicitly restore the context each integration owns so cleanup does not close another operation's scope or leak a request context into later work.

Additional Notes

  • Non-legacy CI Visibility cleanup restores the saved context without finishing outstanding application spans. Legacy cleanup retains its existing behavior.
  • Keep compatibility choices local to each integration while the legacy paths remain supported.
  • Add regressions for context restoration, nested and repeated completion, Karate step vetoes and cold-start retries, AWS asynchronous signing, Mongo span handoff and serialization failures, and OpenTracing active-view closure. Isolate concurrent Karate test reports and include the Mongo DBM test dependency locks.
  • Local validation: all 89 Karate 2.0 tests passed on JDK 21; both cold-start retry tests also passed on OpenJ9 JDK 21. Karate 2.0 formatting checks passed.

@mcculls mcculls added tag: no release notes Changes to exclude from release notes type: refactoring comp: context propagation Trace context propagation tag: ai generated Largely based on code generated by an AI or LLM labels Nov 13, 2026
@mcculls
mcculls added this pull request to stack #13397 November 13, 2026 22:47
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 92.41%
• Overall Coverage: 59.87% (-1.52%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 85b0067 | Docs | Give us feedback!

@pr-commenter

pr-commenter Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Debugger benchmarks

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
ci_job_date 1794780659 1794780975
end_time 2026-11-15T22:12:27 2026-11-15T22:17:43
git_branch master mcculls/cleanup-unscoped-contexts
git_commit_sha e8e4235 ffe2e21
start_time 2026-11-15T22:11:00 2026-11-15T22:16:16
See matching parameters
Baseline Candidate
ci_job_id 2255929530 2255929530
ci_pipeline_id 153369329 153369329
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
git_commit_date 1794779748 1794779748

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 9 metrics, 6 unstable metrics.

See unchanged results
scenario Δ mean agg_http_req_duration_min Δ mean agg_http_req_duration_p50 Δ mean agg_http_req_duration_p75 Δ mean agg_http_req_duration_p99 Δ mean throughput
scenario:noprobe unstable
[-19.750µs; +22.274µs] or [-6.261%; +7.062%]
unstable
[-33288.697ns; +33472.163ns] or [-9.547%; +9.599%]
unstable
[-43079.114ns; +42355.580ns] or [-11.862%; +11.663%]
unstable
[-130.460µs; +68.223µs] or [-11.007%; +5.756%]
same
scenario:basic same same same unstable
[-128.505µs; +119.332µs] or [-11.277%; +10.472%]
unstable
[-123.470op/s; +123.470op/s] or [-5.309%; +5.309%]
scenario:loop same same same same same
Request duration reports for reports
gantt
    title reports - request duration [CI 0.99] : candidate=None, baseline=None
    dateFormat X
    axisFormat %s
section baseline
noprobe (348.691 µs) : 317, 381
.   : milestone, 349,
basic (321.812 µs) : 317, 327
.   : milestone, 322,
loop (7.57 ms) : 7564, 7576
.   : milestone, 7570,
section candidate
noprobe (348.782 µs) : 317, 380
.   : milestone, 349,
basic (322.486 µs) : 317, 328
.   : milestone, 322,
loop (7.57 ms) : 7564, 7576
.   : milestone, 7570,
Loading
  • baseline results
Scenario Request median duration [CI 0.99]
noprobe 348.691 µs [316.621 µs, 380.761 µs]
basic 321.812 µs [316.523 µs, 327.101 µs]
loop 7.57 ms [7.564 ms, 7.576 ms]
  • candidate results
Scenario Request median duration [CI 0.99]
noprobe 348.782 µs [317.426 µs, 380.139 µs]
basic 322.486 µs [317.12 µs, 327.852 µs]
loop 7.57 ms [7.564 ms, 7.576 ms]

@dd-octo-sts

dd-octo-sts Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.88 s 14.64 s [+0.8%; +2.5%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.65 s 13.79 s [-1.7%; -0.4%] (maybe better)
startup:petclinic:appsec:Agent 17.86 s 17.70 s [-0.0%; +1.9%] (no difference)
startup:petclinic:iast:Agent 17.66 s 17.69 s [-1.2%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 17.49 s 16.92 s [-1.1%; +7.9%] (no difference)
startup:petclinic:sca:Agent 17.89 s 17.78 s [-0.3%; +1.5%] (no difference)
startup:petclinic:tracing:Agent 16.86 s 16.95 s [-1.4%; +0.3%] (no difference)

Commit: 85b00678 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from 6f92b15 to 065a236 Compare November 14, 2026 20:18
@pr-commenter

pr-commenter Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master mcculls/cleanup-unscoped-contexts
git_commit_date 1796080420 1796085647
git_commit_sha a522d44 85b0067
See matching parameters
Baseline Candidate
ci_job_date 1796086974 1796086974
ci_job_id 2313200602 2313200602
ci_pipeline_id 157093339 157093339
cpu_model Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-ek8opdze 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-ek8opdze 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaProduceBenchmark.benchProduce same

@pr-commenter

pr-commenter Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master mcculls/cleanup-unscoped-contexts
git_commit_date 1796080420 1796085647
git_commit_sha a522d44 85b0067
See matching parameters
Baseline Candidate
ci_job_date 1796087002 1796087002
ci_job_id 2313200603 2313200603
ci_pipeline_id 157093339 157093339
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-9yndu1b5 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-9yndu1b5 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume same

@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from 065a236 to 3d8e54f Compare November 15, 2026 14:21
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch 2 times, most recently from b668a33 to ffe2e21 Compare November 15, 2026 21:59
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from ffe2e21 to f3d5901 Compare November 16, 2026 23:56
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from f3d5901 to 54d3643 Compare November 18, 2026 19:48
@mcculls
mcculls removed this pull request from stack #13397 November 19, 2026 09:27
@mcculls
mcculls added this pull request to stack #13545 November 19, 2026 09:27
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from 54d3643 to c58fbaa Compare November 20, 2026 17:48
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from c58fbaa to dbe14d7 Compare November 20, 2026 21:32
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot requested a review from a team as a code owner November 26, 2026 17:19
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot force-pushed the mcculls/cleanup-unscoped-contexts branch from 5ad9c27 to 492e3f8 Compare November 26, 2026 17:19

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Static review identified no reportable issue in context restoration or Mongo span handoff. Runtime behavior under the legacy and non-legacy context managers was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 492e3f8

@mcculls
mcculls requested a review from cecile75 November 26, 2026 18:50
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from 2b301df to 70a7230 Compare November 27, 2026 09:24

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The static reviewer identified no actionable defects. AWS dependency-version compatibility was assessed from repository evidence only, and runtime behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 70a7230

@genesor genesor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@gh-worker-ownership-write-b05516
gh-worker-ownership-write-b05516 Bot removed the request for review from a team November 27, 2026 18:21
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from daeeec1 to dada4be Compare November 27, 2026 18:30

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Closing OpenTracing’s deprecated active-scope view intentionally preserves the non-legacy context; callers must close the scope returned by activation. Static inspection found no actionable defects, but runtime restoration behavior was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit dada4be

@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from dada4be to 4becd5d Compare November 27, 2026 18:43

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Static review identified no actionable defects in context restoration or Mongo span handoff. Runtime tests were not executed, and production telemetry was explicitly excluded.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 4becd5d

@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from 4becd5d to c43d6ff Compare November 27, 2026 18:53

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The static review found no actionable defects in context restoration or span handoff. Closing OpenTracing’s deprecated active-scope view intentionally leaves the context intact under the non-legacy manager; callers must close the scope returned by activation.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit c43d6ff

…sure

Remove the static activateSpanWithoutScope and closeActive helpers and
route callers through TracerAPI. Categorize the retained instance
methods as deprecated scope management supported only in legacy mode.
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from c43d6ff to 8cc6eab Compare December 1, 2026 00:13
@mcculls
mcculls requested a review from a team as a code owner December 1, 2026 00:13

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Static review identified no reportable defect in context restoration or Mongo span ownership. Runtime behavior remains unverified because builds and tests were not run.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 8cc6eab

Save and restore test, suite, and Karate step contexts with context handles.
Keep nested CI activations restorable when they end out of order, clean up
vetoed Karate steps, and preserve cold-start retry instrumentation.

Include context restoration, step veto, and cold-start retry regressions.

Isolate paired Karate test reports by worker and wait for runner cleanup
so concurrent forks cannot interfere. Preserve underlying JUnit failure
causes.
Restore AWS SDK v1 request contexts at execution exit and keep SDK v2
legacy scope advice separate from context restoration advice. Preserve
async signing contexts and retain the legacy scope lifecycle.

Include request restoration, async signing, missing-context, and legacy
client regressions.
Use MongoPendingSpan to hand command spans from connection advice to the
command listener without changing the active context. Create a command
span when no pending span is available and inject the helper into all
supported driver instrumentation modules.

Include helper and async DBM handoff regressions for both context managers,
with the corresponding test suite configuration and dependency locks.
Keep ScopeManager.active().close() as an active-span view in non-legacy
mode and warn once that callers must close the scope returned by activate.
Preserve legacy closure and strict-mode checks across both instrumented
OpenTracing versions and the compatibility library.

Include active-view closure regressions for all three implementations.
@mcculls
mcculls force-pushed the mcculls/cleanup-unscoped-contexts branch from 8cc6eab to 85b0067 Compare December 1, 2026 00:45

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The deprecated OpenTracing active-scope view intentionally leaves non-legacy contexts intact; callers must close the scope returned by activation. Runtime context restoration remains unverified because tests were not executed and production telemetry was excluded.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 85b0067

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: context propagation Trace context propagation tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes tag: override pr size check Override the "pull request size" check type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants