open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.18k stars 753 forks source link

[bug] ApplicationInsightsExporter SamplingRatio overwrites OTel Tracer Sampling Ratio #5830

Closed gensichen closed 2 weeks ago

gensichen commented 2 weeks ago

Package

OpenTelemetry

Package Version

Package Name Version
OpenTelemetry 1.8.1
Azure.Monitor.OpenTelemetry.Exporter 1.3.0

Runtime Version

net6.0, net8.0

Description

The static class TracerProviderBuilderExtensions, contains a method called SetSampler which takes an instance of TracerProviderBuilder and calls TracerProviderBuilderSdk.SetSampler to set its sampler instance to the provided sampler.

The issue is that since the builder is a a static instance. When adding the ApplicationInsightsExporter it also calls the very same SetSampler which can be seen here.

This results in the overriding of the original sampling instance.

Steps to Reproduce

  1. Create an OTel Trace Exporter and set sampling.
  2. Create an Application Insights Exporter with a different sampling ratio.
  3. Observer the Application Insights Sampling is used for all sampling.

Expected Result

The original sampler instance should not be overridden when ApplicationInsightsSampler is added.

Actual Result

The original sampler instance is overridden by the ApplicationInsightsSampler.

Additional Context

No response

cijothomas commented 2 weeks ago

This is best reported in Application Insights repo. There is nothing to be done in this repo to address this!. Closing. Feel free to reopen, if you believe this repo has something to do about this.