Configuring the .NET Core 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.

.NET Tracer configuration setting precedence

You can set configuration settings in the .NET Tracer with any of the following methods:

To configure the tracer using environment variables, set the variables before launching the instrumented application. To learn how to set environment variables in different environments, see Configuring process environment variables.

To configure the tracer in application code, create a TracerSettings instance from the default configuration sources. Set properties on this TracerSettings instance before calling Tracer.Configure(). For example:

Note: Settings must be set on TracerSettings before creating the Tracer. Changes made to TracerSettings properties after the Tracer is created are ignored.
using Datadog.Trace;
using Datadog.Trace.Configuration;

// read default configuration sources (env vars, web.config, datadog.json)
var settings = TracerSettings.FromDefaultSources();

// change some settings
settings.Environment = "prod";
settings.ServiceName = "MyService";
settings.ServiceVersion = "abc123";
settings.Exporter.AgentUri = new Uri("http://localhost:8126/");

// configure the global Tracer settings

To configure the tracer using a JSON file, create datadog.json in the instrumented application’s directory. The root JSON object must be an object with a key-value pair for each setting. For example:

  "DD_TRACE_AGENT_URL": "http://localhost:8126",
  "DD_ENV": "prod",
  "DD_SERVICE": "MyService",
  "DD_VERSION": "abc123",

Configuration settings

Note: On Linux, the names of environment variables are case-sensitive.

Using the methods described above, customize your tracing configuration with the following variables. Use the environment variable name (for example, DD_TRACE_AGENT_URL) when setting environment variables or configuration files. Use the TracerSettings property (for example, Exporter.AgentUri) when changing settings in code.

Unified Service Tagging

To use Unified Service Tagging, configure the following settings for your services:

TracerSettings property: Environment
If specified, adds the env tag with the specified value to all generated spans. Added in version 1.17.0.
TracerSettings property: ServiceName
If specified, sets the service name. Otherwise, the .NET Tracer tries to determine service name automatically from the application name (IIS application name, process entry assembly, or process name). Added in version 1.17.0.
TracerSettings property: ServiceVersion
If specified, sets the version of the service. Added in version 1.17.0.

Optional configuration

The following configuration variables are available for both automatic and custom instrumentation:

TracerSettings property: Exporter.AgentUri
Sets the URL endpoint where traces are sent. Overrides DD_AGENT_HOST and DD_TRACE_AGENT_PORT if set.
It can contain a Unix path to a socket by prefixing the path with unix://.
Default: http://<DD_AGENT_HOST>:<DD_TRACE_AGENT_PORT> if they are set, unix:///var/run/datadog/apm.socket if the file exists, or http://localhost:8126.
Sets the host where the Agent is listening for connections. Can be a hostname or an IP address. Use DD_TRACE_AGENT_URL, which has precedence over this parameter.
Default: localhost
Sets the TCP port where the Agent is listening for connections. Use DD_TRACE_AGENT_URL, which has precedence over this parameter.
Default: 8126
TracerSettings property: GlobalSamplingRate
Default: Defaults to the rates returned by the Datadog Agent
Enables ingestion rate control. This parameter is a float representing the percentage of spans to sample. Valid values are from 0.0 to 1.0. For more information, see Ingestion Mechanisms.
TracerSettings property: CustomSamplingRules
Default: null
A JSON array of objects. Each object must have a "sample_rate". 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. For more information, see Ingestion Mechanisms.
  • Set the sample rate to 20%: '[{"sample_rate": 0.2}]'
  • Set the sample rate to 10% for services starting with ‘a’ and span name ‘b’ and set the sample rate to 20% for all other services: '[{"service": "a.*", "name": "b", "sample_rate": 0.1}, {"sample_rate": 0.2}]'
TracerSettings property: MaxTracesSubmittedPerSecond
The number of traces allowed to be submitted per second (deprecates DD_MAX_TRACES_PER_SECOND).
Default: 100 when DD_TRACE_SAMPLE_RATE is set. Otherwise, delegates rate limiting to the Datadog Agent.
TracerSettings property: GlobalTags
If specified, adds all of the specified tags to all generated spans.
Enables or disables debug logging. Valid values are true or false.
Default: false
TracerSettings property:HeaderTags
Accepts a map of case-insensitive header keys to tag names and automatically applies matching header values as tags on root spans. Also accepts entries without a specified tag name.
Example: CASE-insensitive-Header:my-tag-name,User-ID:userId,My-Header-And-Tag-Name
Added in version 1.18.3. Response header support and entries without tag names added in version 1.26.0.
TracerSettings property: GlobalTags
If specified, adds all of the specified tags to all generated spans.
Example: layer:api, team:intake
Added in version 1.17.0.
Note that the delimiter is a comma and a space: , .
Sets the directory for .NET Tracer logs.
Default: %ProgramData%\Datadog .NET Tracer\logs\ on Windows, /var/log/datadog/dotnet on Linux
Sets rate limiting for log messages. If set, unique log lines are written once per x seconds. For example, to log a given message once per 60 seconds, set to 60. Setting to 0 disables log rate limiting. Added in version 1.24.0. Disabled by default.
Rename services using configuration. Accepts a map of service name keys to rename, and the name to use instead, in the format [from-key]:[to-name].
Example: mysql:main-mysql-db, mongodb:offsite-mongodb-service
The from-key value is specific to the integration type, and should exclude the application name prefix. For example, to rename my-application-sql-server to main-db, use sql-server:main-db. Added in version 1.23.0

Automatic instrumentation optional configuration

The following configuration variables are available only when using automatic instrumentation:

TracerSettings property: TraceEnabled
Enables or disables all automatic instrumentation. Setting the environment variable to false completely disables the CLR profiler. For other configuration methods, the CLR profiler is still loaded, but traces will not be generated. Valid values are: true or false.
Default: true
Sets status code ranges that will cause HTTP client spans to be marked as errors.
Default: 400-499
Sets status code ranges that will cause HTTP server spans to be marked as errors.
Default: 500-599
TracerSettings property: LogsInjectionEnabled
Enables or disables automatic injection of correlation identifiers into application logs.
Your logger needs to have a source that sets the trace_id mapping correctly. The default source for .NET Applications, csharp, does this automatically. For more information, see correlated logs in the Trace ID panel.
Enables .NET runtime metrics. Valid values are true or false.
Default: false
Added in version 1.23.0.
Expands all route parameters in the application for ASP.NET/ASP.NET Core (except ID parameters)
This can be useful if you are using parameter names to differentiate between form values, or a slug, such as in GraphQL. Default: false Added in version 2.5.1.
List of methods to trace. Accepts a semicolon (;) separated list where each entry has the format TypeName[MethodNames], where MethodNames is either a comma (,) separated list of method names or the * wildcard. For generic types, replace the angled brackets and the type parameters’ names with a backtick (`) followed by the number of generic type parameters. For example, Dictionary<TKey, TValue> must be written as Dictionary`2. For generic methods, you only need to specify the method name.
Example: Namespace1.Class1[Method1,GenericMethod];Namespace1.GenericTypeWithOneTypeVariable`1[ExecuteAsync];Namespace2.Class2[*]
Note: The wildcard method support ([*]) selects all methods in a type except constructors, property getters and setters, Equals, Finalize, GetHashCode, and ToString.
Added in version 2.6.0. Wildcard support [*] added in version 2.7.0.
Alters the behavior of the Kafka consumer span
Default: true
When set to true, the consumer span is created when a message is consumed and closed before consuming the next message. The span duration is representative of the computation between one message consumption and the next. Use this setting when message consumption is performed in a loop.
When set to false, the consumer span is created when a message is consumed and immediately closed. Use this setting when a message is not processed completely before consuming the next one, or when multiple messages are consumed at once.

Automatic instrumentation integration configuration

The following table lists configuration variables that are available only when using automatic instrumentation and can be set for each integration.

TracerSettings property: DisabledIntegrationNames
Sets a list of integrations to disable. All other integrations remain enabled. If not set, all integrations are enabled. Supports multiple values separated with semicolons. Valid values are the integration names listed in the Integrations section.
TracerSettings property: Integrations[<INTEGRATION_NAME>].Enabled
Enables or disables a specific integration. Valid values are: true or false. Integration names are listed in the Integrations section.
Default: true

Experimental features

The following configuration variables are for features that are available for use but may change in future releases.

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.26.0, only compatible with the Datadog Agent 7.26.0+.
Default: false

Deprecated settings

Sets the path for the automatic instrumentation log file and determines the directory of all other .NET Tracer log files. Ignored if DD_TRACE_LOG_DIRECTORY is set.
Enables improved resource names for web spans when set to true. Uses route template information where available, adds an additional span for ASP.NET Core integrations, and enables additional tags. Added in version 1.26.0. Enabled by default in 2.0.0
Default: true

Headers extraction and injection

The Datadog APM Tracer supports B3 and W3C (TraceParent) headers extraction and injection for distributed tracing.

You can configure injection and extraction styles for distributed headers.

The .NET Tracer supports the following styles:

  • Datadog: Datadog
  • B3: B3
  • W3C: W3C
  • B3 Single Header: B3SingleHeader or B3 single header

You can use the following environment variables to configure injection and extraction styles:


The environment variable values are comma-separated lists of header styles enabled for injection or extraction. By default, only the Datadog injection style is enabled.

If multiple extraction styles are enabled, the extraction attempt is completed in order of configured styles, and uses the first successful extracted value.

Further reading