34

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?

1
  • 4
    The page request and the AJAX request are two separate requests therefore different TraceId.
    – Brad
    Commented Jun 4, 2018 at 23:09

2 Answers 2

58

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}

https://github.com/aspnet/KestrelHttpServer/blob/a48222378b8249a26b093b5b835001c7c7b45815/src/Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs

https://github.com/aspnet/KestrelHttpServer/blob/0aff4a0440c2f393c0b98e9046a8e66e30a56cb0/src/Kestrel.Core/Internal/Http/Http1Connection.cs#L446

4
1

It is DateTime.UtcNow.Ticks base32 encoded.

https://github.com/aspnet/HttpAbstractions/blob/87cd79d6fc54bb4abf07c1e380cd7a9498a78612/src/Microsoft.AspNetCore.Http/Features/HttpRequestIdentifierFeature.cs

1
  • 2
    This implementation isn't used in Kestrel.
    – davidfowl
    Commented Jun 5, 2018 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.