Skip to content

fix(python): flush pending traces during Client.cleanup()#2799

Merged
Angus Jelinek (angus-langchain) merged 4 commits intomainfrom
feat/cleanup-flushes-on-shutdown
Apr 25, 2026
Merged

fix(python): flush pending traces during Client.cleanup()#2799
Angus Jelinek (angus-langchain) merged 4 commits intomainfrom
feat/cleanup-flushes-on-shutdown

Conversation

@angus-langchain
Copy link
Copy Markdown
Contributor

@angus-langchain Angus Jelinek (angus-langchain) commented Apr 24, 2026

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

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.
@angus-langchain Angus Jelinek (angus-langchain) merged commit dd4a7d5 into main Apr 25, 2026
62 of 66 checks passed
@angus-langchain Angus Jelinek (angus-langchain) deleted the feat/cleanup-flushes-on-shutdown branch April 25, 2026 00:27
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