Skip to content

[SDK] Clamp BatchSpanProcessor max_export_batch_size to max_queue_size - #4727

Open
ltowarek wants to merge 3 commits into
open-telemetry:mainfrom
ltowarek:batch-processor-clamp-export-batch-size
Open

ltowarek wants to merge 3 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.72%. Comparing base (ac7b87a) to head (8655fc2).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4727      +/-   ##
==========================================
+ Coverage   86.69%   86.72%   +0.03%     
==========================================
  Files         527      528       +1     
  Lines       20902    20915      +13     
==========================================
+ Hits        18119    18136      +17     
+ Misses       2783     2779       -4     
Files with missing lines Coverage Δ
sdk/src/trace/batch_span_processor.cc 92.35% <100.00%> (+3.59%) ⬆️

... and 1 file 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

This branch has not been deployed

No deployments
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