fix(profiling): fall back when PY_UNWIND is not a valid local event - #20003
fix(profiling): fall back when PY_UNWIND is not a valid local event#20003vlad-scherbich wants to merge 1 commit into
Conversation
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
|
4a90e1a to
a3f34cd
Compare
89aed97 to
1b91da5
Compare
a3f34cd to
be2ca2c
Compare
5f77393 to
d05bf3d
Compare
df5e2f7 to
6d624f8
Compare
438d4ce to
8a65502
Compare
79b8faf to
ddba58a
Compare
8a65502 to
326a2cb
Compare
326a2cb to
ccb19c1
Compare
Pre-rc1 CPython 3.15 raises ValueError for local PY_UNWIND. Strip-only retry would leave unwind dead; fall back to set_events and recompute on unregister so handlers still fire. rc1+ keeps local-only enablement.
ccb19c1 to
99d3e63
Compare
BenchmarksBenchmark execution time: 2026-09-09 20:38:43 Comparing candidate commit ccb19c1 in PR branch Found 0 performance improvements and 2 performance regressions! Performance is the same for 571 metrics, 10 unstable metrics, 7 known flaky benchmarks, 17 flaky benchmarks without significant changes.
|
There was a problem hiding this comment.
🔵 Needs a closer look
The change alters low-level sys.monitoring event arming behavior (including global event enablement) in ways that could have non-obvious runtime and performance impact and merits final human review.
Pull request overview
Adds a runtime-compatibility fallback in ddtrace.internal.monitoring for CPython 3.15 pre-rc1 builds where PY_UNWIND is rejected as a local event, ensuring unwind callbacks still fire by enabling PY_UNWIND globally only when needed.
Changes:
- Detects
set_local_events(..., PY_UNWIND)rejection and falls back to enablingPY_UNWINDviaset_events()while keeping other events local. - Adjusts
_on_py_unwindbehavior in fallback mode to avoid returning stickyDISABLEfor unregistered code objects. - Updates tests to accept either local-only or global-fallback arming and adds an explicit regression test for the fallback path.
File summaries
| File | Description |
|---|---|
| ddtrace/internal/monitoring.py | Implements the local-event probe and global-event fallback for PY_UNWIND, plus global enable/disable recomputation. |
| tests/internal/test_monitoring.py | Adds fixtures/helpers and new assertions/tests to cover both local and global fallback arming behavior. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| needed: int = 0 | ||
| for handlers in _registry.values(): | ||
| if _events_for(handlers) & _E.PY_UNWIND: | ||
| needed = _E.PY_UNWIND | ||
| break |
|
Revisit if becomes a problem |
Description
Delta vs #19269: adds a local-event fallback for
PY_UNWIND. Whensys.monitoring.set_local_eventsrejects that event, the profiling setup retries without it; the global callback remains configured.This PR does not add the native build or change the asyncio task-tracking path.
Testing
Risks
Additional Notes
Sibling of the other runtime compatibility fixes.
changelog/no-changelog.