Skip to content

Conversation

@delner
Copy link
Collaborator

@delner delner commented Jan 27, 2026

Adds automatic span flushing on program exit to prevent data loss from buffered traces.

Problem

The OpenTelemetry BatchSpanProcessor buffers spans before export. If a Ruby process exits before the buffer flushes, those spans are lost silently. This is especially common in short-lived scripts or CLI tools.

Solution

Register an at_exit hook that calls force_flush on the tracer provider, ensuring all buffered spans are exported before the process terminates.

Configuration

Variable Default Description
BRAINTRUST_FLUSH_ON_EXIT true Set to false to disable automatic flushing

Disabling may be useful in long-running processes where graceful shutdown is handled separately, or in test environments where the overhead is undesirable.

@delner delner requested review from clutchski and jseldess January 27, 2026 21:26
@delner delner self-assigned this Jan 27, 2026
@delner delner added the enhancement New feature or request label Jan 27, 2026
@delner delner merged commit a23711a into main Jan 27, 2026
7 checks passed
@delner delner deleted the feature/flush_on_exit branch January 27, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants