Skip to content

feat: enable batch for instrumentation#43

Merged
jeanscherf merged 2 commits intomainfrom
feat/enable-batch-instrumentation
Apr 9, 2026
Merged

feat: enable batch for instrumentation#43
jeanscherf merged 2 commits intomainfrom
feat/enable-batch-instrumentation

Conversation

@jeanscherf
Copy link
Copy Markdown
Member

Description

This PR changes the default to disable_batch=False (async BatchSpanProcessor) and exposes the parameter so users can override it when needed.

auto_instrument was hardcoding disable_batch=True, forcing SimpleSpanProcessor which exports spans synchronously on the request thread. With concurrent workloads, the network round-trip to the OTEL collector adds up directly on the hot path. A user reported response times dropping from ~40s to ~5s under 9 concurrent requests after patching this locally.

Related Issue

Closes #40

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update

How to Test

  1. Call auto_instrument() and send concurrent requests to an instrumented agent exporting to an OTLP endpoint
  2. Verify response times are not impacted by span export latency
  3. Verify auto_instrument(disable_batch=True) still works for cases where synchronous export is needed (e.g. short-lived scripts)

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Breaking Changes

None. The new default (disable_batch=False) is a behavior improvement. Users who relied on the previous synchronous behavior can restore it with auto_instrument(disable_batch=True).

Additional Notes

Trade-offs of BatchSpanProcessor (the new default):

  • Spans in the queue are lost if the process is killed abruptly (SIGKILL)
  • In short-lived scripts or serverless runtimes, call tracer_provider.force_flush() on shutdown to avoid losing the last batch
  • Export errors surface in a background thread (logged, not propagated)

For these cases, disable_batch=True remains available and is documented in the user guide.

@jeanscherf jeanscherf requested a review from a team as a code owner April 9, 2026 12:37
LucasAlvso
LucasAlvso approved these changes Apr 9, 2026
Copy link
Copy Markdown
Contributor

@LucasAlvesSoares LucasAlvesSoares left a comment

Choose a reason for hiding this comment

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

img

@jeanscherf jeanscherf merged commit 05f5202 into main Apr 9, 2026
10 checks passed
@jeanscherf jeanscherf deleted the feat/enable-batch-instrumentation branch April 9, 2026 13:11
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.

Make disable_batch user-configurable for auto_instrument

4 participants