我应该在请求标头中使用Request

编程入门 行业动态 更新时间:2024-10-17 07:33:22
本文介绍了我应该在请求标头中使用Request-Id,X-Request-Id或X-Correlation-Id吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不清楚出于关联性的目的应在请求和响应中放入哪个id头.

I am not clear which id header I should put in the request and response for the correlationship purpose.

"X-Correlation-ID"和"X-Request-ID"是已知的http标头.在请求和响应中使用哪一个无关紧要?

"X-Correlation-ID" and the "X-Request-ID" are the known http header. Does it matter which one I use in the request and response?

ASP.NET Core的System.Diagnostics.DiagnosticSource查找请求ID".这仅用于活动目的吗?为什么不使用"X-Request-ID"?

ASP.NET Core's System.Diagnostics.DiagnosticSource looks for the "Request-Id". Is this for the Activity purpose only? Why doesn't it use the "X-Request-ID"?

如果我不使用活动,则不需要发送该标头,对吗?

If I don't use the Activity, I don't need to send that header, right?

ASP.NET Core还具有分层请求ID( github/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/HierarchicalRequestId.md ),我喜欢这个主意.我可以做这样的事情

ASP.NET Core also has the Hierarchical Request-Id (github/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/HierarchicalRequestId.md ) that I like the idea. I can do something like this

var newRequestId = $"{context.Request.headers["X-Correlation-ID"]}:{CreateNewGuid()}";

或者使用活动"更好吗?我发现Activity.Current始终为null.是否需要启用它并且会影响性​​能?

OR is it better to use the Activity? I find the Activity.Current is always null. Does it need to be enabled and does it affect performance?

推荐答案

对于 Request-Id ,它唯一标识操作处理中涉及的每个HTTP请求,并在调用方生成并传递给被呼叫者.

For Request-Id, it's uniquely identifies every HTTP request involved in operation processing, and is generated on the caller side and passed to callee.

对于 X-Correlation-ID ,也称为传输ID",是唯一的标识符值,附加到允许引用特定事务或事件链的请求和消息上.

For X-Correlation-ID, also known as a Transit ID, is a unique identifier value that is attached to requests and messages that allow reference to a particular transaction or event chain.

对于每个请求,应使用 Request-Id ,对于请求事务,应使用 X-Correlation-ID .

For every request, you should use Request-Id, for request transaction, you should use X-Correlation-ID.

如果我不使用活动,则不需要发送该标头,对吗?

If I don't use the Activity, I don't need to send that header, right?

通常,对于相关ID",您不必使用一个.但是,如果您要设计一个包含消息队列和异步处理的分布式系统,那么最好在消息中包含一个Correlation ID.

For Correlation ID, in general, you don’t have to use one. But if you are designing a distributed system that incorporates message queues and asynchronous processing, you will do well to include a Correlation ID in your messages.

我发现Activity.Current始终为null.是否需要启用它并且会影响性​​能?

I find the Activity.Current is always null. Does it need to be enabled and does it affect performance?

要使用 Activity.Current ,您需要能够 ApplicationInsights ,或实现自己的功能来管理活动.

For using Activity.Current, you need to able ApplicationInsights, or implement your own feature to manage activity.

  • 安装 Microsoft.ApplicationInsights.AspNetCore
  • 配置 WebHost.CreateDefaultBuilder(args).UseStartup< Startup>().UseApplicationInsights()
  • 使用类似 var activity = Activity.Current;
  • 更多推荐

    我应该在请求标头中使用Request

    本文发布于:2023-11-14 19:58:59,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1588379.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:标头中   Request

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!