[monitor-opentelemetry-exporter] Add AzureMonitorSamplingSpanProcessor for scoped sampling#39260
Draft
JacksonWeber wants to merge 21 commits into
Draft
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…r for scoped sampling Add `AzureMonitorSamplingSpanProcessor` and the `createAzureMonitorSampler` factory so a distribution can scope trace sampling (rate-limited via `tracesPerSecond` or percentage via `samplingRatio`) to the Azure Monitor export pipeline only, leaving other exporters at 100%. The processor makes the sampling decision at `onStart` (preserving the `RateLimitedSampler` timing and inheriting an in-process parent's decision via a WeakMap) and applies it at `onEnd`: sampled-out spans are dropped and sampled-in spans get the `microsoft.sample_rate` attribute stamped on a non-mutating proxy, so the original span shared with other exporters is left untouched. `createAzureMonitorSampler` returns a `RateLimitedSampler` when `tracesPerSecond > 0`, otherwise an `ApplicationInsightsSampler` built from `samplingRatio` (defaulting to 100%). Bump the package version to 1.0.0-beta.44 and regenerate the API report. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 841d1f1f-9529-46f5-9347-5a33947f2ec8
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.
Summary
Adds
AzureMonitorSamplingSpanProcessorand thecreateAzureMonitorSamplerfactory so a distribution can scope trace sampling to the Azure Monitor export pipeline only, leaving every other exporter (e.g. A365, OTLP) at 100%.Today a distro applies a single global sampler at the SDK level, which drops spans for all exporters. This change lets sampling live in front of just the Azure Monitor batch processor instead.
What's added
AzureMonitorSamplingSpanProcessor— aSpanProcessorthat wraps a delegate processor (e.g. theBatchSpanProcessoraroundAzureMonitorTraceExporter) and applies aSampler:onStart— preservesRateLimitedSamplertiming and lets a child span inherit its in-process parent's decision via aWeakMap, keeping whole traces together.onEnd— sampled-out spans are dropped; sampled-in spans get themicrosoft.sample_rateattribute stamped on a non-mutating proxy, so the original span shared with other exporters is untouched.createAzureMonitorSampler({ tracesPerSecond, samplingRatio })— returns aRateLimitedSamplerwhentracesPerSecond > 0, otherwise anApplicationInsightsSampler(defaulting to 100%).Version
1.0.0-beta.44and regenerates the API report.Testing
test/internal/azureMonitorSamplingSpanProcessor.spec.ts(10 tests): 100% pass-through, drop-on-sampled-out, sample-rate proxy (original span untouched), parent-decision inheritance, independent root decisions, factory selection, andforceFlush/shutdowndelegation.Notes