Skip to content

Added RateLimitedSampler #41925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Conversation

rads-1996
Copy link
Member

@rads-1996 rads-1996 commented Jul 8, 2025

Description

Adding support for RateLimitedSampler, inspired by Java Application Insights sampler
https://github.com/microsoft/ApplicationInsights-Java/blob/main/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/RateLimitedSamplingPercentage.java

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 00:41
@github-actions github-actions bot added Monitor - Distro Monitor OpenTelemetry Distro Monitor - Exporter Monitor OpenTelemetry Exporter labels Jul 8, 2025
Copy link
Contributor

@Copilot 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

This PR adds support for a rate-limited sampler alongside the existing fixed-percentage sampler in the Azure Monitor OpenTelemetry SDK. Key changes include:

  • Introducing new constants and environment variable handling for RATE_LIMITED_SAMPLER and sampling traces per second.
  • Updating _get_configurations, _configure, and SDK constants to select between rate-limited and fixed-percentage samplers.
  • Implementing RateLimitedSampler, utility functions (_get_djb2_sample_score, _round_down_to_nearest), and comprehensive tests for sampling behavior.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/utils/test_configurations.py Added tests for rate-limited and fixed-percentage sampler env var scenarios
_constants.py (SDK) Defined RATE_LIMITED_SAMPLER, FIXED_PERCENTAGE_SAMPLER, and SAMPLING_TRACES_PER_SECOND_ARG
configurations.py Enhanced _default_sampling_ratio to branch on sampler type and set appropriate configuration
_configure.py Updated setup to instantiate RateLimitedSampler when traces-per-second is set
exporter/_utils.py Added _get_djb2_sample_score and improved rounding logic
_rate_limited_sampling.py Implemented RateLimitedSamplingPercentage and RateLimitedSampler
exporter/_constants.py Defined hash and integer bounds for sampling utilities

@rads-1996 rads-1996 marked this pull request as draft July 8, 2025 00:59
@rads-1996 rads-1996 force-pushed the rate-limited-sampler branch from 360c7da to 7183758 Compare July 8, 2025 15:15
@rads-1996
Copy link
Member Author

The existing sampler - ApplicationInsightsSampler, has a lot of constants, methods defined internally in _sampling.py that I have defined in constants.py and utils. If needed I can create another PR for that sampler, so it also references the methods and variables just like the new one does.

@rads-1996 rads-1996 marked this pull request as ready for review July 8, 2025 20:00
@rads-1996 rads-1996 closed this Jul 9, 2025
@rads-1996
Copy link
Member Author

A fresh one created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Monitor - Distro Monitor OpenTelemetry Distro Monitor - Exporter Monitor OpenTelemetry Exporter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant