Skip to content

[SDK] Clamp BatchSpanProcessor max_export_batch_size to max_queue_size - #4727

Merged
marcalff merged 4 commits into
open-telemetry:mainfrom
ltowarek:batch-processor-clamp-export-batch-size
Oct 27, 2026
Merged

marcalff merged 4 commits into
open-telemetry:mainfrom
ltowarek:batch-processor-clamp-export-batch-size

Conversation

@ltowarek

Copy link
Copy Markdown
Contributor

[SDK] Clamp BatchSpanProcessor max_export_batch_size to max_queue_size

Changes

Since #4466, BatchSpanProcessor waits for a full batch before it exports. If max_export_batch_size is larger than max_queue_size, a full batch never arrives. Spans are then exported only when schedule_delay_millis expires, and new spans are dropped once the queue is full.

The specification says the batch size must be less than or equal to the queue size, so such values are invalid. They still worked before #4466, though. Since #4466, apps that use them lose spans, and nothing points at the configuration as the cause.

The fix is based on the Java and Python SDKs, which both refuse such values. Java clamps the batch size to the queue size and logs a warning (BatchSpanProcessorBuilder). Python raises a ValueError (BatchSpanProcessor). opentelemetry-cpp must also work without exceptions, so this PR does what Java does: it clamps and logs one warning at construction. A max_queue_size of 0 is left alone, because clamping to it would make the worker spin.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

A batch size larger than the queue can never fill, so since the worker
waits for a full batch, spans were exported only when the schedule delay
expired and dropped in between. Use max_queue_size instead and warn.
A max_queue_size of 0 is left alone, since a batch size of 0 makes the
worker spin.
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.60%. Comparing base (c827b60) to head (5317bc2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4727      +/-   ##
==========================================
- Coverage   86.70%   86.60%   -0.09%     
==========================================
  Files         527      530       +3     
  Lines       20902    21009     +107     
==========================================
+ Hits        18121    18193      +72     
- Misses       2781     2816      +35     
Files with missing lines Coverage Δ
sdk/src/trace/batch_span_processor.cc 92.35% <100.00%> (+2.47%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ltowarek
ltowarek marked this pull request as ready for review October 23, 2026 05:08
@ltowarek
ltowarek requested a review from a team as a code owner October 23, 2026 05:08

@lalitb lalitb 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.

LGTM. one comment, can be a follow-up fix.

@ltowarek

Copy link
Copy Markdown
Contributor Author

LGTM. one comment, can be a follow-up fix.

Thanks for the review! I'll create a follow-up PR.

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.

3 participants