feat(tracing): add flush_traces() for long-running workers#2735
feat(tracing): add flush_traces() for long-running workers#2735mvanhorn wants to merge 6 commits intoopenai:mainfrom
Conversation
In long-running processes (Celery, FastAPI background tasks, RQ), traces are buffered indefinitely because the process never exits to trigger shutdown flushing. This adds flush_traces() as a public API that delegates to the trace provider's force_flush(), allowing users to explicitly flush traces at the end of each task. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30cb3f99ec
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
seratch
left a comment
There was a problem hiding this comment.
If you're willing to take more time, please continue working until Codex auto review gives 👍 to your PR. Then, we'll check the direction and details.
…lity The flush_traces() function calls get_trace_provider().force_flush(), but TraceProvider (the abstract base class) did not declare force_flush as an abstract method. mypy correctly flagged this as attr-defined error since only DefaultTraceProvider had the concrete implementation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f29ffb7a27
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…patibility Addresses Codex review feedback: existing TraceProvider subclasses that don't override force_flush or shutdown will no longer break at instantiation. Both methods now default to no-ops on the base class. Adds a test proving a minimal custom provider works with flush_traces(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add hasattr check so flush_traces() is safe to call even with custom TraceProvider implementations that predate the force_flush method.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25377a406a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
force_flush() now checks the disabled flag before flushing processors, matching the behavior of shutdown(). Prevents buffered telemetry from being exported after set_tracing_disabled(True). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
seratch
left a comment
There was a problem hiding this comment.
can you fix the lint / typecheck errors?
Add explicit `pass` to TraceProvider.force_flush/shutdown to satisfy ruff B027 (empty method in abstract class without @AbstractMethod). Expand MinimalProvider test stub signatures to match the parent class. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Fixed in 21d84de:
|
Summary
In long-running worker processes (Celery, FastAPI background tasks, RQ, Dramatiq), traces created with
agents.trace()are buffered byBatchTraceProcessorbut never exported because the process never exits to trigger shutdown flushing. Users currently have to access private internals (get_trace_provider()._multi_processor.force_flush()) to flush traces.This PR adds a public
flush_traces()function that delegates to the trace provider'sforce_flush():Test plan
test_flush_traces_calls_provider_force_flush- verifies the function delegates to the providertest_flush_traces_importable_from_agents- verifies the public API export worksmake tests- 2405 passed)Issue number
Closes #2135
Checks
make lintandmake formatThis contribution was developed with AI assistance (Claude Code).