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

[BUG] Instrumentation Options delegates get called multiple times #46824

Closed
TimothyMothra opened this issue Oct 24, 2024 · 2 comments
Closed
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Monitor - Distro Monitor OpenTelemetry Distro

Comments

@TimothyMothra
Copy link
Contributor

TimothyMothra commented Oct 24, 2024

Library name and version

Azure.Monitor.OpenTelemetry.AspNetCore

Describe the bug

The AzureMonitor Distro (Azure.Monitor.OpenTelemetry.AspNetCore) automatically includes some Instrumentation libraries.
If a user adds the same Instrumentation library again, we expect there should be no conflict.

Unfortunately, it seems that the delegate methods can get executed multiple times.
This has only been confirmed with the AspNetCore Instrumentation's EnrichWithHttpRequest library, but I suspect it applies to each Instrumentation library.

Example

builder.Services.AddOpenTelemetry().UseAzureMonitor()
    .WithTracing(builder =>
    {
        builder.AddAspNetCoreInstrumentation(options =>
        {
            options.EnrichWithHttpRequest = (activity, HttpResponse) =>
            {
                // this will be called twice
                Console.WriteLine($"EnrichWithHttpRequest was called for activity: {activity.Id}");
            };
        });
    });

Workaround

The workaround is to use the Configure Api to set an Instrumentation library's options.
This is already described in our Readme and public docs, but users are not discovering this pattern and doing the above instead.

builder.Services.AddOpenTelemetry().UseAzureMonitor()
builder.Services.Configure<AspNetCoreTraceInstrumentationOptions>(options =>
{
    options.EnrichWithHttpRequest = (activity, HttpResponse) =>
    {
        // this will be called once
        Console.WriteLine($"EnrichWithHttpRequest was called for activity: {activity.Id}");
    };
});

Expected behavior

N/A

Actual behavior

N/A

Reproduction Steps

N/A

Environment

No response

@TimothyMothra TimothyMothra self-assigned this Oct 24, 2024
@TimothyMothra TimothyMothra added the Monitor - Distro Monitor OpenTelemetry Distro label Oct 24, 2024
@github-actions github-actions bot added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Oct 24, 2024
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Oct 24, 2024
@TimothyMothra
Copy link
Contributor Author

I've opened an issue with the Instrumentation libraries as I believe this issue needs to be addressed there. open-telemetry/opentelemetry-dotnet-contrib#2247

@TimothyMothra
Copy link
Contributor Author

Confirmed this is an issue in the Instrumentation libraries and not the Azure Monitor libraries.
I'm closing this issue in favor of continuing the conversation in the OpenTelemetry repo

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. Monitor - Distro Monitor OpenTelemetry Distro
Projects
None yet
Development

No branches or pull requests

2 participants