Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.