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

aspnet instrumentation zipkin exporter span name is router template #1782

Open
SimTsai opened this issue Dec 16, 2020 · 3 comments
Open

aspnet instrumentation zipkin exporter span name is router template #1782

SimTsai opened this issue Dec 16, 2020 · 3 comments
Labels
bug Something isn't working comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet question Further information is requested

Comments

@SimTsai
Copy link

SimTsai commented Dec 16, 2020

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 SimTsai added the question Further information is requested label Dec 16, 2020
@SimTsai
Copy link
Author

SimTsai commented Dec 17, 2020

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

related code

@philipbawn
Copy link

philipbawn commented Jan 22, 2021

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);


    }

@cijothomas cijothomas added the bug Something isn't working label Jan 22, 2021
@CodeBlanch
Copy link
Member

@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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants