dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.35k stars 9.99k forks source link

Retrieve traceId #17857

Closed chniter closed 4 years ago

chniter commented 4 years ago

Is your feature request related to a problem? Please describe.

I am trying to retrieve the traceId from server side that is attached on every HttpRequest. The Json response look like this:

{"type":"https://tools.ietf.org/html/rfc7235#section-3.1", "title":"Unauthorized", "status":401, "traceId":"|a08ab0a-4722acd640681cf6.1.1dfb8ec2_"}

Describe the solution you'd like

We can retrieve this value from: HttpContext.Request.Headers["Request-Id"] But why isn't the same as HttpContext.TraceIdentifier ?

davidfowl commented 4 years ago

This is the API: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.activity.id?view=netcore-3.1#System_Diagnostics_Activity_Id

But why isn't the same as HttpContext.TraceIdentifier ?

There are a couple of reasons:

That said, we should figure out how to stash the TraceIdentifier on the activity.

JunTaoLuo commented 4 years ago

Sounds like this issue has been answered.