Skip to content

refactor: migrate Context to native - #19712

Draft
emmettbutler wants to merge 1 commit into
mainfrom
emmett.butler/native-context
Draft

refactor: migrate Context to native#19712
emmettbutler wants to merge 1 commit into
mainfrom
emmett.butler/native-context

Conversation

@emmettbutler

Copy link
Copy Markdown
Collaborator

No description provided.

@emmettbutler
emmettbutler requested review from a team as code owners August 14, 2026 23:44
@emmettbutler
emmettbutler marked this pull request as draft August 14, 2026 23:44
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/_trace/context.py                                               @DataDog/apm-sdk-capabilities-python
ddtrace/internal/native/_native.pyi                                     @DataDog/apm-core-python
src/native/context/context_data.rs                                      @DataDog/apm-core-python
src/native/context/mod.rs                                               @DataDog/apm-core-python
src/native/context_provider.rs                                          @DataDog/apm-core-python
src/native/lib.rs                                                       @DataDog/apm-core-python
src/native/span/span_data.rs                                            @DataDog/apm-core-python
tests/tracer/test_context.py                                            @DataDog/apm-sdk-capabilities-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 5 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.contrib.internal.pytorch._distributed -> ddtrace.contrib.internal.pytorch._rank_root -> ddtrace.contrib.internal.pytorch._distributed
ddtrace.contrib.internal.django.patch -> ddtrace.contrib.internal.django.response -> ddtrace.contrib.internal.django.patch
ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 255 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 255 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=134)
ddtrace.internal.test_visibility.api -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=132)
ddtrace.internal.openfeature._span_enrichment -×-> ddtrace.trace  (product:openfeature -> product:tracing, score=132)
ddtrace.llmobs._integrations.claude_agent_sdk -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.aiguard._api_client -×-> ddtrace.trace  (product:aiguard -> product:tracing, score=132)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

🚦 12 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v126532274-233089d-musllinux_1_2_x86_64, 1]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741357-d2b8243-manylinux2014_aarch64, 1]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-py | build linux: [amd64, cp315-cp315, v113741238-d2b8243-manylinux2014_x86_64]   View in Datadog   GitLab

View all 12 failed jobs.

❄️ 4 New flaky tests detected

test_context_baggage_cycle_is_collectable[py3.11] from test_context.py   View in Datadog
assert 5 == 9
 +  where 5 = _count_objects_of_type('Context')

New test introduced in this PR is flaky.

test_context_baggage_cycle_is_collectable[py3.12] from test_context.py   View in Datadog
assert 96 == 203
 +  where 96 = _count_objects_of_type('Context')

New test introduced in this PR is flaky.

View in Flaky Test Management

ℹ️ Info

No other issues found (see more)

🧪 All tests passed

Useful? React with 👍 / 👎

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38ef60bfe1

ℹ️ 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".

"""Cycles formed via `_baggage` must be reclaimed by `gc.collect()`."""
import gc

initial = _count_objects_of_type("Context")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Collect pre-existing cycles before taking the baseline

When an earlier test leaves any unreachable object named Context in a reference cycle, this baseline includes it, but the later gc.collect() frees it alongside the 200 cycles created here. The final exact comparison then observes fewer objects than initial and fails depending on suite order and GC timing; collect before recording the baseline or track only the contexts created by this test.

Useful? React with 👍 / 👎.

@pr-commenter

pr-commenter Bot commented Aug 15, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-15 00:14:29

Comparing candidate commit 38ef60b in PR branch emmett.butler/native-context with baseline commit 3e902cc in branch main.

📊 Benchmarking dashboard

Found 14 performance improvements and 14 performance regressions! Performance is the same for 588 metrics, 10 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 ----------------------------------'

scenario:httppropagationextract-empty_headers

  • 🟩 execution_time [-350.628ns; -335.177ns] or [-26.726%; -25.549%]

scenario:httppropagationextract-invalid_priority_header

  • 🟩 execution_time [-657.173ns; -624.519ns] or [-11.058%; -10.509%]

scenario:httppropagationextract-invalid_span_id_header

  • 🟩 execution_time [-659.586ns; -615.597ns] or [-11.101%; -10.361%]

scenario:httppropagationextract-invalid_tags_header

  • 🟩 execution_time [-691.171ns; -636.907ns] or [-11.589%; -10.679%]

scenario:httppropagationextract-invalid_trace_id_header

  • 🟩 execution_time [-634.559ns; -587.631ns] or [-10.681%; -9.891%]

scenario:httppropagationextract-none_propagation_style

  • 🟩 execution_time [-344.974ns; -328.437ns] or [-24.728%; -23.542%]

scenario:httppropagationextract-valid_headers_all

  • 🟩 execution_time [-658.454ns; -613.226ns] or [-11.063%; -10.303%]

scenario:httppropagationextract-valid_headers_basic

  • 🟩 execution_time [-702.205ns; -667.269ns] or [-12.636%; -12.007%]

scenario:httppropagationextract-wsgi_empty_headers

  • 🟩 execution_time [-336.541ns; -320.248ns] or [-25.695%; -24.451%]

scenario:httppropagationextract-wsgi_invalid_priority_header

  • 🟩 execution_time [-631.463ns; -584.252ns] or [-10.566%; -9.776%]

scenario:httppropagationextract-wsgi_invalid_span_id_header

  • 🟩 execution_time [-328.263ns; -311.432ns] or [-25.120%; -23.832%]

scenario:httppropagationextract-wsgi_invalid_tags_header

  • 🟩 execution_time [-629.493ns; -591.525ns] or [-10.514%; -9.880%]

scenario:httppropagationextract-wsgi_invalid_trace_id_header

  • 🟩 execution_time [-631.549ns; -578.937ns] or [-10.563%; -9.683%]

scenario:httppropagationextract-wsgi_valid_headers_basic

  • 🟩 execution_time [-644.157ns; -602.137ns] or [-11.614%; -10.856%]

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+4.811µs; +5.015µs] or [+22.844%; +23.814%]

scenario:httppropagationinject-with_all

  • 🟥 execution_time [+2.668µs; +2.909µs] or [+9.399%; +10.248%]

scenario:httppropagationinject-with_dd_origin

  • 🟥 execution_time [+2.576µs; +2.792µs] or [+10.387%; +11.260%]

scenario:httppropagationinject-with_priority_and_origin

  • 🟥 execution_time [+2.609µs; +2.856µs] or [+10.580%; +11.582%]

scenario:httppropagationinject-with_sampling_priority

  • 🟥 execution_time [+2.274µs; +2.467µs] or [+10.566%; +11.465%]

scenario:httppropagationinject-with_tags

  • 🟥 execution_time [+2.446µs; +2.689µs] or [+9.450%; +10.389%]

scenario:httppropagationinject-with_tags_invalid

  • 🟥 execution_time [+2.211µs; +2.426µs] or [+8.085%; +8.872%]

scenario:httppropagationinject-with_tags_max_size

  • 🟥 execution_time [+2.422µs; +2.686µs] or [+9.226%; +10.231%]

scenario:iastaspects-lstrip_aspect

  • 🟥 execution_time [+35.748µs; +44.537µs] or [+12.471%; +15.537%]

scenario:iastaspects-modulo_noaspect

  • 🟥 execution_time [+41.312µs; +46.334µs] or [+12.297%; +13.792%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+126.609µs; +135.743µs] or [+31.334%; +33.594%]

scenario:span-start

  • 🟥 execution_time [+1.308ms; +1.484ms] or [+8.574%; +9.725%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+508.275ns; +542.874ns] or [+19.280%; +20.593%]

scenario:tracer-small

  • 🟥 execution_time [+34.447µs; +37.036µs] or [+10.164%; +10.928%]

Unstable benchmarks

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

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-837.457ns; +648.883ns] or [-7.574%; +5.869%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-32.716ns; +33.320ns] or [-5.335%; +5.434%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1707.656ns; +1599.435ns] or [-9.984%; +9.351%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1111.167ns; +1383.291ns] or [-8.583%; +10.686%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-343.981ns; +310.562ns] or [-9.342%; +8.435%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-280.392ns; +230.881ns] or [-9.551%; +7.865%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-82.924ns; +62.891ns] or [-6.983%; +5.296%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4018.111ns; +4035.331ns] or [-9.846%; +9.888%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-923.868ns; +626.592ns] or [-11.224%; +7.612%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-58.055µs; +63.083µs] or [-9.110%; +9.899%]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant