-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Migrate to use ActivitySource API to create Activities in AspNetCore Hosting #29132
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
Comments
@alanwest @CodeBlanch from OpenTelemetry .NET group |
This is technically a behavior change in that the Also, as mentioned in the issue, we need to address the scenario where no activity is created. I'm not a fan of creating a dummy listener. I'd prefer if |
👀 @JamesNK we might want to make a similar change in gRPC |
And in HttpClient.. and Asp.Net (its separate package for aspnet) too. |
Grpc.Net.Client multitargets .NET Core 3. Is it worth having the legacy method in .NET Core 3, and creating activities with the new method in .NET 5+? |
All suggestions here are good. Only we need to be careful not breaking current working scenarios. e.g. if someone today creating DiagnosticsListener to listen for such cultures properly they will be broken if we didn't do something to make this work.
Why creating simple ActivityListener is not good here. it s a few lines: using ActivityListener listener = new ActivityListener();
listener.ShouldListenTo = (activitySource) => object.ReferenceEquals(aSource, activitySource);
listener.SampleUsingParentId = (ref ActivityCreationOptions<string> activityOptions) => ActivitySamplingResult.AllData;
listener.Sample = (ref ActivityCreationOptions<ActivityContext> activityOptions) => ActivitySamplingResult.AllData; but not a problem to explore the request and discuss it. |
Couple thoughts:
I am guessing Grpc.Net.Client is an out-of-band NuGet package? I'm not sure how this will play out yet by my hunch is that we would ship Grpc.Net.Client v.next with an assembly reference to Microsoft.Diagnostics.DiagnosticSource.dll v.next and both of these packages are capable of targetting .NET Core 3 if that is where developers wish to deploy them. It will probably be simpler maintaining only one code path rather than maintaining separate v3 and >v3 codepaths. I was trying to find where Grpc code created Activities for incoming messages but my github-foo was failing me. I found what looked like the Activity name but not where it was being used to create activities. I'm glad to take a closer look if you can point at the right spot? |
I meant to say - we should fully retain existing behavior. If an Activity would have been created currently, we should still create it. If not, we shouldn't either. |
Thanks for contacting us. |
I'm allergic to making this code more complex and less performant. I think we'll need to spend some dedicated time figuring out how to move this logic outs of the critical path so it's more amenable to changes |
Grpc.Net.Client creates an activity here - https://github.com/grpc/grpc-dotnet/blob/d8d982b29182e99a956f71963455c8cd5496e915/src/Grpc.Net.Client/Internal/GrpcCall.cs#L660-L750 |
What do you consider the critical path? If critical path means code that runs for:
I wouldn't assume that is the result : )
Thanks! This usage looks simpler the Kestrel host. I'm optimistic that we could write something that wouldn't add too much complexity and it would handle both DiagnosticListener and ActivityListener regardless of which .NET Core version is installed. |
Did you consider keeping the code paths independent and producing activity for DiagnosticSource and one for AcitivitySource depending on what's enabled? Sometimes you might get two activities if two independent listeners subscribe to the same thing but at least it keeps the back-compat story simple. |
Is your feature request related to a problem? Please describe.
AspNetCore uses Activity API along with DiagnosticSource/Listener API to emit telemetry/diagnostic events. https://github.com/dotnet/aspnetcore/blob/master/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Its currently using the new Activity() method to create an Activity. In .NET 5.0, a new mechanism was introduced to create Activity. The new API is based on
ActivitySource
. It offers following advantages:ActivitySource
allows setting proper Kind to be set on Activity, instead of the defaultInternal
.ActivitySource
assigns correct ActivitySource to Activity. (instead of a default ActivitySource which has "" name)ActivitySource
runs through the Sampler before deciding to create the activity and creates Activity with correct values forIsAllDataRequested
andRecorded
. This allows connecting samplers to control Activity creation and is in alignment with OpenTelemetry specifications. Since AspNetCore does not use ActivitySource API, Activity is always created without the ability to configure Sampler.Describe the solution you'd like
A clear and concise description of what you want to happen. Include any alternative solutions you've considered.
ActivityListener
, which will setSamplingResult
toPropagationData
. This ensures that activity will always be created (thus maintaining backward compatibility).OpenTelemetry (or other telemetry systems) can setup additional Listeners and achieve its needs.
Once the above is achieved, OpenTelemetry instrumentations can avoid the current hacks it deploys to workaround the limitations. As of now, OpenTelemetry uses reflection to set Kind, Source on Activity, and runs samplers to correctly set
IsAllDataRequested
andRecorded
fields.Additional context
Related issue: #28642
The text was updated successfully, but these errors were encountered: