Repository navigation
fix(tracing): enforce max_batch_size during force_flush and shutdown in BatchTraceProcessor - #3985
Conversation
…in BatchTraceProcessor
seratch
left a comment
There was a problem hiding this comment.
Thanks for the contribution. The issue is valid: max_batch_size is documented as the maximum number of items passed to one export, but the current force-flush and shutdown paths bypass it, and the default HTTP exporter can consequently place the entire same-key queue into one request.
Before merging, please remove the now-unused force parameter from _export_batches() and update its callers. Once every invocation drains the queue in bounded batches, force=True and force=False no longer select different behavior, so retaining them would leave a misleading internal contract. The new exact batch-size assertion should remain. After that change and green CI, this should be ready for another review.
After max_batch_size is always enforced, force no longer changes behavior and left a misleading internal contract.
|
Removed the unused force parameter from _export_batches() and updated all callers (force_flush, _run, and the no-worker shutdown path). |
Summary
When
force_flush()orshutdown()is called onBatchTraceProcessor,_export_batches(force=True)was called. In_export_batches, the inner loop condition containedforce or len(items_to_export) < self._max_batch_size. Becauseforceevaluated toTrue, themax_batch_sizelimit was completely bypassed during queue draining.As a result, all queued items (even thousands of spans) were gathered into a single exported batch. When sent to the HTTP exporter (
BackendSpanExporter), giant single payloads lead to HTTP 413 (Payload Too Large) errors, request timeouts, or connection failures, stranding or dropping queued telemetry.This PR removes the
force orcondition from the inner batch collector so that_export_batchesalways enforcesmax_batch_sizeon every batch passed toexporter.export(), while the outer loop continues draining the queue until empty.Test plan
test_batch_trace_processor_force_flushunit test intests/test_trace_processor.pyto assert that exported batches strictly respectmax_batch_size(e.g. 3 queued items withmax_batch_size=2are exported as 2 separate batches of sizes[2, 1]).make format-checkmake lintmake typecheckmake testsIssue number
N/A
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR