To configure Golang Datadog tracing to add tracing details to outbound requests, follow these steps:
Import the datadog namespace:
import "gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
Create a new Datadog HTTP client:
client := &http.Client{Transport: &ddtrace.Transport{}}
Use the client to make HTTP requests:
req, _ := http.NewRequest("GET", "https://example.com", nil)
resp, _ := client.Do(req)
When making HTTP requests, the Datadog tracer will automatically add a x-datadog-trace-id
header to the outgoing request. This header contains the Datadog trace ID.
You can also add custom span tags to the outgoing request by using the Datadog tracer:
span, _ := tracer.StartSpanFromContext(ctx, "outgoing.http.request")
span.SetTag("http.method", req.Method)
span.SetTag("peer.hostname", req.URL.Hostname())
tracer.Stop()
By following these steps, you will be able to add tracing details to outbound requests using Golang Datadog tracing.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-09-25 11:00:00 +0000
Seen: 12 times
Last updated: Jun 25 '21