chore: break circular import through atexit's lazy config import#19005
Merged
Conversation
atexit.py imported ddtrace.config lazily inside exception handlers to read DD_TESTING_RAISE, but the import-cycle detector treats function-scoped imports the same as module-level ones, so this closed a loop back to the top-level ddtrace package. Reading the flag via the native config accessor (already used by ddtrace.internal.settings) avoids the top-level import entirely and removes the cycle.
Contributor
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 7738f6c | Docs | Datadog PR Page | Give us feedback! |
Codeowners resolved as |
Circular import analysis
|
brettlangdon
approved these changes
Jul 15, 2026
BenchmarksBenchmark execution time: 2026-07-15 20:01:47 Comparing candidate commit 7738f6c in PR branch Found 0 performance improvements and 3 performance regressions! Performance is the same for 615 metrics, 10 unstable metrics. scenario:iastaspects-lstrip_aspect
scenario:iastaspectsospath-ospathbasename_aspect
scenario:span-start
|
juanjux
added a commit
that referenced
this pull request
Jul 16, 2026
## Description Backports #19030, #18851, and #19005 to 4.12. These changes separate default service-name resolution from the span schema, remove reverse dependencies through the public tracing API and global config, and simplify atexit configuration access. Together they align the 4.12 import graph with main and unblock circular-import validation for 4.12 backports. The 4.12 branch has 4,974 detected circular import paths before these changes and 61 afterward. ## Testing - `cycles.py analyze` — 4,974 → 61 circular imports - `cycles.py compare` — 4,913 circular imports removed, no new cycles - Python 3.14 internal tests for process tags, service-name imports, and atexit — 78 passed, 1 skipped - Python 3.14 tracer atexit tests — passed - Targeted formatting and lint checks — passed ## Risks Low. These are direct backports of three fixes already merged to main. ## Additional Notes Internal refactor only; no changelog entry is needed. --------- Co-authored-by: Emmett Butler <723615+emmettbutler@users.noreply.github.com> Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com> Co-authored-by: vlad-scherbich <vlad.scherbich@datadoghq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
atexit.py imported ddtrace.config lazily inside exception handlers to read DD_TESTING_RAISE, but the import-cycle detector treats function-scoped imports the same as module-level ones, so this closed a loop back to the top-level ddtrace package. Reading the flag via the native config accessor (already used by ddtrace.internal.settings) avoids the top-level import entirely and removes the cycle.