open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.27k stars 769 forks source link

Track Cancelled/Aborted Request #5302

Open cliedeman opened 10 months ago

cliedeman commented 10 months ago

Feature Request

I would like to track the percentage of aborted/cancelled http server requests

Describe the solution you'd like:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httpcontext.requestaborted?view=aspnetcore-8.0

Describe alternatives you've considered.

Custom Enrichment

Additional Context

Add any other context about the feature request here.

cijothomas commented 10 months ago

Can you clarify the ask some more?

cliedeman commented 10 months ago

Sure.

Here is an example of how we could do it with enrich.

                    .AddAspNetCoreInstrumentation(opts =>
                    {
                        opts.Enrich = (string _, HttpContext context, ref TagList tags) =>
                        {
                            tags.Add("cancelled", context.RequestAborted.IsCancellationRequested);
                        };
                    })
cijothomas commented 10 months ago

I see you are asking if the asp.net core instrumentation should do this by default, without having to write the Enrich? Then the answer is generally no, as the instrumentation follows otel conventions, and there isn't anything about "cancellation requested". It is possible to propose something to the Otel Semantic Conventions group, but its usually accepted for very common things. Your best bet would likely be to do such customizations via Enrich itself.

cliedeman commented 10 months ago

thanks @cijothomas that makes sense.

I looked around in the semantic conventions at this PR and this open issue

https://opentelemetry.io/docs/specs/semconv/http/http-spans/#common-attributes

According to the docs for error.type we could stipulate timeout or requestAborted in the error.type.

Currently a request would display as successful in the traces/metrics but actually be aborted (aka failed)?

github-actions[bot] commented 2 days ago

This issue was marked stale due to lack of activity and will be closed in 7 days. Commenting will instruct the bot to automatically remove the label. This bot runs once per day.