Skip to content

Add Enrich to OnCustom in HttpInListener #2948

@Tornhoof

Description

@Tornhoof

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions