-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Feature for setting activity tags on creation #62090
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
base: main
Are you sure you want to change the base?
Conversation
It may make sense to actually have the aspnetcore/src/Shared/Diagnostics/ActivityCreator.cs Lines 13 to 22 in 6ab9fa6
|
also fixed up unshipped API documentation
What's the scenario where you want to set activity tags on creation? This seems like kind of niche feature and I'd prefer to see whether the problem can be solved with existing APIs. For example, there is a feature to get the current request activity, |
Is the scenario that you set a feature with tags earlier in the request. Tags could be different depending on the request. An activity is created very early in a request so the number of places to set it would be limited. Can you give an example of this being used? Also, what does the activity source do with the tags? |
I'm specifically using YARP as a reverse proxy for a large number of services. There are calls for many different host names. I want to make tracing sampling decision for those calls and would like to have separate buckets for each hostname. For example, in a given time window, I want a minimum number of traces to always be sampled and then start doing probabilistic sampling after that. As it is now, I can only get the base operation name (just The only way to get tags to be available at the time of making the sampling decision is for them to be passed in to the The flow is:
I don't know of any other way to get information available to the sampler than to pass the tags in on Create/StartActivity. This is extra work for every request, even those that end up not sampled, which is why it does nothing by default and would require a user to specifically opt in with their own implementation for specifically the data points they need in their particular scenario. For example, the vast majority of our services would not use this functionality; only our YARP usage would define an implementation to just add the host/ |
The OpenTelemetry spec has this SHOULD requirement for tags available at span creation time:
It's not free to add those so making it possible but explicitly opt-in seems like a good change. |
Right now tracing in ASP.NET Core doesn't follow the OTEL standard. When we do then those tags should be set immediately. It sounds like server address and port are what you want to use when making sampling decisions, right? The performance cost shouldn't be a concern. We would only call ActivitySource if someone is listening to the activity, so people who care about perf and aren't listening won't be impacted. |
For our specific use case we would only use Performance impact of this change would be initializing the feature if it's registered and doing the feature lookup if there's a listener:
|
Feature for adding tags at Activity creation time
Summary of the changes
Adding a feature so that implementations can specify tags to add at Activity creation. This is to support using those tags when making sampling decisions as only tags provided in the
CreateActivity
/StartActivity
are available at that time.Description
Implementations of
IHttpActivityCreationTagsFeature
can determine what tags are desired to be used for sampling. It's important that this is an opt-in where the user specifies the tags to add since this work will get done for every Activity created for an incoming request and not just for the ones that eventually pass the sampling filter.Example implementation:
Fixes #50488