-
Notifications
You must be signed in to change notification settings - Fork 289
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
Activity.DisplayName is overwritten by instrumentation libraries #1948
Comments
@johncrim - DisplayName is set by instrumentation as per the specification. You can use Enrich callback to change it. Specifically similar example - open-telemetry/opentelemetry-dotnet#3977 (comment) |
@vishweshbankwar Given the fact this is commonly asked, its best to document the SpanName in the doc : https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Instrumentation.AspNetCore along with the correct way for users who wish to change it. |
Hi @vishweshbankwar - thank you for the response. My point with this issue is that it's problematic to only allow modifying it in the EnrichResponse. If I modify it in application code (for example, say I have a specific path where the In general, I think it's reasonable to expect that any telemetry values or attributes added throughout the request lifecycle will not be overwritten by the autoinstrumentation (unless there's a good reason for it).Otherwise, I have to debug this issue (which I did), and then in my app code set a value to use later, and then add an EnrichResponse handler to overwrite the value that the autoinstrumentation overwrote. Also, without stepping through the library code to figure out why and where it's being overwritten, a normal developer wouldn't figure out that for @cijothomas - Thanks for the reply. I'll add that the span name in the Azure Monitor exporter also effectively overwrites the value a second time, so even if I add an EnrichResponse callback (or Processor) to overwrite the |
Also: using |
@johncrim - Its actually the other way. If you are relying on auto-instrumentation, then in general you would not need to modify the tags or display name set by the instrumentation. However, there are valid scenarios as you shared in example where the modification is needed and for such scenarios Enrich callbacks are provided to override that behavior.
Http instrumentation provides the Enrich callbacks as well. https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Instrumentation.Http#enrich-httpclient-api |
This seems like the wrong approach to me. Are you trying to make it more difficult to use? Giving the developer the ability to add to the default telemetry is important. I think it's unrealistic to think that the autoinstrumentation provides the right answer all of the time. Escape hatches / allowing intuitive overrides is important.
I'm aware of that. However that means 2 places to make the same change, and 2 places to document DisplayName and support developers when they can't figure out why it's being overwritten. |
@johncrim Would it be better to offer an option in the instrumentation library (By next year, we expect Asp.Net Core to natively produce span with right names. So at that point, we should make sure they also allow such flexibility (or provide more useful name by default) ) |
@cijothomas - I think it's desirable for the instrumentation library to provide a good default (which it does), but not overwrite a value that the developer (or another instrumentation library) set. I think it's very desirable for the value to be settable during request processing (it's likely only for certain code paths that I would want to change from the default), and not have it overwritten later. I think adding an option to not set the DisplayName at all (if I'm understanding you right) would do more harm than good, because most of the time I want the default value. And any new config option has the potential for adding complexity and thus adding to support load. Since the final default DisplayName can't be computed when the Activity is started (the route hasn't been determined yet), I understand why the DisplayName is set when the Activity is stopped. I think a fix could be as simple as:
Then do the same for the HttpClient activity (I think the same logic would work, but I haven't stepped through it as much). This should work for only setting a default value when the developer or any other instrumentation library has not set it. I agree that it's not pretty, but seems reasonable. |
Another option (if you don't like the proposal above) is:
|
I think this looks reasonable. If user ever changes this to something else, then instrumentation should not bother to update it, as user has already overwrote it with something other than the default. This may not be perfect solution, but I don't think there is any other easy way to "don't override displayname, if user has already modified it from the default". (Agree that my other suggestion of adding an option is not very good.) |
@vishweshbankwar could you comment on the approach suggested by @johncrim ? i.e instrumentation should not update display name, if it is something other than the default value.? The same agreement must be honored by asp.net core native instrumentation as well in the future, else it'll break users. |
I am ok with the changes proposed but I think we should wait for the final design on dotnet/aspnetcore#52439 due to risk of a breaking change in the future. Would like to see what the general guidance for changing defaults would be. Apart from Http instrumentation coming up in |
Component
OpenTelemetry.Instrumentation.AspNetCore
OpenTelemetry.Instrumentation.Http
Package Version
Runtime Version
net8.0
Description
It should be possible to set the
Activity.DisplayName
in application code to provide a more useful span name than the default auto-instrumented value. For bothOpenTelemetry.Instrumentation.AspNetCore
andOpenTelemetry.Instrumentation.Http
any value stored in.DisplayName
before the Activity is stopped is subsequently overwritten by the instrumentation library.Steps to Reproduce
Here's a test that should pass IMO:
Expected Result
Passing test
Actual Result
The test fails because
Activity.DisplayName
is overwritten when the Activity is stopped.Additional Context
A workaround is to store the
.DisplayName
value you want inActivity.SetCustomProperty()
, then add a processor that reads that value and if present sets theActivity.DisplayName
after it has stopped.The same logic is present in OpenTelemetry.Instrumentation.Http. I haven't checked the other instrumentation libraries, but I wouldn't be surprised in this pattern is pervasive.
Related to #1744 and possibly #1792
The text was updated successfully, but these errors were encountered: