如何在.net核心中生成HttpContext TraceIdentifier?

Dar*_*der 14 c# http .net-core asp.net-core

如何生成HttpContext TraceIdentifier,又称Correlation-Id?

我通过控制器请求一个页面,它给了我以下TraceId: 0HLEACIU86PT6:0000000D

该页面将触发一个具有以下TraceId的ajax调用: 0HLEACIU86PT7:00000005

你可以看到它们非常相似.是基于时间吗?

为什么我没有得到相同的TraceIdentifier?

如何确保相同的TraceIdentifier?

dav*_*owl 27

Kestrel生成请求ID为{ConnectionId}:{Request number}.连接ID是使用字母1-9和A-V的long的base32编码版本.请求计数是通过该连接的请求数.对特定连接的第n个请求是{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

  • @davidfowl 有没有办法覆盖 Kestrel 生成 CorrelationId 的方式?我想让它始终使用 GUID。 (4认同)
  • 以及如何生成“ConnectionId”? (2认同)
  • https://github.com/aspnet/KestrelHttpServer/blob/a48222378b8249a26b093b5b835001c7c7b45815/src/Kestrel.Core/Internal/Infrastruct/CorrelationIdGenerator.cs (2认同)