[英]How can I access W3C TraceContext Headers in a .net core 3.1 application?
These sources ( microsoft docs , microsoft dev blog ) state that in order to use the new W3C Trace Context Headers in a .net 3.0+ core application no extra configuration is required.这些来源( 微软文档, 微软开发博客)state,为了在 .net 3.0+ 核心应用程序中使用新的W3C 跟踪上下文标头,不需要额外的配置。 However, we are not receiving traceparent or tracestate from any request made via a ServiceClient.
但是,我们没有从通过 ServiceClient 发出的任何请求中接收到 traceparent 或 tracestate。
What is the proper setup process?正确的设置过程是什么? How did you guys get access to a distributed trace id?
你们是如何获得分布式跟踪 ID 的? We prefer to expose those values automaticaly without adding a lot of code to all existing services, if that's possible.
如果可能的话,我们更愿意在不向所有现有服务添加大量代码的情况下自动公开这些值。
Thank you very much in advance!非常感谢您!
PS: this is my first question here; PS:这是我的第一个问题; please let me know if you need further information
如果您需要更多信息,请告诉我
The System.Diagnostics.Activity
Id in .net 5 has already been configured as the w3c standard . .net 5 中的
System.Diagnostics.Activity
Id 已配置为w3c 标准。 It means that all Actions
will be identifiable by a traceparent
id format and both traceparent
and tracestate
will be sent to downstream dependencies in the http
request header.这意味着所有
Actions
都可以通过traceparent
id 格式识别,并且traceparent
和tracestate
都将发送到http
请求 header 中的下游依赖项。 As you said, no extra configuration is required, but in .net 3 is different, the default id format is the Hierarchical
one and it's downstream propagated as a HeaderRequestId
.正如你所说,不需要额外的配置,但在 .net 3 中是不同的,默认的 id 格式是
Hierarchical
的,它作为HeaderRequestId
向下传播。 To see the Activity Id format, import the System.Diagnostics
to your class and type: Console.WriteLine(Activity.Current.Id)
, you'll see a format like this: |fab6082c-46326cca135ffe48.1.
要查看 Activity Id 格式,请将
System.Diagnostics
导入 class 并键入: Console.WriteLine(Activity.Current.Id)
,您将看到如下格式: |fab6082c-46326cca135ffe48.1.
. . To change it to the w3c format in .net 3 is required to force it in your main method:
要将其更改为 .net 3 中的 w3c 格式,需要在您的 main 方法中强制它:
public static void Main(string[] args)
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;
CreateHostBuilder(args).Build().Run();
}
Then, you'll see w3c's format and also the traceparent
and tracestate
fields been propagated to the downstream dependencies in the header.然后,您将看到 w3c 的格式以及
traceparent
和tracestate
字段已传播到 header 中的下游依赖项。
If you want to send messages throw a broker, use the application-properties
section in case of AMQP calls .如果你想发送消息抛出一个代理,在AMQP 调用的情况下使用
application-properties
部分。 You'll find some examples of both cases here and here .您可以在此处和此处找到这两种情况的一些示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.