opentelemetry-dotnet-contrib icon indicating copy to clipboard operation
opentelemetry-dotnet-contrib copied to clipboard

aspnet instrumentation zipkin exporter span name is router template

Open SimTsai opened this issue 4 years ago • 3 comments

Question

Describe your environment.

.netfx 4.8 opentelemetry-dotnet 1.0.0-rc1.1

What are you trying to achieve?

current zipkin span name is router template if use asp.net mvc default route template, all span name is same, indistinguishable. should it be "http.path" value?

Additional Context

[
    {
        "traceId": "96f718411e470c43ab817025b77cfd06",
        "name": "api/{controller}/{action}/{id}",
        "id": "8ee946841c01fc43",
        "kind": "SERVER",
        "timestamp": 1608102106455063,
        "duration": 172749,
        "localEndpoint": {
            "serviceName": "mp",
            "ipv4": "192.168.1.251",
            "ipv6": "fe80::a096:4ad4:ac95:fbf0"
        },
        "annotations": [],
        "tags": {
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.language": "dotnet",
            "telemetry.sdk.version": "1.0.0.1",
            "http.host": "localhost:4469",
            "http.method": "POST",
            "http.path": "/api/Auth/Login",
            "http.user_agent": "PostmanRuntime/7.26.8",
            "http.url": "http://localhost:4469/api/Auth/Login",
            "http.status_code": "200",
            "otel.status_code": "0",
            "http.route": "api/{controller}/{action}/{id}",
            "otel.library.name": "OpenTelemetry.Instrumentation.AspNet",
            "otel.library.version": "1.0.0.1"
        }
    }
]

SimTsai avatar Dec 16 '20 07:12 SimTsai

when OnStartActivity activity.DisplayName is "http.path" value howevey OnStopActivity activity.DisplayName is router template

related code

SimTsai avatar Dec 17 '20 05:12 SimTsai

I am having the same problem as @simhgd in an earlier version of ASP.NET . I am working around it like below in global.asax.cs (see OnStopActivity enrichment)

    protected void Application_Start()
    {
        this.tracerProvider = Sdk.CreateTracerProviderBuilder()
        .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyASPNETWebApplication"))
        .AddAspNetInstrumentation((options) => options.Enrich
        = (activity, eventName, rawObject) =>
        {
            if (eventName.Equals("OnStartActivity"))
            {
                if (rawObject is HttpRequest httpRequest)
                {
                    activity.SetTag("physicalPath", httpRequest.PhysicalPath);
                }
            }
            else if (eventName.Equals("OnStopActivity"))
            {
                if (rawObject is HttpResponse httpResponse)
                {
                    activity.SetTag("responseType", httpResponse.ContentType);
                    if (activity.Tags.Where(x => x.Key == "http.path").Any())
                    {
                        activity.DisplayName = activity.Tags.Where(x => x.Key == "http.path").First().Value;
                    }
                }
            }
        })
        .AddZipkinExporter(c =>
        {
            c.ServiceName = "MyASPNETWebApplication";
            c.Endpoint = new Uri("http://zipkin/api/v2/spans");
            c.ExportProcessorType = ExportProcessorType.Simple;
        })
        .Build();

        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);


    }

philipbawn avatar Jan 22 '21 22:01 philipbawn

@simhgd If possible, could you add a couple of examples of the values you are seeing?

In general, the spec is pretty clear about the names being low cardinality. Check out Semantic conventions for HTTP spans. It basically says incoming spans should be the generic route (eg /user/{userId} not /user/1234) and outgoing spans are even worse, usually "HTTP [METHOD]" because we don't have any template available.

It does say we can add options to change the behavior, which we should do 😄

CodeBlanch avatar Jan 30 '21 00:01 CodeBlanch