Network Performance Monitoring is now generally available! Network Monitoring is now available!

Tracing Go Applications

Installation and Getting Started

For configuration instructions and details about using the API, see the Datadog API documentation. For manual instrumentation, use the integrations section below for Go libraries and frameworks supporting automatic instrumentation.

For a description of the terminology used in APM, see the Getting started with APM section. For details about contributing, check the official repository

Consult the migration document if you need to migrate from an older version of the tracer (e.g. v<0.6.x) to the newest version.


If you already have a Datadog account you can find step-by-step instructions in our in-app guides for host-based and container-based set ups.

First install and configure the Datadog Agent. See the additional documentation for tracing Docker applications or Kubernetes applications.

Next, install the Go tracer from its canonical import path:

go get

You are now ready to import the tracer and start instrumenting your code.

Automatic Instrumentation

Datadog has a series of pluggable packages which provide out-of-the-box support for instrumenting a series of libraries and frameworks. Find the list of supported integrations below.


To begin tracing your Go applications, your environment must first meet the following requirements:

  • Runing the Datadog Agent >= 5.21.1.
  • Using Go 1.9+


Framework Compatibility

Integrate the Go tracer with the following list of web frameworks using one of the following helper packages.

FrameworkSupport TypeGoDoc Datadog Documentation
Gorilla MuxFully
gRPC v1.2Fully

Library Compatibility

The Go tracer includes support for the following data stores and libraries.

LibrarySupport TypeExamples and Documentation
HTTP routerFully
Redis (go-redis)Fully
Redis (redigo)Fully
Kafka (confluent)Fully
Kafka (sarama)Fully
Google APIFully

Note: The integrations documentation provides a detailed overview of the supported packages and their APIs, along with usage examples.

Packages must be imported, i.e.:



The tracer is configured with options parameters when the Start function is called. An example for generating a trace using the HTTP library:

package main

import (

    httptrace ""

func sayHello(w http.ResponseWriter, r * http.Request) {
    msg: = "Hello " + strings.TrimPrefix(r.URL.Path, "/")
    w.Write([] byte(msg))

func main() {
    // start the tracer with zero or more options
    defer tracer.Stop()

    mux: = httptrace.NewServeMux() // init the http tracer
    mux.HandleFunc("/", sayHello) // use the tracer to handle the urls

    err: = http.ListenAndServe(":9090", mux) // set listen port
    if err != nil {
        log.Fatal("ListenAndServe: ", err)

For more tracer settings, see available options in the configuration documentation.

B3 Headers Extraction and Injection

The Datadog APM tracer supports B3 headers extraction and injection for distributed tracing.

Distributed headers injection and extraction is controlled by configuring injection/extraction styles. Two styles are supported: Datadog and B3.

Configure injection styles using the environment variable DD_PROPAGATION_STYLE_INJECT=Datadog,B3

Configure extraction styles using the environment variable DD_PROPAGATION_STYLE_EXTRACT=Datadog,B3

The values of these environment variables are comma separated lists of header styles that are enabled for injection or extraction. By default only the Datadog extraction style is enabled.

If multiple extraction styles are enabled, extraction attempts are made in the order that those styles are specified. The first successfully extracted value is used.

Change Agent Hostname

Configure your application level tracers to submit traces to a custom Agent hostname:

The Go Tracing Module automatically looks for and initializes with the ENV variables DD_AGENT_HOST and DD_TRACE_AGENT_PORT

package main

import (


func main() {
    addr := net.JoinHostPort(
    defer tracer.Stop()

Further Reading