Skip to content

[Python] DDTestLogsHandler SDK for test visibility log correlation#37367

Open
gnufede wants to merge 3 commits into
masterfrom
gnufede/logs-api-docs
Open

[Python] DDTestLogsHandler SDK for test visibility log correlation#37367
gnufede wants to merge 3 commits into
masterfrom
gnufede/logs-api-docs

Conversation

@gnufede

@gnufede gnufede commented Jun 9, 2026

Copy link
Copy Markdown
Member

What does this PR do? What is the motivation?

Documents the new ddtrace.testing.logs public 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 — a logging.Handler that auto-detects agentless vs. EVP proxy mode from standard environment variables
  • ThreadLocalCorrelationFilter — for the common thread-per-worker case
  • A ContextVar-backed CorrelationFilter subclass — for asyncio workers

Merge instructions

Merge readiness:

  • Ready for merge

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.

…round job workers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@datadog-prod-us1-6

This comment has been minimized.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Preview links (active after the build_preview check completes)

Modified Files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gnufede gnufede marked this pull request as ready for review June 9, 2026 10:26
@gnufede gnufede requested review from a team as code owners June 9, 2026 10:26
@rtrieu

rtrieu commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

/review

@github-actions github-actions Bot 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.

🤖 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 ddf697bb7e97c81b1fcb38142f2a9bd8106ed675workflow run

Comment thread content/en/tests/correlate_logs_and_tests/_index.md Outdated
Comment thread content/en/tests/correlate_logs_and_tests/_index.md Outdated
Comment thread content/en/tests/correlate_logs_and_tests/_index.md Outdated
handler.addFilter(correlation)
logging.getLogger().addHandler(handler)

while True:

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.

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:

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.

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 rtrieu 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.

please see comments from the gitactions bot

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants