Skip to content

Make native span ownership exception-safe - #6128

Merged
lloeki merged 1 commit into
masterfrom
lloeki/native-span-exception-safety-foundation
Aug 4, 2026
Merged

Make native span ownership exception-safe#6128
lloeki merged 1 commit into
masterfrom
lloeki/native-span-exception-safety-foundation

Conversation

@lloeki

@lloeki lloeki commented Jul 30, 2026

Copy link
Copy Markdown
Member

AI-generated code disclosure: this PR was implemented with substantial AI assistance and manually reviewed and validated.

What does this PR do?

Makes raw native span ownership exception-safe across Ruby non-local exits, TypedData wrapping, batch transfer, warning and hash mutation paths, partial batches, and exporter configuration and runtime setup.

Motivation:

Ruby exceptions and non-local exits can interrupt native ownership transfer and leak or double-release spans unless every transition has an explicit cleanup path. This is the internal safety work tracked by APMSP-3829.

Change log entry

No.

Additional Notes:

How to test the change?

  • Ran the native transport suite against libdatadog 36: 117 examples, 0 failures, covering allocation, wrapping, transfer, partial-batch, warning, hash mutation, configuration, and runtime failure paths.
  • Ran the focused ruby_memcheck suite under Valgrind: 34 examples, 0 failures, with no reported leaks.
  • Ran Standard and Steep successfully.

Keep each raw `ddog_TracerSpan` under an ensure-backed owner until
`TypedData` or trace chunks consume it. This prevents Ruby non-local
exits during meta and metrics conversion or partial batch construction
from leaking native spans.

Apply fallible exporter configuration before creating the separately
owned shared runtime so rejected configuration cannot leak it.

Refs: APMSP-3829
@lloeki lloeki added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Jul 30, 2026
@lloeki
lloeki requested review from a team as code owners July 30, 2026 11:48
@lloeki
lloeki requested review from mabdinur and wantsui July 30, 2026 11:48
@dd-octo-sts

dd-octo-sts Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thank you for updating Change log entry section 👏

Visited at: 2026-07-30 12:12:06 UTC

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Jul 30, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 90.01% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 853a676 | Docs | Datadog PR Page | Give us feedback!

@pr-commenter

pr-commenter Bot commented Jul 30, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-30 12:26:03

Comparing candidate commit 853a676 in PR branch lloeki/native-span-exception-safety-foundation with baseline commit 0a15637 in branch master.

📊 Benchmarking dashboard

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:tracing - trace.to_digest - Continue

  • unstable throughput [-1478.841op/s; +1545.967op/s] or [-5.033%; +5.261%]

@lloeki
lloeki merged commit c8d374e into master Aug 4, 2026
605 checks passed
@lloeki
lloeki deleted the lloeki/native-span-exception-safety-foundation branch August 4, 2026 13:57
@dd-octo-sts dd-octo-sts Bot added this to the 2.41.0 milestone Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants