Configuring the Node.js 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:
Unified Service Tagging
- DD_ENV
- Configuration: env
 Default: The environment configured in the Datadog Agent
 Set an application’s environment (for example,prod,pre-prod, andstage).
- DD_SERVICE
- Configuration: service
 Default: Thenamefield inpackage.json
 The service name used for this application.
- DD_VERSION
- Configuration: version
 Default: Theversionfield inpackage.json
 The version number of the application.
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.
Traces
- DD_TRACE_ENABLED
- Configuration: N/A
 Default:true
 Whether to enable dd-trace. Setting this tofalsedisables all features of the library.
 See also DD_APM_TRACING_ENABLED.
- DD_TRACE_DEBUG
- Configuration: N/A
 Default:false
 Enable debug logging in the tracer.
- DD_TRACING_ENABLED
- Configuration: N/A
 Default:true
 Whether to enable tracing.
- DD_TRACE_RATE_LIMIT
- Configuration: rateLimit
 Default:100whenDD_TRACE_SAMPLE_RATEis set. Otherwise, delegates rate limiting to the Datadog Agent.
The maximum number of traces per second per service instance.
 
- DD_TRACE_HEADER_TAGS
- Configuration: headerTags
 Default: N/A
 Accepts a comma-delimited list of case-insensitive HTTP headers optionally mapped to tag names. Automatically applies matching header values as tags on traces. When a tag name is not specified, it defaults to tags of the formhttp.request.headers.<header-name>for requests andhttp.response.headers.<header-name>for responses. Note: This option is only supported for HTTP/1.
 
 Example:User-ID:userId,Request-ID
 - If the Request/Response has a header User-ID, its value is applied as taguserIdto the spans produced by the service.
 
- If the Request/Response has a header Request-ID, its value is applied as taghttp.request.headers.Request-IDfor requests andhttp.response.headers.Request-IDfor responses.
 
- DD_SERVICE_MAPPING
- Configuration: serviceMapping
 Default: N/A
 Example:mysql:my-mysql-service-name-db,pg:my-pg-service-name-db
 Provide service names for each plugin. Accepts comma separatedplugin:service-namepairs, with or without spaces.
- Flush Interval
- Configuration: flushInterval
 Default:2000
 Interval in milliseconds at which the tracer submits traces to the Agent.
- DD_TRACE_PARTIAL_FLUSH_MIN_SPANS
- Configuration: flushMinSpans
 Default:1000
 Number of spans before partially exporting a trace. This prevents keeping all the spans in memory for very large traces.
- DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP
- Configuration: N/A
 Default: N/A
 A regex to redact sensitive data from incoming requests’ query string reported in thehttp.urltag (matches are replaced with<redacted>). Can be an empty string to disable redaction or.*to redact all query string. WARNING: This regex executes for every incoming request on an unsafe input (url) so make sure you use a safe regex.
- DD_TRACE_CLIENT_IP_HEADER
- Configuration: N/A
 Default: N/A
 Custom header name to source thehttp.client_iptag from.
- DNS Lookup Function
- Configuration: lookup
 Default:require('dns').lookup
 Custom function for DNS lookups when sending requests to the Agent. Some setups have hundreds of services running, each doing DNS lookups on every flush interval, causing scaling issues. Override this to provide your own caching or resolving mechanism.
- DD_TRACE_AGENT_PROTOCOL_VERSION
- Configuration: protocolVersion
 Default:0.4
 Protocol version to use for requests to the Agent. The version configured must be supported by the Agent version installed or all traces are dropped.
- DD_TRACE_REPORT_HOSTNAME
- Configuration: reportHostname
 Default:false
 Whether to report the system’s hostname for each trace. When disabled, the hostname of the Agent is used instead.
- DD_TRACE_STARTUP_LOGS
- Configuration: startupLogs
 Default:false
 Enable tracer startup configuration and diagnostic log.
- DD_SPAN_SAMPLING_RULES_FILE
- Configuration: N/A
 Default: N/A
 Points to a JSON file that contains the span sampling rules.DD_SPAN_SAMPLING_RULEStakes precedence over this variable. SeeDD_SPAN_SAMPLING_RULESfor the rule format.
- DD_TRACE_DISABLED_PLUGINS
- Configuration: N/A
 Default: N/A
 Example:DD_TRACE_DISABLED_PLUGINS=express,dns
 A comma-separated string of integration names automatically disabled when the tracer is initialized.
- Experimental Features
- Configuration: experimental
 Default:{}
 Experimental features can be enabled by adding predefined keys with a value oftrue. Contact Support to learn more about the available experimental features.
- Automatically Instrument External Libraries
- Configuration: plugins
 Default:true
 Whether to enable automatic instrumentation of external libraries using the built-in plugins.
- DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING
- Configuration: cloudPayloadTagging.request
 Default: N/A (disabled)
 Example:DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING=$.Metadata.UserId
 A comma-separated string of JSONPath entries to redact from AWS SDK requests. Setting this enables AWS payload tagging for requests.
- DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING
- Configuration: cloudPayloadTagging.response
 Default: N/A (disabled)
 Example:DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING=$.Metadata.UserId
 A comma-separated string of JSONPath entries to redact from AWS SDK responses. Setting this enables AWS payload tagging for responses.
- DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH
- Configuration: cloudPayloadTagging.maxDepth
 Default: 10
 Example:DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH=10
 An integer representing the maximum depth of an AWS SDK request/reponse payload to use for AWS payload tagging.
Agent
- DD_TAGS
- Configuration: tags
 Default:{}
 Set global tags that are applied to all spans and runtime metrics. When passed as an environment variable, the format iskey:value,key:value. When setting this programmatically, the format istracer.init({ tags: { foo: 'bar' } }).
- DD_TRACE_AGENT_URL
- Configuration: url
 Default:http://localhost:8126
 The URL of the Trace Agent that the tracer submits to. Takes priority over hostname and port, if set. If the Agent configuration setsreceiver_portorDD_APM_RECEIVER_PORTto something other than the default8126, thenDD_TRACE_AGENT_PORTorDD_TRACE_AGENT_URLmust match it. Supports Unix Domain Sockets in combination with theapm_config.receiver_socketin yourdatadog.yamlfile, or theDD_APM_RECEIVER_SOCKETenvironment variable.
- DD_TRACE_AGENT_HOSTNAME
- Configuration: hostname
 Default:localhost
 The address of the Agent that the tracer submits to.
- DD_TRACE_AGENT_PORT
- Configuration: port
 Default:8126
 The port of the Trace Agent that the tracer submits to. If the Agent configuration setsreceiver_portorDD_APM_RECEIVER_PORTto something other than the default8126, thenDD_TRACE_AGENT_PORTorDD_TRACE_AGENT_URLmust match it.
- DD_DOGSTATSD_PORT
- Configuration: dogstatsd.port
 Default:8125
 The port of the DogStatsD Agent that metrics are submitted to. If the Agent configuration setsdogstatsd_portorDD_DOGSTATSD_PORTto something other than the default8125, then this tracing libraryDD_DOGSTATSD_PORTmust match it.
- DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS
- Configuration: remoteConfig.pollInterval
 Default: 5
 Remote configuration polling interval in seconds.
AAP
- DD_APPSEC_ENABLED
- Configuration: appsec.enabled
 Default:false
 Enable App and API Protection features.
- DD_APPSEC_RULES
- Configuration: appsec.rules
 Default: N/A
 A path to a custom AppSec rules file.
- DD_APPSEC_WAF_TIMEOUT
- Configuration: appsec.wafTimeout
 Default:5000
 Limits the WAF synchronous execution time (in microseconds).
- DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP
- Configuration: appsec.obfuscatorKeyRegex
 Default: N/A
 A regex string to redact sensitive data by its key in attack reports.
- DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP
- Configuration: appsec.obfuscatorValueRegex
 Default: N/A
 A regex string to redact sensitive data by its value in attack reports.
Database monitoring
- DD_DBM_PROPAGATION_MODE
- Configuration: dbmPropagationMode
 Default:'disabled'
 To enable DBM to APM link using tag injection, can be set to'service'or'full'. The'service'option enables the connection between DBM and APM services. The'full'option enables connection between database spans with database query events. Available for Postgres.
Logs
- DD_LOGS_INJECTION
- Configuration: logInjection
 Default:true
 Enable automatic injection of trace IDs in logs for supported logging libraries.
- DD_TRACE_LOG_LEVEL
- Configuration: logLevel
 Default:debug
 A string for the minimum log level for the tracer to use when debug logging is enabled, for example,error,debug.
OpenTelemetry
- DD_TRACE_OTEL_ENABLED
- Configuration: N/A
 Default:undefined
 Whentrue, OpenTelemetry-based tracing for custom instrumentation is enabled.
Profiling
- DD_PROFILING_ENABLED
- Configuration: profiling
 Default:false
 Whether to enable profiling.
Runtime metrics
- DD_RUNTIME_METRICS_ENABLED
- Configuration: runtimeMetrics
 Default:false
 Whether to enable capturing runtime metrics. Port8125(or configured withDD_DOGSTATSD_PORT) must be opened on the Agent for UDP.
Trace context propagation
For information about valid values and using the following configuration options, see Propagating Node.js Trace Context.
- DD_TRACE_PROPAGATION_STYLE_INJECT
- Configuration: tracePropagationStyle.inject
 Default:Datadog,tracecontext,baggage
 A comma-separated list of header formats to include to propagate distributed traces between services.
- DD_TRACE_PROPAGATION_STYLE_EXTRACT
- Configuration: tracePropagationStyle.extract
 Default:Datadog,tracecontext,baggage
 A comma-separated list of header formats from which to attempt to extract distributed tracing propagation data. The first format found with complete and valid headers is used to define the trace to continue.
- DD_TRACE_PROPAGATION_STYLE
- Configuration: tracePropagationStyle
 Default:Datadog,tracecontext,baggage
 A comma-separated list of header formats from which to attempt to inject and extract distributed tracing propagation data. The first format found with complete and valid headers is used to define the trace to continue. The more specificDD_TRACE_PROPAGATION_STYLE_INJECTandDD_TRACE_PROPAGATION_STYLE_EXTRACTconfigurations take priority when present.
For more examples of how to work with the library see API documentation.
Further Reading
Additional helpful documentation, links, and articles: