---
title: Configuring the Go Tracing Library
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > APM > Application Instrumentation > Configure the Datadog Tracing
  Library > Configuring the Go Tracing Library
---

# Configuring the Go Tracing Library

After you [set up the tracing library with your code, configure the Agent to collect APM data, and activate the Go integration](https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/go), start the tracer and configure the library as desired. **Note**: This documentation uses v2 of the Go tracer, which Datadog recommends for all users. If you are using v1, see the [migration guide](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/go/migration) to upgrade to v2.
To verify your runtime configuration and confirm settings, view the current configuration of your service in Datadog. Navigate to the **APM Service Page**, click **Service Config**, and select the **SDK Configuration** tab.
Datadog recommends using `DD_ENV`, `DD_SERVICE`, and `DD_VERSION` to set `env`, `service`, and `version` for your services.

Read the [Unified Service Tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging) documentation for recommendations on how to configure these environment variables. These variables are available for versions 1.24.0+ of the Go tracer.

You may also elect to provide `env`, `service`, and `version` through the tracer's API:

```go
package main

import (
    "github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
)

func main() {
    tracer.Start(
        tracer.WithEnv("prod"),
        tracer.WithService("test-go"),
        tracer.WithServiceVersion("abc123"),
    )

    // When the tracer is stopped, it will flush everything it has to the Datadog Agent before quitting.
    // Make sure this line stays in your main function.
    defer tracer.Stop()

    // If you expect your application to be shut down by SIGTERM (for example, a container in Kubernetes),
    // you might want to listen for that signal and explicitly stop the tracer to ensure no data is lost
    sigChan := make(chan os.Signal, 1)
    signal.Notify(sigChan, syscall.SIGTERM)
    go func() {
        <-sigChan
        tracer.Stop()
    }()
}
```

The Go tracer supports additional environment variables and functions for configuration. See all available options in the [configuration documentation](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace/tracer#StartOption) (or [configuration documentation v1](https://pkg.go.dev/gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer#StartOption)).

### Unified service tagging{% #unified-service-tagging %}

{% dl %}

{% dt %}
`DD_VERSION`
{% /dt %}

{% dd %}
Set the application's version, for example: `1.2.3`, `6c44da20`, `2020.02.13`
{% /dd %}

{% dt %}
`DD_SERVICE`
{% /dt %}

{% dd %}
The service name to be used for this application.
{% /dd %}

{% dt %}
`DD_ENV`
{% /dt %}

{% dd %}
Set the application's environment, for example: prod, pre-prod, staging.
{% /dd %}

{% /dl %}

### Traces{% #traces %}

{% dl %}

{% dt %}
`DD_TRACE_ENABLED`
{% /dt %}

{% dd %}
**Default**: `true`Enable web framework and library instrumentation. When false, the application code doesn't generate any traces.See also [DD_APM_TRACING_ENABLED](https://docs.datadoghq.com/tracing/trace_collection/library_config/#traces).
{% /dd %}

{% dt %}
`DD_TRACE_AGENT_PORT`
{% /dt %}

{% dd %}
**Default**: `8126`Overrides the default trace Agent port for Datadog trace submission. Ignored if `DD_TRACE_AGENT_URL` is set. If the [Agent configuration](https://docs.datadoghq.com/agent/configuration/network/#configure-ports) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then the library configuration `DD_DOGSTATSD_PORT` must match it.
{% /dd %}

{% dt %}
`DD_TRACE_AGENT_URL`
{% /dt %}

{% dd %}
**Default**: `null`Override the Agent URL used for trace submission. Supports `http://`, `https://`, and `unix://` protocols. Takes precedence over `DD_AGENT_HOST` and `DD_TRACE_AGENT_PORT` if set.
{% /dd %}

{% dt %}
`DD_TRACE_RATE_LIMIT`
{% /dt %}

{% dd %}
Maximum number of spans to sample per-second, per-Go process. Defaults to 100 when DD_TRACE_SAMPLE_RATE is set. Otherwise, delegates rate limiting to the Datadog Agent.
{% /dd %}

{% dt %}
`DD_TRACE_STARTUP_LOGS`
{% /dt %}

{% dd %}
**Default**: `true`Enable startup configuration and the diagnostic log.
{% /dd %}

{% dt %}
`DD_TRACE_DEBUG`
{% /dt %}

{% dd %}
**Default**: `false`Enable debug logging in the tracer.
{% /dd %}

{% dt %}
`DD_SERVICE_MAPPING`
{% /dt %}

{% dd %}
**Default**: `null`Dynamically rename services through configuration. Services can be separated by commas or spaces, for example: `mysql:mysql-service-name,postgres:postgres-service-name`, `mysql:mysql-service-name postgres:postgres-service-name`.
{% /dd %}

{% dt %}
`DD_TRACE_PARTIAL_FLUSH_ENABLED`
{% /dt %}

{% dd %}
**Default**: `false`Enables incrementally flushing large traces to the Datadog Agent, reducing the chance of rejection by the Agent. Use only when you have long-lived traces or traces with many spans. Valid values are `true` or `false`. Added in version 1.54.0. Only compatible with the Datadog Agent 7.26.0+.
{% /dd %}

{% dt %}
`DD_TRACE_PARTIAL_FLUSH_MIN_SPANS`
{% /dt %}

{% dd %}
**Default**: `1000`Number of spans within a trace that can be partially flushed to the Datadog Agent. `DD_TRACE_PARTIAL_FLUSH_ENABLED` must be `true` for partial flushing to occur. Added in version 1.54.0. Only compatible with the Datadog Agent 7.26.0+.
{% /dd %}

{% dt %}
`DD_TRACE_CLIENT_IP_ENABLED`
{% /dt %}

{% dd %}
**Default**: `false`Enable client IP collection from relevant IP headers in HTTP request spans. Added in version 1.47.0
{% /dd %}

{% dt %}
`DD_TRACE_HEADER_TAGS`
{% /dt %}

{% dd %}
**Default**: `null`List of comma-separated HTTP headers to be used as span tags. Optionally specify a "mapped" field to rename the request header as a tag. Configuration can be set globally with this environment variable, or at the integration level using the options specified in the [Go documentation](https://pkg.go.dev/gopkg.in/DataDog/dd-trace-go.v1/contrib). This feature is compatible with [HTTP1](https://www.rfc-editor.org/rfc/rfc7230#section-3.2) headers.**Examples:**
- Capture request header `my-header`: `"DD_TRACE_HEADER_TAGS=my-header"`
- Capture request headers `my-header-1` and `my-header-2`: `"DD_TRACE_HEADER_TAGS=my-header1,my-header-2"`
- Capture request header `my-header` and rename it to `my-tag`: `"DD_TRACE_HEADER_TAGS=my-header:my-tag"`

{% /dd %}

{% dt %}
`DD_TAGS`
{% /dt %}

{% dd %}
**Default**: noneA list of default tags to be added to every span, metric, and profile. Tags can be separated by commas or spaces, for example: `layer:api,team:intake,key:value` or `layer:api team:intake key:value`. Key-value pairs must be of string-convertible types.
{% /dd %}

{% /dl %}

### Agent{% #agent %}

{% dl %}

{% dt %}
`DD_AGENT_HOST`
{% /dt %}

{% dd %}
**Default**: `localhost`Override the default trace Agent host address for trace submission. Ignored if `DD_TRACE_AGENT_URL` is set.
{% /dd %}

{% dt %}
`DD_DOGSTATSD_PORT`
{% /dt %}

{% dd %}
**Default**: `8125`Overrides the default trace Agent port for DogStatsD metric submission. If the [Agent configuration](https://docs.datadoghq.com/agent/configuration/network/#configure-ports) sets `dogstatsd_port` or `DD_DOGSTATSD_PORT` to something other than the default `8125`, then the library configuration `DD_DOGSTATSD_PORT` must match it.
{% /dd %}

{% dt %}
`DD_INSTRUMENTATION_TELEMETRY_ENABLED`
{% /dt %}

{% dd %}
**Default**: `true`Datadog may collect [environmental and diagnostic information about your system](https://docs.datadoghq.com/tracing/configure_data_security#telemetry-collection) to improve the product. When false, this telemetry data will not be collected.
{% /dd %}

{% /dl %}

### Runtime metrics{% #runtime-metrics %}

{% dl %}

{% dt %}
`DD_RUNTIME_METRICS_ENABLED`
{% /dt %}

{% dd %}
**Default**: `false`Enable [runtime metric](https://docs.datadoghq.com/tracing/metrics/runtime_metrics/?tab=go) collection. Added in version 1.26.0.
{% /dd %}

{% /dl %}

### Trace context propagation{% #trace-context-propagation %}

{% dl %}

{% dt %}
`DD_TRACE_PROPAGATION_STYLE`
{% /dt %}

{% dd %}
**Default**: `datadog,tracecontext,baggage`Configures trace header injection and extraction style. See [Propagating Go Trace Context](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/) for more information.
{% /dd %}

{% /dl %}

## Configure APM environment name{% #configure-apm-environment-name %}

The [APM environment name](https://docs.datadoghq.com/tracing/advanced/setting_primary_tags_to_scope/#environment) may be configured [in the Agent](https://docs.datadoghq.com/getting_started/tracing/#environment-name) or using the [WithEnv](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace/tracer#StartOption) start option of the tracer.

## Further reading{% #further-reading %}

- [Source code](https://github.com/DataDog/dd-trace-go/tree/v1)
- [Package page](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace)
- [v2 Package page](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace)
- [Explore your services, resources and traces](https://docs.datadoghq.com/tracing/glossary/)
- [Propagating trace context](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/)
- [OpenTelemetry Environment Variable Configurations](https://docs.datadoghq.com/opentelemetry/interoperability/environment_variable_support)
