Skip to content

Added changes for rate limited sampler (azure-exporter changes) #41954

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rads-1996
Copy link
Member

@rads-1996 rads-1996 commented Jul 9, 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 9, 2025 14:54
@github-actions github-actions bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label Jul 9, 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 introduces a new rate-limited sampling mechanism for the Azure Monitor OTLP trace exporter, including utilities for DJB2-based sampling scores and rounding logic, and covers the feature with extensive unit tests.

  • Implemented RateLimitedSampler and its adaptive percentage generator in _rate_limited_sampling.py
  • Added two new utility functions (_get_djb2_sample_score, _round_down_to_nearest) and corresponding constants in _utils.py and _constants.py
  • Exported RateLimitedSampler in the package API and supplied comprehensive tests in test_rate_limited_sampling.py

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/trace/test_rate_limited_sampling.py New unit tests exercising various sampling scenarios and thread safety
export/trace/_utils.py Added DJB2 hash sampling score and nearest-rounding helper
export/trace/_rate_limited_sampling.py Added RateLimitedSampler and RateLimitedSamplingPercentage
exporter/_constants.py Defined _HASH, _INTEGER_MAX, _INTEGER_MIN for DJB2 utilities
exporter/init.py Exported RateLimitedSampler in public API
Comments suppressed due to low confidence (4)

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_utils.py:330

  • [nitpick] Add a docstring describing the purpose, inputs, and output range of this DJB2-based sampling score function.
def _get_djb2_sample_score(trace_id_hex: str) -> float:

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_utils.py:348

  • [nitpick] Add a docstring explaining the rounding strategy, edge cases handled, and example behavior.
def _round_down_to_nearest(sampling_percentage: float) -> float:

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py:221

  • [nitpick] Consider renaming _HASH to _DJB2_INITIAL_HASH or similar to clarify its role as the initial seed in the DJB2 algorithm.
_HASH = 5381

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_utils.py:348

  • Add unit tests for _round_down_to_nearest to verify correct behavior at boundaries (e.g., very small percentages, zero, and percentages that map to integer counts).
def _round_down_to_nearest(sampling_percentage: float) -> float:

Copy link

github-actions bot commented Jul 9, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-monitor-opentelemetry-exporter

@rads-1996 rads-1996 force-pushed the rads-1996/rate-limited-sampler-exporter branch from 7f47987 to c7d6608 Compare July 9, 2025 16:44
@rads-1996 rads-1996 force-pushed the rads-1996/rate-limited-sampler-exporter branch from 1f39e15 to 463011e Compare July 9, 2025 21:07
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.

1 participant