Description
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.
- Migrating to ActivitySource API - replacing new Activity() with ActivitySource.StartActivity() is a breaking change, as Activity may or may not be created when using ActivitySource. To avoid this breaking change, it is proposed to create a dummy
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.
- Populate the necessary tags. (as per OpenTelemetry semantic conventions) - This is optional, if replace batch files with kvm #3 is continued, as a listener can listen to DiagnosticSource events, and populate Tags as needed.
- The DiagnosticSource events may continue to be fired.
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
and Recorded
fields.
Additional context
Related issue: #28642