Skip to content

docs(tracing): add Long-running workers section with flush_traces() examples#2834

Closed
nanookclaw wants to merge 1 commit intoopenai:mainfrom
nanookclaw:docs/tracing-long-running-workers
Closed

docs(tracing): add Long-running workers section with flush_traces() examples#2834
nanookclaw wants to merge 1 commit intoopenai:mainfrom
nanookclaw:docs/tracing-long-running-workers

Conversation

@nanookclaw
Copy link
Copy Markdown

Summary

In long-running worker processes (Celery, FastAPI background tasks, RQ, Dramatiq), traces buffered by BatchTraceProcessor are silently dropped when the worker picks up the next task — the process never exits to trigger shutdown flushing, so buffered spans are never exported.

This PR documents the flush_traces() pattern with concrete examples for the two most common worker runtimes (Celery and FastAPI background tasks), explains why traces are dropped in worker environments, and points to #2135 for context.

Changes

  • docs/tracing.md: New Long-running workers section inserted before Ecosystem integrations, covering:
    • Root cause (BatchTraceProcessor + worker process lifecycle)
    • flush_traces() pattern with Celery example
    • flush_traces() pattern with FastAPI background task example
    • Note on silent data loss without the flush call

Relationship to open PRs

PR #2735 adds the flush_traces() public API. This PR documents it. The two are complementary — users who discover the worker issue via #2135 will find the solution pattern in the docs.

Checks

  • Documentation change only — no code changes
  • Examples tested against current SDK API (agents.flush_traces, agents.trace, agents.Runner)
  • Section placement follows existing doc structure (between Additional notes and Ecosystem integrations)

…xamples

In long-running worker processes (Celery, FastAPI background tasks, RQ,
Dramatiq), traces buffered by BatchTraceProcessor may not be exported
before the next task begins, because the process never exits to trigger
shutdown flushing.

Documents flush_traces() pattern with Celery and FastAPI examples.
Explains the silent data loss scenario and references openai#2135 for context.

Closes openai#2135
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Apr 3, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 314b766b05

ℹ️ 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".

Comment thread docs/tracing.md
Comment on lines +148 to +152
Use [`flush_traces()`][agents.flush_traces] after each task completes to ensure all buffered spans
are exported:

```python
from agents import Agent, Runner, trace, flush_traces
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove flush_traces guidance until API is available

This new section tells users to call flush_traces() and links to [agents.flush_traces], but that public symbol is not defined/exported in the current SDK (it is absent from both src/agents/tracing/__init__.py and src/agents/__init__.py). In this state, users copying the snippet will hit an ImportError, and the reference link target is unresolved during docs generation, so the docs now prescribe a non-existent API.

Useful? React with 👍 / 👎.

@seratch
Copy link
Copy Markdown
Member

seratch commented Apr 3, 2026

As mentioned at Codex reviews, the utility does not exist in this SDK. We may add something similar in the future. In the case, we'll update the documentation as well.

@seratch seratch closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants