英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论