Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
When doing sampling with Activity/Traces, the information that you have to make the decision on whether to Sample or Drop is only that which is passed in as tags to Start/CreateActivity method. Sampling at the Head (root activity) is the most efficient method as it allows child activitys to inherit that decision and therefore reduce processing. You can sample at an individual (child) activity level too.
Right now, there is very little information to go on when trying to apply Head Sampling in a .NET application. This is because of the Activity being created having no tags being used as part of the Create.
This means that the samplers can only base their decision on the parent context.
In order to use other contextual information, you need to use something like the IHttpContextAccessor to access the ambient context.
Describe the solution you'd like
What would make this better from a consumer perspective would be an extension point to augment the activity tags at creation time.
I don't know if Features for HTTP are available to get during the pipeline, however, something like the following
interface IHttpActivityEnrichmentFeature
{
ActivityTagsCollection OnCreate(HttpContext context);
void PostCreate(Activity activity, HttpContext context);
}
This would allow users to do that enrichment at the right time. It would allow the level of data being used to be configured according to the performance concerns of the user.
Additional context
No response
Activity
joegoldman2 commentedon Sep 1, 2024
What do you think about renaming the two methods to
ActivityCreating
andActivityCreated
?This convention is already used in some places like https://github.com/dotnet/efcore/blob/main/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs.
rkargMsft commentedon May 23, 2025
Taking a look at this.
Ideally, if something like the host or method were added at Create time then it wouldn't also be added again later after an Activity passes the sampling check but I don't see a clean way to avoid that duplicate work right now.
Maybe that extra work of setting it twice, only for the sampled Activity case, isn't that big of a deal?
rkargMsft commentedon May 23, 2025
Adding feature as a hook for users to be able to specify what tags should be added on creation