Skip to content

[Monitor OpenTelemetry Exporter] Add client-side token bucket rate limiter for telemetry export#46999

Merged
hectorhdzg merged 8 commits into
Azure:mainfrom
hectorhdzg:feature/add-client-side-rate-limiter-for-export
May 22, 2026
Merged

[Monitor OpenTelemetry Exporter] Add client-side token bucket rate limiter for telemetry export#46999
hectorhdzg merged 8 commits into
Azure:mainfrom
hectorhdzg:feature/add-client-side-rate-limiter-for-export

Conversation

@hectorhdzg
Copy link
Copy Markdown
Member

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

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
Copilot AI review requested due to automatic review settings May 19, 2026 20:44
@github-actions github-actions Bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label May 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _TokenBucketRateLimiter with 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
@hectorhdzg hectorhdzg force-pushed the feature/add-client-side-rate-limiter-for-export branch from b2bbd0e to 2b4ce8c Compare May 19, 2026 22:54
@hectorhdzg hectorhdzg changed the title Add client-side token bucket rate limiter for telemetry export [Monitor OpenTelemetry Exporter] Add client-side token bucket rate limiter for telemetry export May 19, 2026
hectorhdzg and others added 5 commits May 20, 2026 17:32
…smit calls

Address JacksonWeber review: when _transmit() hits a 307/308 redirect and
calls itself recursively, the rate-limiting logic at the top would consume
tokens a second time for the same batch. Add _skip_rate_limit parameter
that is set to True on recursive calls to prevent this.
@hectorhdzg hectorhdzg merged commit 25e9220 into Azure:main May 22, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Monitor - Exporter Monitor OpenTelemetry Exporter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants