简体   繁体   English

如何在 .net 核心 3.1 应用程序中访问 W3C TraceContext 标头?

[英]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 格式识别,并且traceparenttracestate都将发送到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 的格式以及traceparenttracestate字段已传播到 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.

相关问题 如何在 c# .net core 3.1 控制台应用程序中保存设置? - how to save settings in c# .net core 3.1 console application? 如何将DateTime .NET数据类型转换为W3C XML DateTime数据类型字符串并返回? - How do I convert DateTime .NET datatype to W3C XML DateTime data type string and back? 如何在我的 asp.net core 3.1 应用程序中播种用户和角色? - How can I seed users and roles in my asp.net core 3.1 application? 在 C# ASP.NET Core 3.1 应用程序中,我如何路由到 controller 然后查询字符串? - In a C# ASP.NET Core 3.1 application how do I route to a controller then query string? 如何在 .NET Core 3.1 项目中访问 ResourceManager class? - How do I access the ResourceManager class in a .NET Core 3.1 project? 如何在 .NET Core 3.1 的 C# 中检索域用户的所有本地组? - How can I retrieve all the local groups for a domain user in C# in .NET Core 3.1? 如何在 .Net Core 3.1 WPF 中运行交互外壳 - How can I run Interaction Shell in .Net Core 3.1 WPF 如何在共享服务器上托管的 ASP.Net Core 3.1 应用程序中存储生产机密,如连接字符串 - How can I store production secrets like connection string in ASP.Net Core 3.1 application, hosted on a shared server 我如何使用 Net Core 获取 Headers 值? - How can i get Headers value with Net Core? 使用.Net Core 3.1 Razor页面应用程序访问Class中的Session - Access Session in Class using .Net Core 3.1 Razor Pages Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM