Skip to content

chore(wrapping): run wrap() trampoline on Python 3.15 (PROF-15852) - #19910

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
vlad/py315-wrap-lift
Aug 29, 2026
Merged

chore(wrapping): run wrap() trampoline on Python 3.15 (PROF-15852)#19910
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
vlad/py315-wrap-lift

Conversation

@vlad-scherbich

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

Copy link
Copy Markdown
Contributor

Description

#17849 is on main: 3.15 generator/coroutine assemblies and sys.monitoring WrappingContext / inject_hook. wrap() / wrap_bytecode() still gate on NEXT_PY_VERSION_INFO (was 3.15), so they raised on 3.15.

This PR sets NEXT_PY_VERSION to 3.16. The wrap() comparison is unchanged, so wrap() runs the existing trampoline on 3.15 and fail-closes from 3.16. Not a sys.monitoring port of wrap(). requires-python stays >=3.9,<3.15.

Side effect: @lazy on 3.15 takes the PYTHON_VERSION_INFO < NEXT branch (LazyWrappingContext.wrap()). inject_hook is already monitoring-based on 3.15 (PY >= (3, 15)); this PR does not change that gate.

Layer Meaning Which PR
Compiled into artifact 3.15 assemblies #17849 (on main)
Armed at runtime wrap() no longer raises on 3.15 this PR
Observable in product/Python wrap() / wrap_bytecode() run on 3.15 this PR

Testing

Sync, generator, and coroutine trampoline tests pinned to 3.15 (>= (3, 15) and < NEXT_PY). A monkeypatch pins fail-closed from 3.16.

Risks

3.15 is still unsupported (requires-python <3.15).

Additional Notes

Part of #17810. No release note: internal wrapping, 3.15 unsupported; changelog/no-changelog.

@vlad-scherbich vlad-scherbich added the changelog/no-changelog A changelog entry is not required for this PR. label Aug 27, 2026
@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

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 240 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=135)
ddtrace.appsec._listeners -×-> ddtrace.trace  (product:appsec -> product:tracing, score=133)
ddtrace.llmobs._integrations.mcp -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.profiling.collector.pytorch -×-> ddtrace.trace  (product:profiling -> product:tracing, score=133)
ddtrace.internal.openfeature._span_enrichment -×-> ddtrace.trace  (product:openfeature -> product:tracing, score=133)

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

@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

@datadog-prod-us1-5

datadog-prod-us1-5 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: c4b6422 | 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-08-28 15:20:03

Comparing candidate commit c4b6422 in PR branch vlad/py315-wrap-lift with baseline commit c9856f2 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.472µs; +2.684µs] or [+14.945%; +16.226%]

scenario:iastaspects-add_aspect

  • 🟥 execution_time [+10.514µs; +13.053µs] or [+10.638%; +13.207%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+131.981µs; +140.344µs] or [+32.168%; +34.207%]

scenario:iastaspectssplit-rsplit_aspect

  • 🟥 execution_time [+40.748µs; +46.151µs] or [+28.765%; +32.579%]

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

  • 🟥 execution_time [+617.407ns; +659.139ns] or [+22.822%; +24.365%]

scenario:tracer-small

  • 🟥 execution_time [+26.390µs; +28.795µs] or [+7.845%; +8.560%]

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 [-685.811ns; +777.522ns] or [-6.280%; +7.120%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-37.357ns; +28.987ns] or [-6.105%; +4.737%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1348.953ns; +1931.627ns] or [-8.035%; +11.505%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-912.470ns; +1581.409ns] or [-7.113%; +12.328%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-269.266ns; +375.100ns] or [-7.440%; +10.364%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-185.869ns; +319.118ns] or [-6.484%; +11.132%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-66.671ns; +82.441ns] or [-5.687%; +7.033%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-3969.697ns; +3943.054ns] or [-9.708%; +9.642%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-883.162ns; +662.018ns] or [-10.796%; +8.092%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-60.933µs; +57.118µs] or [-9.727%; +9.118%]

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 [+67.848µs; +74.841µs] or [+27.610%; +30.456%]

scenario:iastaspects-translate_aspect

  • 🟥 execution_time [+86.084µs; +94.422µs] or [+19.570%; +21.466%]

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_noaspect
  • scenario:iastaspects-upper_noaspect
  • scenario:packagespackageforrootmodulemapping-cache_off
  • scenario:packagespackageforrootmodulemapping-cache_on
  • scenario:sethttpmeta-all-enabled
  • scenario:span-start
  • scenario:telemetryaddmetric-record-100-metrics

@vlad-scherbich
vlad-scherbich force-pushed the chore/315-wrapping-context branch from 612f5d6 to 7e34962 Compare August 27, 2026 23:11
@vlad-scherbich vlad-scherbich changed the title feat(wrapping): run wrap() trampoline on Python 3.15 chore(wrapping): run wrap() trampoline on Python 3.15 Aug 28, 2026
@vlad-scherbich
vlad-scherbich requested a lite review from Copilot August 28, 2026 00:01

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 enables ddtrace.internal.wrapping.wrap() / wrap_bytecode() to execute on Python 3.15 (instead of raising NotImplementedError), relying on the existing trampoline logic and newly-added 3.15 generator/coroutine assemblies from the stacked work. It updates the Python 3.15 “import-time degrade” tests accordingly and adjusts the inject_hook() expectation to match the 3.15 sys.monitoring implementation.

Changes:

  • Remove the Python “next-unsupported” guard that raised NotImplementedError in wrap() / wrap_bytecode().
  • Replace the 3.15 “wrap raises” test with sync/generator/coroutine wrap exercises.
  • Update the 3.15 inject_hook() test to no longer expect NotImplementedError and to use an executable line number.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/internal/test_py315_import_degrade.py Updates 3.15 degrade tests to exercise wrap behavior (sync/generator/coroutine) and adjusts inject_hook() expectations for 3.15.
ddtrace/internal/wrapping/__init__.py Removes the explicit 3.15+ NotImplementedError gate so wrapping code paths run on 3.15.
Suppressed comments (1)

tests/internal/test_py315_import_degrade.py:125

  • This test now only checks that inject_hook() doesn’t raise, but it doesn’t verify that the hook is actually invoked when the function runs on 3.15+ (sys.monitoring path). Adding a call and an assertion would prevent regressions where registration succeeds but the hook never fires.
@pytest.mark.skipif(PYTHON_VERSION_INFO < NEXT_PY_VERSION_INFO, reason=f"{NEXT_PY_VERSION} debugging products degrade")
def test_debugging_products_load_without_failure():
    from ddtrace.internal.products import ProductManager


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

Comment thread tests/internal/test_py315_import_degrade.py

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 2 out of 2 changed files in this pull request and generated 3 comments.

Suppressed comments (1)

tests/internal/test_py315_import_degrade.py:59

  • Same as the sync wrap test: the current skip condition allows this coroutine test to run on Python 3.16+ where wrap() should raise NotImplementedError, causing unexpected failures when the test matrix advances.
@pytest.mark.skipif(PYTHON_VERSION_INFO < NEXT_PY_VERSION_INFO, reason=f"{NEXT_PY_VERSION} wrap() coroutine")
@pytest.mark.asyncio
async def test_wrap_coroutine_on_315():

Comment thread tests/internal/test_py315_import_degrade.py Outdated
Comment thread tests/internal/test_py315_import_degrade.py
Comment thread ddtrace/internal/wrapping/__init__.py Outdated
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Aug 28, 2026
**prev:** [#19906](#19906) | **next:** [#19910](#19910)

## Summary

Wrapping context + bytecode injection for 3.15. Delta vs #19906 only (monitoring + 3.15 assemblies).

## Test plan

- [ ] CI green on this branch
- [ ] Stack merges cleanly into the next PR's base branch


Co-authored-by: vlad-scherbich <vlad.scherbich@datadoghq.com>
Co-authored-by: gabriele.tornetta <gabriele.tornetta@datadoghq.com>
Base automatically changed from chore/315-wrapping-context to main August 28, 2026 14:36
wrap() already gates on NEXT_PY_VERSION_INFO. Lifting the constant enables
the 3.15 trampoline and fail-closes on 3.16, so the adhoc +1 tripwire can go.
@vlad-scherbich vlad-scherbich changed the title chore(wrapping): run wrap() trampoline on Python 3.15 chore(wrapping): run wrap() trampoline on Python 3.15 (PROF-15852) Aug 28, 2026
@vlad-scherbich
vlad-scherbich requested a lite review from Copilot August 28, 2026 15:03

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 2 out of 2 changed files in this pull request and generated no new comments.

@vlad-scherbich
vlad-scherbich marked this pull request as ready for review August 28, 2026 15:34
@vlad-scherbich
vlad-scherbich requested review from a team as code owners August 28, 2026 15:34
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 3e4b91a into main Aug 29, 2026
1304 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the vlad/py315-wrap-lift branch August 29, 2026 18:12
vlad-scherbich added a commit that referenced this pull request Aug 30, 2026
NEXT_MAX_PY is 3.15 (packaging). wrap() and lazy must match merged
#19910: trampoline and WrappingContext are live on 3.15, fail closed
from 3.16. A rebase onto main must not re-disable wrap on 3.15.
vlad-scherbich added a commit that referenced this pull request Aug 30, 2026
NEXT_MAX_PY is 3.15 (packaging). wrap() and lazy must match merged
#19910: trampoline and WrappingContext are live on 3.15, fail closed
from 3.16. A rebase onto main must not re-disable wrap on 3.15.

(cherry picked from commit ed3bd06)
vlad-scherbich added a commit that referenced this pull request Aug 30, 2026
NEXT_MAX_PY is 3.15 (packaging). wrap() and lazy must match merged
#19910: trampoline and WrappingContext are live on 3.15, fail closed
from 3.16. A rebase onto main must not re-disable wrap on 3.15.

(cherry picked from commit ed3bd06)
(cherry picked from commit 44f4160)
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.

3 participants