Skip to content
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

[QUERY] Setting custom Sampler does not work with Azure Monitor Distro, alternatives? #48592

Open
niravbhattsai opened this issue Mar 6, 2025 · 1 comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Distro Monitor OpenTelemetry Distro needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@niravbhattsai
Copy link

Library name and version

Azure.Monitor.OpenTelemetry.AspNetCore 1.2.0

Query/Question

Hello Team,

Recently we moved from Application Insight SDK to Monitor Distro. Earlier we were using Adaptive Sampling but now that is not the case.

To mitigate this I created a Sampler of my Own.

`

public class MySampler(float samplingRate) : Sampler
{
private readonly Sampler _parentBasedSampler = new ParentBasedSampler(new TraceIdRatioBasedSampler(samplingRate));

public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
    var traceId = samplingParameters.TraceId;
    var name = samplingParameters.Name;
    var kind = samplingParameters.Kind;
    var attributes = samplingParameters.Tags;

    // Record all telemetry of request and exception type
    if (kind == ActivityKind.Server || kind == ActivityKind.Consumer || kind == ActivityKind.Producer)
    {
        return new SamplingResult(SamplingDecision.RecordAndSample);
    }

    // Record if any exception occurred in a trace
    if (attributes is not null && attributes.Any(attr => attr.Key == "otel.status_code" && attr.Value?.Equals("ERROR") == true))
    {
        return new SamplingResult(SamplingDecision.RecordAndSample);
    }

    // Record any activity/trace starting with name "my.prefix"
    if (name.StartsWith("my.prefix", StringComparison.OrdinalIgnoreCase))
    {
        return new SamplingResult(SamplingDecision.RecordAndSample);
    }

    // Sample remaining dependencies by a configured ratio
    return _parentBasedSampler.ShouldSample(samplingParameters);
}

}

`

However even if I set my Sampler with Open Telemetry, it gets overridden by the line in Distro Lib
`
public static TracerProviderBuilder AddAzureMonitorTraceExporter(
this TracerProviderBuilder builder,
Action configure = null,
TokenCredential credential = null,
string name = null)
{
// ...

var deferredBuilder = builder as IDeferredTracerProviderBuilder;
// ...

    builder.SetSampler(new ApplicationInsightsSampler(exporterOptions.SamplingRatio));
//...

}
`

Is there any alternative to set my own sampler?

Environment

.NET SDK:
Version: 9.0.200
Commit: 90e8b202f2
Workload version: 9.0.200-manifests.69179adf
MSBuild version: 17.13.8+cbc39bea8

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.200\

.NET workloads installed:
[aspire]
Installation Source: VS 17.13.35825.156
Manifest Version: 8.2.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Install Type: Msi

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.2
Architecture: x64
Commit: 80aa709f5d

.NET SDKs installed:
6.0.428 [C:\Program Files\dotnet\sdk]
9.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 6, 2025
@jsquire jsquire added Service Attention Workflow: This issue is responsible by Azure service team. Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Monitor - Distro Monitor OpenTelemetry Distro and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Mar 6, 2025
Copy link

github-actions bot commented Mar 6, 2025

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @rajkumar-rangaraj @TimothyMothra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Distro Monitor OpenTelemetry Distro needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants