Connecting Go Logs and Traces
Datadog の調査レポート: サーバーレスの状態 レポート: サーバーレスの状態

Connecting Go Logs and Traces


Automatically Inject Trace and Span IDs

Coming Soon. Reach out to the Datadog support team to learn more.

Manually Inject Trace and Span IDs

The Go tracer exposes two API calls to allow printing trace and span identifiers along with log statements using exported methods from SpanContext type:

package main

import (


func handler(w http.ResponseWriter, r *http.Request) {
    // Create a span for a web request at the /posts URL.
    span := tracer.StartSpan("web.request", tracer.ResourceName("/posts"))
    defer span.Finish()

    // Retrieve Trace ID and Span ID
    traceID := span.Context().TraceID()
    spanID := span.Context().SpanID()

    // Append them to log messages as fields:
    log.Printf("my log message dd.trace_id=%d dd.span_id=%d", traceID, spanID)

The above example illustrates how to use the span’s context in the standard library’s log package. Similar logic may be applied to 3rd party packages too.

Note: If you are not using a Datadog Log Integration to parse your logs, custom log parsing rules need to ensure that dd.trace_id and dd.span_id are being parsed as strings. More information can be found in the FAQ on this topic.

Further Reading