[bug] Enrich methods can be called multiple times. #2247
Labels
bug
Something isn't working
comp:instrumentation.http
Things related to OpenTelemetry.Instrumentation.Http
Component
OpenTelemetry.Instrumentation.Http
Package Version
Runtime Version
net8.0
Description
I've verified this behavior with the Http and AspNetCore Instrumentation libraries, but I suspect it applies to all Instrumentation libraries. For the sake of conversation, I'm going to focus on the HttpClient Instrumentation.
When configuring OpenTelemetry Instrumentation Libraries, if the
AddHttpClientInstrumentation()
method is called multiple times, any configured method delegates will be called multiple times.This can be a problem when users consume a Distro package, such as Azure.Monitor.OpenTelemetry.AspNetCore.
In this example, the Distro internally adds Instrumentation Libraries.
If a user wants to add their configuration to these instrumentations, they may call
AddHttpClientInstrumentation()
an additional time to set their options.Workaround
For the sake of conversation, I'm going to focus on the HttpClient Instrumentation.
As a workaround, users should use the Configure api
builder.Services.Configure<HttpClientTraceInstrumentationOptions>()
.Steps to Reproduce
EXAMPLE 1: HttpClient Instrumentation
OUTPUT
EXAMPLE 2: AspNetCore Instrumentation
OUTPUT
EXAMPLE 3: AzureMonitor Distro
Internally,
UseAzureMonitor()
already callsAddAspNetCoreInstrumentation
.Here a user may call this an additional time to set their own customizations.
Expected Result
configured delegates would only be called once.
Actual Result
configured delegates are called however many times that Instrumentation library was added.
Additional Context
No response
The text was updated successfully, but these errors were encountered: