Configuring the Java 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.

All configuration options below have system property and environment variable equivalents. If the same key type is set for both, the system property configuration takes priority. System properties can be set as JVM flags.

Note: When using the Java tracer’s system properties, make sure that they are listed before -jar so they get read in as JVM options.

dd.service
Environment Variable: DD_SERVICE
Default: unnamed-java-app
The name of a set of processes that do the same job. Used for grouping stats for your application. Available for versions 0.50.0+.
dd.tags
Environment Variable: DD_TAGS
Default: null
Example: layer:api,team:intake
A list of default tags to be added to every span, profile, and JMX metric. If DD_ENV or DD_VERSION is used, it overrides any env or version tag defined in DD_TAGS. Available for versions 0.50.0+.
dd.env
Environment Variable: DD_ENV
Default: none
Your application environment (for example, production, staging). Available for versions 0.48+.
dd.version
Environment Variable: DD_VERSION
Default: null
Your application version (for example, 2.5, 202003181415, 1.3-alpha). Available for versions 0.48+.
dd.logs.injection
Environment Variable: DD_LOGS_INJECTION
Default: true
Enabled automatic MDC key injection for Datadog trace and span IDs. See Advanced Usage for details.
dd.trace.config
Environment Variable: DD_TRACE_CONFIG
Default: null
Optional path to a file where configuration properties are provided one per each line. For instance, the file path can be provided as via -Ddd.trace.config=<FILE_PATH>.properties, with setting the service name in the file with dd.service=<SERVICE_NAME>
dd.service.mapping
Environment Variable: DD_SERVICE_MAPPING
Default: null
Example: mysql:my-mysql-service-name-db, postgres:my-postgres-service-name-db
Dynamically rename services via configuration. Useful for making databases have distinct names across different services.
dd.writer.type
Environment Variable: DD_WRITER_TYPE
Default: DDAgentWriter
Default value sends traces to the Agent. Configuring with LoggingWriter instead writes traces out to the console.
dd.agent.host
Environment Variable: DD_AGENT_HOST
Default: localhost
Hostname for where to send traces to. If using a containerized environment, configure this to be the host IP. See Tracing Docker Applications for more details.
dd.trace.agent.port
Environment Variable: DD_TRACE_AGENT_PORT
Default: 8126
Port number the Agent is listening on for configured host.
dd.trace.agent.unix.domain.socket
Environment Variable: DD_TRACE_AGENT_UNIX_DOMAIN_SOCKET
Default: null
This can be used to direct trace traffic to a proxy, to later be sent to a remote Datadog Agent.
dd.trace.agent.url
Environment Variable: DD_TRACE_AGENT_URL
Default: null
The URL to send traces to. This can start with http:// to connect using HTTP or with unix:// to use a Unix Domain Socket. When set this takes precedence over DD_AGENT_HOST and DD_TRACE_AGENT_PORT. Available for versions 0.65+.
dd.trace.agent.timeout
Environment Variable: DD_TRACE_AGENT_TIMEOUT
Default: 10
Timeout in seconds for network interactions with the Datadog Agent.
dd.trace.header.tags
Environment Variable: DD_TRACE_HEADER_TAGS
Default: null
Example: CASE-insensitive-Header:my-tag-name,User-ID:userId,My-Header-And-Tag-Name
Accepts a map of case-insensitive header keys to tag names and automatically applies matching header values as tags on traces. Also accepts entries without a specified tag name that are automatically mapped to tags of the form http.request.headers.<header-name> and http.response.headers.<header-name> respectively.

Prior to version 0.96.0 this setting only applied to request header tags. To change back to the old behavior, add the setting -Ddd.trace.header.tags.legacy.parsing.enabled=true or the environment variable DD_TRACE_HEADER_TAGS_LEGACY_PARSING_ENABLED=true.
dd.trace.request_header.tags
Environment Variable: DD_TRACE_REQUEST_HEADER_TAGS
Default: null
Example: CASE-insensitive-Header:my-tag-name,User-ID:userId,My-Header-And-Tag-Name
Accepts a map of case-insensitive header keys to tag names and automatically applies matching request header values as tags on traces. Also accepts entries without a specified tag name that are automatically mapped to tags of the form http.request.headers.<header-name>.
Available since version 0.96.0.
dd.trace.response_header.tags
Environment Variable: DD_TRACE_RESPONSE_HEADER_TAGS
Default: null
Example: CASE-insensitive-Header:my-tag-name,User-ID:userId,My-Header-And-Tag-Name
Accepts a map of case-insensitive header keys to tag names and automatically applies matching response header values as tags on traces. Also accepts entries without a specified tag name that are automatically mapped to tags of the form http.response.headers.<header-name>.
Available since version 0.96.0.
dd.trace.annotations
Environment Variable: DD_TRACE_ANNOTATIONS
Default: (listed here)
Example: com.some.Trace;io.other.Trace
A list of method annotations to treat as @Trace.
dd.trace.methods
Environment Variable: DD_TRACE_METHODS
Default: null
Example: package.ClassName[method1,method2,...];AnonymousClass$1[call];package.ClassName[*]
List of class/interface and methods to trace. Similar to adding @Trace, but without changing code. Note: The wildcard method support ([*]) does not accommodate constructors, getters, setters, synthetic, toString, equals, hashcode, or finalizer method calls
dd.trace.classes.exclude
Environment Variable: DD_TRACE_CLASSES_EXCLUDE
Default: null
Example: package.ClassName,package.ClassName$Nested,package.Foo*,package.other.*
A list of fully qualified classes (that may end with a wildcard to denote a prefix) which will be ignored (not modified) by the tracer. Must use the jvm internal representation for names (eg package.ClassName$Nested and not package.ClassName.Nested)
dd.trace.partial.flush.min.spans
Environment Variable: DD_TRACE_PARTIAL_FLUSH_MIN_SPANS
Default: 1000
Set a number of partial spans to flush on. Useful to reduce memory overhead when dealing with heavy traffic or long running traces.
dd.trace.split-by-tags
Environment Variable: DD_TRACE_SPLIT_BY_TAGS
Default: null
Example: aws.service
Used to rename the service name associated with spans to be identified with the corresponding span tag
dd.trace.db.client.split-by-instance
Environment Variable: DD_TRACE_DB_CLIENT_SPLIT_BY_INSTANCE
Default: false
When set to true db spans get assigned the instance name as the service name
dd.trace.health.metrics.enabled
Environment Variable: DD_TRACE_HEALTH_METRICS_ENABLED
Default: true
When set to true sends tracer health metrics
dd.trace.health.metrics.statsd.host
Environment Variable: DD_TRACE_HEALTH_METRICS_STATSD_HOST
Default: Same as dd.jmxfetch.statsd.host
Statsd host to send health metrics to
dd.trace.health.metrics.statsd.port
Environment Variable: DD_TRACE_HEALTH_METRICS_STATSD_PORT
Default: Same as dd.jmxfetch.statsd.port
Statsd port to send health metrics to
dd.http.client.tag.query-string
Environment Variable: DD_HTTP_CLIENT_TAG_QUERY_STRING
Default: false
When set to true query string parameters and fragment get added to web client spans
dd.http.client.error.statuses
Environment Variable: DD_HTTP_CLIENT_ERROR_STATUSES
Default: 400-499
A range of errors can be accepted. By default 4xx errors are reported as errors for http clients. This configuration overrides that. Ex. dd.http.client.error.statuses=400-403,405,410-499
dd.http.server.error.statuses
Environment Variable: DD_HTTP_SERVER_ERROR_STATUSES
Default: 500-599
A range of errors can be accepted. By default 5xx status codes are reported as errors for http servers. This configuration overrides that. Ex. dd.http.server.error.statuses=500,502-599
dd.http.server.tag.query-string
Environment Variable: DD_HTTP_SERVER_TAG_QUERY_STRING
Default: false
When set to true query string parameters and fragment get added to web server spans
dd.trace.enabled
Environment Variable: DD_TRACE_ENABLED
Default: true
When false tracing agent is disabled.
dd.jmxfetch.enabled
Environment Variable: DD_JMXFETCH_ENABLED
Default: true
Enable collection of JMX metrics by Java Tracing Agent.
dd.jmxfetch.config.dir
Environment Variable: DD_JMXFETCH_CONFIG_DIR
Default: null
Example: /path/to/directory/etc/conf.d
Additional configuration directory for JMX metrics collection. The Java Agent looks for jvm_direct:true in the instance section in the yaml file to change configuration.
dd.jmxfetch.config
Environment Variable: DD_JMXFETCH_CONFIG
Default: null
Example: path/to/file/conf.yaml,other/path/to/file/conf.yaml
Additional metrics configuration file for JMX metrics collection. The Java Agent looks for jvm_direct:true in the instance section in the yaml file to change configuration.
dd.jmxfetch.check-period
Environment Variable: DD_JMXFETCH_CHECK_PERIOD
Default: 1500
How often to send JMX metrics (in ms).
dd.jmxfetch.refresh-beans-period
Environment Variable: DD_JMXFETCH_REFRESH_BEANS_PERIOD
Default: 600
How often to refresh list of available JMX beans (in seconds).
dd.jmxfetch.statsd.host
Environment Variable: DD_JMXFETCH_STATSD_HOST
Default: Same as agent.host
Statsd host to send JMX metrics to. If you are using Unix Domain Sockets, use an argument like ‘unix://PATH_TO_UDS_SOCKET’. Example: unix:///var/datadog-agent/dsd.socket
dd.jmxfetch.statsd.port
Environment Variable: DD_JMXFETCH_STATSD_PORT
Default: 8125
StatsD port to send JMX metrics to. If you are using Unix Domain Sockets, input 0.
dd.integration.opentracing.enabled
Environment Variable: DD_INTEGRATION_OPENTRACING_ENABLED
Default: true
By default the tracing client detects if a GlobalTracer is being loaded and dynamically registers a tracer into it. By turning this to false, this removes any tracer dependency on OpenTracing.
dd.hystrix.tags.enabled
Environment Variable: DD_HYSTRIX_TAGS_ENABLED
Default: false
By default the Hystrix group, command, and circuit state tags are not enabled. This property enables them.
dd.trace.servlet.async-timeout.error
Environment Variable: DD_TRACE_SERVLET_ASYNC_TIMEOUT_ERROR
Default: true
By default, long running asynchronous requests will be marked as an error, setting this value to false allows to mark all timeouts as successful requests.
dd.trace.startup.logs
Environment Variable: DD_TRACE_STARTUP_LOGS
Default: true
When false, informational startup logging is disabled. Available for versions 0.64+.
dd.trace.servlet.principal.enabled
Environment Variable: DD_TRACE_SERVLET_PRINCIPAL_ENABLED
Default: false
When true, user principal is collected. Available for versions 0.61+.

Note:

Integrations

See how to disable integrations in the integrations compatibility section.

Examples

dd.service.mapping

Example with system property:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.service=web-app -Ddd.service.mapping=postgresql:web-app-pg -jar path/to/application.jar
service mapping

dd.tags

Setting a global env for spans and JMX metrics:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.service=web-app -Ddd.env=dev -jar path/to/application.jar
trace global tags

dd.trace.span.tags

Example with adding project:test to every span:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.service=web-app -Ddd.env=dev -Ddd.trace.span.tags=project:test -jar path/to/application.jar
trace span tags

dd.trace.jmx.tags

Setting custom.type:2 on a JMX metric:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.service=web-app -Ddd.env=dev -Ddd.trace.span.tags=project:test -Ddd.trace.jmx.tags=custom.type:2 -jar path/to/application.jar
trace JMX tags

dd.trace.methods

Example with system property:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.service=web-app -Ddd.env=dev -Ddd.trace.methods="hello.GreetingController[doSomeStuff,doSomeOtherStuff];hello.Randomizer[randomize]" -jar path/to/application.jar
trace methods

dd.trace.db.client.split-by-instance

Example with system property:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.env=dev -Ddd.service=web-app -Ddd.trace.db.client.split-by-instance=TRUE -jar path/to/application.jar

DB Instance 1, webappdb, now gets its own service name that is the same as the db.instance span metadata:

instance 1

DB Instance 2, secondwebappdb, now gets its own service name that is the same as the db.instance span metadata:

instance 2

Similarly on the service map, you would now see one web app making calls to two different Postgres databases.

dd.http.server.tag.query-string

Example with system property:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.service=web-app -Ddd.env=dev -Ddd.http.server.tag.query-string=TRUE -jar path/to/application.jar
query string

dd.trace.enabled

Example with system property and debug app mode:

java -javaagent:/path/to/dd-java-agent.jar -Ddd.trace.enabled=false -Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug -jar path/to/application.jar

Debug app logs show that Tracing is disabled, not installing instrumentations.

dd.jmxfetch.config.dir and dd.jmxfetch.config

Example configuration:

  • Either the combination of: DD_JMXFETCH_CONFIG_DIR=<DIRECTORY_PATH> + DD_JMXFETCH_CONFIG=conf.yaml
  • Or directly: DD_JMXFETCH_CONFIG=<DIRECTORY_PATH>/conf.yaml

With the following content for conf.yaml:

init_config:
instances:
    - jvm_direct: true
      port: '<PORT>'
      conf:
          - include:
                bean:
                    - java.lang:type=MemoryPool,name=Metaspace
                attribute:
                    Usage.used:
                        metric_type: gauge
                        alias: sb.usage.used

Would produce the following result:

JMX fetch example

See the Java integration documentation to learn more about Java metrics collection with JMX fetch.

B3 headers extraction and injection

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

Distributed headers injection and extraction is controlled by configuring injection/extraction styles. Currently two styles are supported:

  • Datadog: Datadog
  • B3: B3

Injection styles can be configured using:

  • System Property: -Ddd.propagation.style.inject=Datadog,B3
  • Environment Variable: DD_PROPAGATION_STYLE_INJECT=Datadog,B3

The value of the property or environment variable is a comma (or space) separated list of header styles that are enabled for injection. By default only Datadog injection style is enabled.

Extraction styles can be configured using:

  • System Property: -Ddd.propagation.style.extract=Datadog,B3
  • Environment Variable: DD_PROPAGATION_STYLE_EXTRACT=Datadog,B3

The value of the property or environment variable is a comma (or space) separated list of header styles that are enabled for extraction. By default only Datadog extraction style is enabled.

If multiple extraction styles are enabled extraction attempt is done on the order those styles are configured and first successful extracted value is used.

Further Reading