How is HttpContext TraceIdentifier generated in .NET Core?
16,704
Solution 1
Kestrel generates the request ID as {ConnectionId}:{Request number}. The connection id is the base32 encoded version of a long using the alphabet 1-9, and A - V. The request count is the number of requests over that connection. The nth request over a specific connection is {ConnectionId}:{n}
Solution 2
It is DateTime.UtcNow.Ticks
base32 encoded.
Related videos on Youtube
Author by
DarthVader
Updated on September 21, 2020Comments
-
DarthVader over 3 years
How is HttpContext TraceIdentifier (aka Correlation-Id) generated?
I request a page through controller which gives me the following TraceId:
0HLEACIU86PT6:0000000D
The page fires an ajax call which has the following TraceId:
0HLEACIU86PT7:00000005
As you can see, they are very similar. Is it based on time?
Why didn't I get the same TraceIdentifier?
How can I ensure the same TraceIdentifier?
-
Brad almost 6 yearsThe page request and the AJAX request are two separate requests therefore different TraceId.
-
-
davidfowl almost 6 yearsThis implementation isn't used in Kestrel.
-
Konrad almost 6 yearsAnd how
ConnectionId
is generated? -
davidfowl almost 6 years
-
Dave Black over 4 years@davidfowl is there a way to override how Kestrel generates the CorrelationId? I'd like to have it always use a GUID.
-
Kiran B almost 3 yearsHi @DaveBlack The HttpContext.TraceIdentifier has get and set defined, So you can overwrite this in a middleware docs.microsoft.com/en-us/dotnet/api/…