[Python] DDTestLogsHandler SDK for test visibility log correlation#37367
[Python] DDTestLogsHandler SDK for test visibility log correlation#37367gnufede wants to merge 3 commits into
Conversation
…round job workers Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Preview links (active after the
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
/review |
There was a problem hiding this comment.
🤖 Automated review by Claude. AI-generated; verify before acting.
One style nit on the new section heading. Content is clear and code examples look reasonable for technical readers.
Reviewed ddf697bb7e97c81b1fcb38142f2a9bd8106ed675 — workflow run
| handler.addFilter(correlation) | ||
| logging.getLogger().addHandler(handler) | ||
|
|
||
| while True: |
There was a problem hiding this comment.
Suggestion: queue is referenced but never imported or defined in the snippet, which can trip up readers copying the example. Consider adding a brief comment to signal this is illustrative (e.g., # queue and run_test are provided by your worker framework) or initialize them so the snippet is self-contained.
|
|
||
| ##### Asyncio workers | ||
|
|
||
| For asyncio-based workers, subclass `CorrelationFilter` and use a `contextvars.ContextVar` for storage so each `asyncio.Task` sees its own correlation IDs: |
There was a problem hiding this comment.
Suggestion: A one-line note on why CorrelationFilter needs subclassing here (the default ThreadLocalCorrelationFilter stores context in thread-locals, which don't propagate across asyncio.Task boundaries) would help readers understand the choice rather than just follow it.
rtrieu
left a comment
There was a problem hiding this comment.
please see comments from the gitactions bot
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
What does this PR do? What is the motivation?
Documents the new
ddtrace.testing.logspublic API added in dd-trace-py#18078, which ships log records from background job workers to the Datadog logs intake correlated with Test Visibility traces.The new section ("Out of process logs") is added to the existing Correlate Logs and Tests page, under the Python / Agentless tab. It covers:
DDTestLogsHandler— alogging.Handlerthat auto-detects agentless vs. EVP proxy mode from standard environment variablesThreadLocalCorrelationFilter— for the common thread-per-worker caseContextVar-backedCorrelationFiltersubclass — for asyncio workersMerge instructions
Merge readiness:
AI assistance
Used Claude Code to draft the documentation and code examples based on the source implementation in
ddtrace/testing/logs.py.Additional notes
The version constraint (
ddtrace >= 4.11.0) is an estimate — the feature landed after v4.10.1. Update if the actual release version differs.