Skip to content

fix(tracing): flush buffered data after tracing is disabled - #4528

Merged
seratch merged 6 commits into
openai:mainfrom
sylvesterkaczmarek:fix/flush-traces-after-disable
Aug 20, 2026
Merged

seratch merged 6 commits into
openai:mainfrom
sylvesterkaczmarek:fix/flush-traces-after-disable

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Summary

Keep the public flush_traces() operation effective after tracing has been disabled.

DefaultTraceProvider.force_flush() currently returns early when the provider's disabled flag is set. That means an application can create buffered trace data, call set_tracing_disabled(True) to stop collecting new traces, and then call flush_traces() before a worker or request exits, but the explicit flush silently does nothing.

Disabling tracing should control creation of new trace data. It should not prevent already-registered processors from flushing data they already own. This follows the same lifecycle distinction as processor shutdown.

Reproduction

# traces/spans have already been queued
set_tracing_disabled(True)
flush_traces()

On current main, flush_traces() reaches DefaultTraceProvider.force_flush() and returns before calling any registered processor.

Change

Remove the disabled-state early return from DefaultTraceProvider.force_flush(). Trace and span creation remain disabled exactly as before.

Test plan

Adds a regression test through the public flush_traces() function and verifies that a registered processor receives force_flush() even after the provider is disabled.

Issue number

N/A

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

Copy link
Copy Markdown

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: c088462d29

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix. Comparing v0.22.0, the base, and this branch confirms that disabling tracing already allows buffered data to be exported by the background worker and shutdown. Allowing an explicit flush to drain that data is therefore a useful correction.

Please retain _refresh_disabled_flag() and remove only the disabled early return. Removing the refresh call also changes when OPENAI_AGENTS_DISABLE_TRACING is first cached, which is unrelated to this fix. Please add a focused regression test preserving that initialization timing.

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Fixed. I updated the existing disabled-provider force_flush() test to match the new lifecycle contract, so both the direct provider test and the public flush_traces() regression now verify that buffered processors still flush after tracing is disabled.

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. The contradictory test is fixed, but my latest review request is still outstanding. Please retain _refresh_disabled_flag(), remove only the disabled early return, and add the regression test for the environment variable's initialization timing.

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Done. I restored _refresh_disabled_flag() in force_flush() while keeping the disabled early return removed, and added a focused regression test confirming that force_flush() preserves the first-use initialization and caching behavior of OPENAI_AGENTS_DISABLE_TRACING. Thanks for catching that.

@seratch seratch changed the title fix(tracing) flush buffered data after tracing is disabled fix(tracing): flush buffered data after tracing is disabled Aug 20, 2026
@seratch
seratch enabled auto-merge (squash) August 20, 2026 06:10
@seratch seratch added this to the 0.22.x milestone Aug 20, 2026
@seratch
seratch merged commit 502bccd into openai:main Aug 20, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants