Skip to content
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

Add Enrich to OnCustom in HttpInListener #2948

Closed
Tornhoof opened this issue Feb 25, 2022 · 1 comment
Closed

Add Enrich to OnCustom in HttpInListener #2948

Tornhoof opened this issue Feb 25, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Tornhoof
Copy link
Contributor

Feature Request

All the main HttpInListener methods call the Enrich functor to add additional data to the activity, e.g. OnStartActivity, OnStopActivity, OnException. Only OnCustom does not.
I suggest adding to:

public override void OnCustom(string name, Activity activity, object payload)
{
if (name == "Microsoft.AspNetCore.Mvc.BeforeAction")
{
if (activity.IsAllDataRequested)
{
// See https://github.com/aspnet/Mvc/blob/2414db256f32a047770326d14d8b0e2afd49ba49/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreDiagnosticSourceExtensions.cs#L36-L44
// Reflection accessing: ActionDescriptor.AttributeRouteInfo.Template
// The reason to use reflection is to avoid a reference on MVC package.
// This package can be used with non-MVC apps and this logic simply wouldn't run.
// Taking reference on MVC will increase size of deployment for non-MVC apps.
_ = this.beforeActionActionDescriptorFetcher.TryFetch(payload, out var actionDescriptor);
_ = this.beforeActionAttributeRouteInfoFetcher.TryFetch(actionDescriptor, out var attributeRouteInfo);
_ = this.beforeActionTemplateFetcher.TryFetch(attributeRouteInfo, out var template);
if (!string.IsNullOrEmpty(template))
{
// override the span name that was previously set to the path part of URL.
activity.DisplayName = template;
activity.SetTag(SemanticConventions.AttributeHttpRoute, template);
}

try
{
    this.options.Enrich?.Invoke(activity, "OnCustom", payload);
}
catch (Exception ex)
{
    AspNetCoreInstrumentationEventSource.Log.EnrichmentException(ex);
}

This would allow adding more data from the payload, including additional information from the Action, e.g. other attributes or different routeData information.
Example: I use an extended version of the routing attributes to match incoming routes based on extra headers, similar to the concepts described in 5 levels of Hypermedia and the extra information would be useful as tag data.

@Tornhoof Tornhoof added the enhancement New feature or request label Feb 25, 2022
@vishweshbankwar
Copy link
Member

PR removes this event subscription: #5026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants