Configuring the NodeJS Tracing Library

After you set up the tracing library with your code and configure the Agent to collect APM data, optionally configure the tracing library as desired, including setting up Unified Service Tagging.

Tracer settings can be configured with the following environment variables:

Tagging

DD_ENV
Set an application’s environment (for example, prod, pre-prod, and stage). Defaults to the environment configured in the Datadog Agent.
DD_SERVICE
The service name used for this program. Defaults to the name field value in package.json.
DD_VERSION
The version number of the application. Defaults to the version field value in package.json.
DD_TAGS
Set global tags that are applied to all spans and runtime metrics. When passed as an environment variable, the format is key:value,key:value. When setting this programmatically, the format is tracer.init({ tags: { foo: 'bar' } }).

It is recommended that you use DD_ENV, DD_SERVICE, and DD_VERSION to set env, service, and version for your services. Review the Unified Service Tagging documentation for recommendations on configuring these environment variables.

Instrumentation

DD_TRACE_ENABLED
Default: true
Whether to enable the tracer.
DD_TRACE_DEBUG
Default: false
Enable debug logging in the tracer.
DD_TRACE_AGENT_URL
Default: http://localhost:8126
The URL of the Trace Agent that the tracer submits to. Takes priority over hostname and port, if set. Supports Unix Domain Sockets in combination with the apm_config.receiver_socket in your datadog.yaml file, or the DD_APM_RECEIVER_SOCKET environment variable.
DD_TRACE_AGENT_HOSTNAME
Default: localhost
The address of the Agent that the tracer submits to.
DD_TRACE_AGENT_PORT
Default: 8126
The port of the Trace Agent that the tracer submits to.
DD_DOGSTATSD_PORT
Default: 8125
The port of the DogStatsD Agent that metrics are submitted to.
DD_LOGS_INJECTION
Default: false
Enable automatic injection of trace IDs in logs for supported logging libraries.
DD_TRACE_SAMPLE_RATE
Percentage of spans to sample as a float between 0 and 1. Defaults to the rates returned by the Datadog Agent.
DD_TRACE_RATE_LIMIT
Percentage of spans to sample as a float between 0 and 1. Defaults to 100 when DD_TRACE_SAMPLE_RATE is set. Otherwise, delegates rate limiting to the Datadog Agent.
DD_TRACE_SAMPLING_RULES
A JSON array of objects. Each object must have a “sample_rate”, and the “name” and “service” fields are optional. The “sample_rate” value must be between 0.0 and 1.0 (inclusive). Rules are applied in configured order to determine the trace’s sample rate. If omitted, the tracer defers to the Agent to dynamically adjust sample rate across all traces.
DD_RUNTIME_METRICS_ENABLED
Default: false
Whether to enable capturing runtime metrics. Port 8125 (or configured with DD_DOGSTATSD_PORT) must be opened on the Agent for UDP.
DD_SERVICE_MAPPING
Example: mysql:my-mysql-service-name-db,pg:my-pg-service-name-db
Provide service names for each plugin. Accepts comma separated plugin:service-name pairs, with or without spaces.
DD_TRACE_DISABLED_PLUGINS
A comma-separated string of integration names automatically disabled when the tracer is initialized. Environment variable only, for example, DD_TRACE_DISABLED_PLUGINS=express,dns.
DD_TRACE_LOG_LEVEL
Default: debug
A string for the minimum log level for the tracer to use when debug logging is enabled, for example, error, debug.

For more options including the programmatic configuration API, see the API documentation.

Further Reading