fix(python): flush pending traces during Client.cleanup()#2799
Merged
Angus Jelinek (angus-langchain) merged 4 commits intomainfrom Apr 25, 2026
Merged
fix(python): flush pending traces during Client.cleanup()#2799Angus Jelinek (angus-langchain) merged 4 commits intomainfrom
Angus Jelinek (angus-langchain) merged 4 commits intomainfrom
Conversation
bd67e19 to
20d66c1
Compare
cleanup() signaled the background tracing threads to stop without draining
pending work, so any runs still in the queue or compressed buffer could be
dropped on manual shutdown. Flush before stopping, matching OpenTelemetry,
Datadog, Sentry, and PostHog conventions.
API:
- cleanup(timeout: float | None = None) — drains via flush() then stops.
timeout=None waits indefinitely; timeout=0 skips the drain entirely
for error paths / signal handlers.
- flush(timeout: float | None = None) — timeout-bounded drain across
both the tracing queue and the compressed buffer.
- flush_compressed_traces(..., timeout: float | None = None) — passes
the timeout through to cf.wait on in-flight sends.
20d66c1 to
dcb7720
Compare
Jacob Lee (jacoblee93)
approved these changes
Apr 25, 2026
…ueue + compressed_traces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this change, cleanup() stopped the background threads without draining first, so traces in flight at shutdown got dropped.
cleanup() now flushes before stopping, and takes a timeout. Default is None which keeps the old wait-forever behavior. Pass a number when you have a shutdown budget (SIGTERM handlers, Lambda, CI teardown) and cleanup drains what it can inside that window. Pass 0 to skip the drain for error paths where you'd rather lose traces than hang on network I/O.
Fixes #2703, credit to Johan Bonilla (@johanity).