Golang的Datadog追踪功能可以在发送的请求中包含追踪信息。

huangapple go评论99阅读模式
英文:

golang datadog tracing include trace information in outgoing requests

问题

我正在使用golang和datadog进行跟踪,我的简化设置如下:

客户端 -> 服务1 -> 服务2

服务1中,我使用gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux,以便正确记录来自客户端的跟踪和跨度信息。现在,当我从服务1调用服务2时,我希望在发送的请求中包含相同的信息,以便正确地连接跟踪信息。然而,我认为gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux包不会自动执行此操作,这个假设正确吗?如果是这样的话,我需要编写一些中间件到路由器中,以提取这些信息并将其存储以便在任何外发请求中使用。这种方法正确吗?还是有更简单的方法来实现这个?

英文:

I'm using golang and datadog for tracing and my simplified setup is as follows

client -> service 1 -> service 2

in service 1 I'm using gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux so that the trace and span information are logged properly which originate from the client. Now when I call service 2 from service 1 I want to include this same information in the request going out so that the trace information is stitched correctly. However I don't think the gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux package does this automatically, is this assumption correct ? if so then I need to write some middleware to the router which extracts this information and stores it to be used later in any outgoing request. Is this the correct approach to this or is there a simpler method to do this ?

答案1

得分: 1

是的,你需要在某个地方编写一些代码来在服务之间传播追踪上下文,以创建分布式追踪。假设这两个服务都是使用Go编写的,文档中有一个简短的示例展示了客户端和服务器的代码。确保你也阅读了文档中关于不同传播选项的介绍,因为有几种不同的标准可供选择。

英文:

Yes, you'll need some code somewhere to propagate the trace context between the services to create a distributed trace. Assuming both services are in Go, the docs have a short example of the client and server. Make sure you read about the different propagation options on the docs as well, there are a few different standards.

huangapple
  • 本文由 发表于 2023年3月29日 17:52:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75875649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定