fix(telemetry): avoid startup import races#19014
Closed
florentinl wants to merge 5 commits into
Closed
Conversation
Codeowners resolved as |
Circular import analysis
|
This comment has been minimized.
This comment has been minimized.
florentinl
force-pushed
the
agent/fix-telemetry-asm-import-race
branch
from
July 13, 2026 15:25
b433168 to
759db1a
Compare
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
Prevents the instrumentation telemetry worker from initiating imports while
ddtraceis still initializing.The telemetry writer starts during package import. With a short heartbeat interval, its background thread could concurrently import either:
Both paths could expose partially initialized modules and fail startup with a circular-import
ImportError. Endpoint reporting and dependency collection now use settings only after their modules are fully initialized; otherwise, telemetry defers that work to a later heartbeat. Dependency collection defers before scanning modules so no dependency state is lost.This adds a subprocess stress regression covering dependency collection both enabled and disabled, direct dependency-tracker coverage, and a release note.
Testing
Regression tests
Risks
Low. Endpoint reporting or dependency collection can be deferred by one telemetry heartbeat if the required settings are still initializing. Endpoint and dependency state remain queued for the next collection cycle.
Additional Notes
Original failure: https://github.com/DataDog/dd-trace-py/actions/runs/29244084795/job/86802866160#step:7:12111