Ask Your Question
3

How can golang datadog tracing be configured to add tracing details to outbound requests?

asked 2021-09-25 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-06-25 16:00:00 +0000

ladyg gravatar image

To configure Golang Datadog tracing to add tracing details to outbound requests, follow these steps:

  1. Import the datadog namespace:
    import "gopkg.in/DataDog/dd-trace-go.v1/ddtrace"

  2. Create a new Datadog HTTP client:
    client := &http.Client{Transport: &ddtrace.Transport{}}

  3. Use the client to make HTTP requests:

req, _ := http.NewRequest("GET", "https://example.com", nil)
resp, _ := client.Do(req)
  1. 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.

  2. 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())
  1. Finally, close the tracer to ensure that all data is flushed to Datadog:
    tracer.Stop()

By following these steps, you will be able to add tracing details to outbound requests using Golang Datadog tracing.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2021-09-25 11:00:00 +0000

Seen: 12 times

Last updated: Jun 25 '21