fix(tracing): Flush spans on interval instead of idle timeout #4197
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our trace span exporter uses batching logic to avoid making excessive requests to the trace collector. It does this by either waiting for the batch buffer to hit a maximum number of spans (currently 1000), or waiting for no spans to be collected in some timeout window (currently 10s).
If a workload emits spans at a slow but consistent rate, say 1 span/s, it would cause the timeout window to never be hit while the buffer slowly fills. At this rate, it would cause spans to not be emitted for a long time.
This replaces the timeout window with an interval timer that attempts to send the currently buffered spans on a consistent interval, regardless of if the collector has sat idle. This interval is set to 10s to match the current idle timeout, but this can be tuned in the future along with the buffer size if we feel the need.