Skip to content

chore(native): declare PyContextVar_* locally for limited-API builds (PROF-15850) - #19903

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
vlad/py315-pyo3-contextvar
Sep 4, 2026
Merged

chore(native): declare PyContextVar_* locally for limited-API builds (PROF-15850)#19903
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
vlad/py315-pyo3-contextvar

Conversation

@vlad-scherbich

@vlad-scherbich vlad-scherbich commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

Limited-API shims so native builds compile under Py_LIMITED_API.

  • src/native/contextvar.rs declares PyContextVar_New / _Get / _Set locally; pyo3-ffi omits them.
  • src/native/crashtracker/crashtracker_runtime_stacks.rs skips PyGILState_Check on limited-API (not in the stable ABI; Ensure is not signal-safe).
  • // instead of /// on the extern block so rustc does not doctest it.

Does not schedule 3.15 riot, widen requires-python, or change wheel publish.

Testing

Native crate compiles with the local declarations.

Risks

None.

Additional Notes

Base: main. Unofficial next: #19267. Profiling next: #19269.

No release note: internal FFI, changelog/no-changelog.

Contributes to #17817

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 26f0728 | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Aug 27, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-02 20:42:03

Comparing candidate commit 26f0728 in PR branch vlad/py315-pyo3-contextvar with baseline commit 1b2e241 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 6 performance regressions! Performance is the same for 576 metrics, 10 unstable metrics, 2 known flaky benchmarks, 16 flaky benchmarks without significant changes.

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:httppropagationinject-ids_only

  • 🟥 execution_time [+2.315µs; +2.468µs] or [+13.645%; +14.548%]

scenario:iastaspects-join_aspect

  • 🟥 execution_time [+49.698µs; +54.012µs] or [+23.684%; +25.740%]

scenario:iastaspects-title_aspect

  • 🟥 execution_time [+38.384µs; +45.940µs] or [+13.956%; +16.704%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+106.286µs; +113.458µs] or [+25.593%; +27.321%]

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

  • 🟥 execution_time [+546.935ns; +587.783ns] or [+19.973%; +21.465%]

scenario:tracer-small

  • 🟥 execution_time [+39.125µs; +41.521µs] or [+12.029%; +12.765%]

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 [-736.413ns; +749.611ns] or [-6.626%; +6.745%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-37.559ns; +28.147ns] or [-6.100%; +4.571%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1646.213ns; +1632.997ns] or [-9.728%; +9.650%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1265.670ns; +1212.292ns] or [-9.744%; +9.333%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-332.255ns; +317.366ns] or [-9.098%; +8.690%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-255.533ns; +252.005ns] or [-8.798%; +8.677%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-71.987ns; +74.339ns] or [-6.368%; +6.576%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-3839.874ns; +4144.423ns] or [-9.397%; +10.142%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-790.722ns; +755.287ns] or [-9.801%; +9.362%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-44.294µs; +33.827µs] or [-7.630%; +5.827%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:iastaspects-casefold_noaspect

  • 🟥 execution_time [+29.108µs; +37.696µs] or [+11.621%; +15.049%]

scenario:span-start

  • 🟥 execution_time [+1.542ms; +1.692ms] or [+10.809%; +11.862%]

Known flaky benchmarks without significant changes:

  • scenario:errortrackingflasksqli-baseline
  • scenario:flasksimple-iast-get
  • scenario:iastaspects-casefold_aspect
  • scenario:iastaspects-index_aspect
  • scenario:iastaspects-ljust_noaspect
  • scenario:iastaspects-lower_aspect
  • scenario:iastaspects-replace_aspect
  • scenario:iastaspects-swapcase_aspect
  • scenario:iastaspects-title_noaspect
  • scenario:iastaspects-translate_aspect
  • scenario:iastaspects-translate_noaspect
  • scenario:iastaspects-upper_noaspect
  • scenario:packagespackageforrootmodulemapping-cache_off
  • scenario:packagespackageforrootmodulemapping-cache_on
  • scenario:sethttpmeta-all-enabled
  • scenario:telemetryaddmetric-record-100-metrics

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

Part of #19908

@vlad-scherbich vlad-scherbich added the changelog/no-changelog A changelog entry is not required for this PR. label Aug 27, 2026
@vlad-scherbich
vlad-scherbich marked this pull request as ready for review August 27, 2026 21:03
@vlad-scherbich
vlad-scherbich requested a review from a team as a code owner August 27, 2026 21:03
@vlad-scherbich
vlad-scherbich requested review from juanjux and a lite review from Copilot August 27, 2026 21:03
@vlad-scherbich vlad-scherbich changed the title chore(native): declare PyContextVar_* locally for limited-API builds chore(native): declare PyContextVar_* locally for limited-API builds (PROF-15850) Aug 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Rust native extension builds under Py_LIMITED_API (e.g., CPython 3.15 builds using PYO3_USE_ABI3_FORWARD_COMPATIBILITY) by locally declaring the PyContextVar_New, PyContextVar_Get, and PyContextVar_Set C-API entry points that are not exposed by pyo3-ffi in that configuration.

Changes:

  • Add local extern "C" declarations for PyContextVar_* functions in src/native/contextvar.rs.
  • Switch call sites from ffi::PyContextVar_* to the locally declared symbols so the module compiles with and without Py_LIMITED_API.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/native/contextvar.rs Outdated
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 27, 2026

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.

No remaining files require a CODEOWNERS review.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 27, 2026

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

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

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.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
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

cit-pr-commenter-54b7da Bot commented Aug 27, 2026

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 230 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=134)
ddtrace.llmobs._integrations.crewai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.llmobs._integrations.claude_agent_sdk -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.internal.opentelemetry.trace -×-> ddtrace.trace  (product:opentelemetry -> product:tracing, score=132)
ddtrace.internal.ci_visibility.git_client -×-> ddtrace.trace  (product:ci_visibility -> 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

@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: 5e2e90539b

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

Comment thread src/native/contextvar.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@vlad-scherbich
vlad-scherbich force-pushed the vlad/py315-pyo3-contextvar branch 2 times, most recently from f9ee924 to 12acbff Compare August 28, 2026 14:57
@vlad-scherbich
vlad-scherbich requested a review from a team as a code owner August 28, 2026 14:57
@vlad-scherbich
vlad-scherbich changed the base branch from vlad/no-cp315-to-pypi to vlad/py315-manylinux-wheels August 28, 2026 14:58
@vlad-scherbich
vlad-scherbich force-pushed the vlad/py315-pyo3-contextvar branch from 12acbff to 59047aa Compare August 28, 2026 15:51
vlad-scherbich added a commit that referenced this pull request Sep 2, 2026
Track B now forks at #19903 (PyContextVar_*). DoE attach stays #19272.
vlad-scherbich added a commit that referenced this pull request Sep 2, 2026
Track B now forks at #19903 (PyContextVar_*). DoE attach stays #19272.
…imited-API

PyContextVar_New/_Get/_Set are absent from pyo3-ffi limited-API bindings.
PyGILState_Check is not limited-API; on those builds skip the probe rather
than acquire or guess from a crash signal handler.
rust-ci runs clippy -D warnings; rustdoc does not document extern blocks,
so the /// notes were unused_doc_comments.
@vlad-scherbich
vlad-scherbich force-pushed the vlad/py315-pyo3-contextvar branch from 3260237 to 26f0728 Compare September 2, 2026 20:14
vlad-scherbich added a commit that referenced this pull request Sep 2, 2026
Track B now forks at #19903 (PyContextVar_*). DoE attach stays #19272.
@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/merge -m squash

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 3, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-03 01:07:41 UTC ℹ️ Start processing command /merge -m squash


2026-09-03 01:08:01 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-09-03 01:15:53 UTC ⚠️ MergeQueue: This merge request was unqueued

vlad.scherbich@datadoghq.com unqueued this merge request

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/remove

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 3, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-03 01:15:47 UTC ℹ️ Start processing command /remove


2026-09-03 01:15:52 UTC ℹ️ Devflow: /remove

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/merge -f --reason "All checks besides unrelated pytorch failures passed multiple times. Unrelated to this change."

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 3, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-03 01:17:17 UTC ℹ️ Start processing command /merge -f --reason "All checks besides unrelated pytorch failures passed multiple times. Unrelated to this change."


2026-09-03 01:17:36 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-09-03 01:55:13 UTC ⚠️ MergeQueue: This merge request was unqueued

vlad.scherbich@datadoghq.com unqueued this merge request

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/merge -f --reason "All checks besides unrelated pytorch failures passed multiple times. Unrelated to this change."

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 3, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-03 01:55:28 UTC ℹ️ Start processing command /merge -f --reason "All checks besides unrelated pytorch failures passed multiple times. Unrelated to this change."


2026-09-03 01:55:47 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-09-03 05:57:30 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

vlad-scherbich added a commit that referenced this pull request Sep 3, 2026
Track B now forks at #19903 (PyContextVar_*). DoE attach stays #19272.
@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/code blockers

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 3, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-03 19:14:46 UTC ℹ️ Start processing command /code blockers


2026-09-03 19:14:46 UTC ℹ️ Devflow:

Checking merge blockers for #19903...


2026-09-03 19:15:06 UTC ℹ️ Devflow: /code blockers

Detected 1 merge blocker(s) to address:

🔴 Blocking

@vlad-scherbich
vlad-scherbich removed the request for review from a team September 3, 2026 21:57
@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/code blockers

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 3, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-03 21:57:17 UTC ℹ️ Start processing command /code blockers


2026-09-03 21:57:17 UTC ℹ️ Devflow:

Checking merge blockers for #19903...


2026-09-03 21:57:36 UTC ℹ️ Devflow: /code blockers

No merge blockers detected.

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/merge -f --reason "This code change doesn't affect flaky CI jobs."

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 4, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-04 04:13:06 UTC ℹ️ Start processing command /merge -f --reason "This code change doesn't affect flaky CI jobs."


2026-09-04 04:13:11 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 0s (p90).


2026-09-04 04:13:33 UTC ℹ️ MergeQueue: This merge request was merged

Warning

This change was merged without running any pre merge CI checks

Reason: This code change doesn't affect flaky CI jobs.

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit f136d41 into main Sep 4, 2026
1359 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the vlad/py315-pyo3-contextvar branch September 4, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants