.NET Core 中如何生成 HttpContext TraceIdentifier? [英] How is HttpContext TraceIdentifier generated in .NET Core?

查看:25
本文介绍了.NET Core 中如何生成 HttpContext TraceIdentifier?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpContext TraceIdentifier(又名 Correlation-Id)是如何生成的?

How is HttpContext TraceIdentifier (aka Correlation-Id) generated?

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

I request a page through controller which gives me the following TraceId: 0HLEACIU86PT6:0000000D

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

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?

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

Why didn't I get the same TraceIdentifier?

如何确保相同的 TraceIdentifier?

How can I ensure the same TraceIdentifier?

推荐答案

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

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.cs"com/aspnet/KestrelHttpServer/blob/a48222378b8249a26b093b5b835001c7c7b45815/src/Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs

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

这篇关于.NET Core 中如何生成 HttpContext TraceIdentifier?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆