Skip to content

[monitor-opentelemetry-exporter] Add AzureMonitorSamplingSpanProcessor for scoped sampling#39260

Draft
JacksonWeber wants to merge 21 commits into
Azure:mainfrom
JacksonWeber:jacksonweber/azuremonitor-sampling-span-processor
Draft

[monitor-opentelemetry-exporter] Add AzureMonitorSamplingSpanProcessor for scoped sampling#39260
JacksonWeber wants to merge 21 commits into
Azure:mainfrom
JacksonWeber:jacksonweber/azuremonitor-sampling-span-processor

Conversation

@JacksonWeber

Copy link
Copy Markdown
Member

Summary

Adds AzureMonitorSamplingSpanProcessor and the createAzureMonitorSampler factory 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 — a SpanProcessor that wraps a delegate processor (e.g. the BatchSpanProcessor around AzureMonitorTraceExporter) and applies a Sampler:
    • Decides at onStart — preserves RateLimitedSampler timing and lets a child span inherit its in-process parent's decision via a WeakMap, keeping whole traces together.
    • Applies at onEnd — sampled-out spans are dropped; sampled-in spans get the microsoft.sample_rate attribute stamped on a non-mutating proxy, so the original span shared with other exporters is untouched.
  • createAzureMonitorSampler({ tracesPerSecond, samplingRatio }) — returns a RateLimitedSampler when tracesPerSecond > 0, otherwise an ApplicationInsightsSampler (defaulting to 100%).

Version

  • Bumps the package to 1.0.0-beta.44 and regenerates the API report.

Testing

  • New unit suite 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, and forceFlush/shutdown delegation.
  • Existing sampling specs continue to pass.

Notes

  • Draft: opened for review while the consuming distribution change is finalized.

  • Added impacted package name to the issue description
  • Added a changelog (if necessary)

JacksonWeber and others added 21 commits April 2, 2026 16:12
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant