[Monitor OpenTelemetry Exporter] Add client-side token bucket rate limiter for telemetry export#46999
Open
hectorhdzg wants to merge 3 commits into
Open
Conversation
Addresses resilience finding: the Azure Monitor OpenTelemetry exporter had no client-side send-rate cap, allowing telemetry bursts to overload shared ingestion infrastructure. Changes: - Add _TokenBucketRateLimiter in export/_rate_limiter.py with configurable max_envelopes_per_second (default 10,000/sec, 1s burst capacity) - Integrate rate limiting into BaseExporter._transmit() so all exporter types (traces, logs, metrics) are protected - Excess envelopes are routed to local storage for retry, not dropped - Stats/internal exporters bypass rate limiting to preserve observability - Rate limiting can be disabled via max_envelopes_per_second=0 - Add 19 unit and integration tests in tests/test_rate_limiter.py
Contributor
There was a problem hiding this comment.
Pull request overview
Adds client-side token bucket rate limiting to the Azure Monitor OpenTelemetry exporter to reduce burst pressure on ingestion while preserving retry behavior through local storage.
Changes:
- Introduces
_TokenBucketRateLimiterwith default 10,000 envelopes/sec and burst capacity. - Wires rate limiting into
BaseExporter._transmit()with stats/internal exporters bypassed. - Adds unit and integration tests for limiter behavior and exporter integration.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_rate_limiter.py |
Adds the token bucket implementation and rate limit constants. |
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py |
Initializes and applies the rate limiter during telemetry transmission. |
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_rate_limiter.py |
Adds tests for token bucket behavior and BaseExporter rate-limiting paths. |
…e limit values - Mutate envelopes list in-place (del envelopes[granted:]) so callers' _handle_transmit_from_storage sees only admitted envelopes, preventing duplicate storage of overflow on retryable failures - Log a warning when overflow is deferred but storage is disabled - Reject negative max_envelopes_per_second with ValueError instead of silently disabling rate limiting (only 0 disables, per documentation) - Add clarifying comment that per-exporter rate limiting is intentional - Add tests: negative value rejection, in-place mutation, no-storage overflow
b2bbd0e to
2b4ce8c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses resilience finding: the Azure Monitor OpenTelemetry exporter had no client-side send-rate cap, allowing telemetry bursts to overload shared ingestion infrastructure.
Changes: