Datadog.Trace 2.15.0

.NET 6.0 .NET Core 3.1 .NET Standard 2.0 .NET Framework 4.6.1
NuGet\Install-Package Datadog.Trace -Version 2.15.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package Datadog.Trace --version 2.15.0
<PackageReference Include="Datadog.Trace" Version="2.15.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Datadog.Trace --version 2.15.0
#r "nuget: Datadog.Trace, 2.15.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Datadog.Trace as a Cake Addin
#addin nuget:?package=Datadog.Trace&version=2.15.0

// Install Datadog.Trace as a Cake Tool
#tool nuget:?package=Datadog.Trace&version=2.15.0

Datadog.Trace NuGet package

This package contains the Datadog .NET APM tracer for configuring custom instrumentation.

If you are only using automatic instrumentation, you do not need this package. Please read our documentation for details on how to install the tracer for automatic instrumentation.

If you are using automatic instrumentation and would like to interact with APM only through C# attributes, see the Datadog.Trace.Annotations NuGet package.

Getting Started

  1. Configure the Datadog agent for APM as described in our documentation.
  2. For automatic instrumentation, install and enable the tracer as described in our documentation.
  3. Configure custom instrumentation, as shown below
  4. View your live data on Datadog.

Configuring Datadog in code

There are multiple ways to configure your application: using environment variables, a web.config file, or a datadog.json file, as described in our documentation. This NuGet package also allows you to configure settings in code.

To override configuration settings, create an instance of TracerSettings, and pass it to the static Tracer.Configure() method:

using Datadog.Trace;

// Create a settings object using the existing
// environment variables and config sources
var settings = TracerSettings.FromDefaultSources();

// Override a value
settings.GlobalTags.Add("SomeKey", "SomeValue");

// Replace the tracer configuration

Calling Tracer.Configure() will replace the settings for all subsequent traces, both for custom instrumentation and for automatic instrumentation.

⚠️ Replacing the configuration should be done once, as early as possible in your application.

Create custom traces

To create and activate a custom span, use Tracer.Instance.StartActive(). If a trace is already active (when created by automatic instrumentation, for example), the span will be part of the current trace. If there is no current trace, a new one will be started.

⚠️ Ensure you dispose of the scope returned from StartActive. Disposing the scope will close the span, and ensure the trace is flushed to Datadog once all its spans are closed.

using Datadog.Trace;

// Start a new span
using (var scope = Tracer.Instance.StartActive("custom-operation"))
    // Do something

Release Notes

You can view the notes for the latest release on GitHub.

Upgrading from 1.x to 2.0

.NET Tracer 2.0 introduces several breaking changes to the API which allow various performance improvements, add new features, and deprecate problematic ways of using the package. Most of these changes do not require any changes to your code, but some patterns are no longer supported or recommended.

This section describes some of the most important breaking changes. For full details see the release notes on GitHub.

Supported .NET versions

.NET Tracer 2.0 adds support for .NET 6.0 and raises the minimum supported version of .NET Framework from .NET Framework 4.5 to .NET Framework 4.6.1. If you are currently targeting version < 4.6.1, we suggest you upgrade in line with Microsoft's guidance.

For full details of supported versions, see our documentation on .NET Framework compatibility requirements and .NET/.NET Core compatibility requirements.

Singleton Tracer instances

In .NET Tracer 1.x, you could create new Tracer instances with different settings for each instance, using the Tracer constructor. In .NET Tracer 2.0 this constructor is marked [Obsolete] and it is no longer possible to create Tracer instances with different settings. This was done to avoid multiple problematic patterns that were hard for users to detect.

To update your code:

using Datadog.Trace;

// Create your settings as before
var settings = new TracerSettings();

// var tracer = new Tracer(settings) // <- Delete this line
Tracer.Configure(settings);          // <- Add this line

Immutable Tracer.Settings

In .NET Tracer 1.x the TracerSettings object passed into a Tracer instance could be modified later. Depending on the changes, the tracer may or may not respect the changes. In .NET Tracer 2.0, an ImmutableTracerSettings object is created when the Tracer instance is configured. The property Tracer.Settings now returns ImmutableTracerSettings, not TracerSettings. Subsequent changes to the original TracerSettings instance will not be observed by Tracer.

To update your code:

using Datadog.Trace;

var settings = TracerSettings.FromDefaultSources();
settings.TraceEnabled = false;   // TracerSettings are mutable


// All properties on Tracer.Settings are now read-only
// Tracer.Instance.Settings.TraceEnabled = false; // <- DOES NOT COMPILE

Exporter settings

Exporter-related settings were grouped into the TracerSettings.Exporter property.

To update your code:

using Datadog.Trace;

var settings = TracerSettings.FromDefaultSources();

// settings.AgentUri = "http://localhost:8126";        // <- Delete this line
settings.Exporter.AgentUri = "http://localhost:8126";  // <- Add this line


Configure ADO.NET integrations individually

In .NET Tracer 1.x, you could configure automatic instrumentation of all ADO.NET integrations using the AdoNet integration ID. In .NET Tracer 2.0, you can now configure specific integrations using the following integration IDs:

  • MySql
  • Npgsql (PostgreSQL)
  • Oracle
  • SqlClient (SQL Server)
  • Sqlite

See our documentation for a complete list of supported integration IDs. Note that you can still disable all ADO.NET integrations using the AdoNet integration ID.

This change also removes the now-obsolete TracerSettings.AdoNetExcludedTypes setting and the corresponding environment variable DD_TRACE_ADONET_EXCLUDED_TYPES. Replace usages of these with TracerSettings.Integrations["<INTEGRATION_NAME>"].Enabled and DD_TRACE_<INTEGRATION_NAME>_ENABLED, respectively:

using Datadog.Trace;

var settings = TracerSettings.FromDefaultSources();

// settings.AdoNetExcludedTypes.Add("MySql");    // <- Delete this line
settings.Integrations["MySql"].Enabled = false;  // <- Add this line

ElasticsearchNet5 integration ID removed

In .NET Tracer 1.x, the integration ID for version 5.x of Elasticsearch.Net was ElasticsearchNet5, and the integration ID for versions 6 and above was ElasticsearchNet. In .NET Tracer 2.0, ElasticsearchNet5 was removed. Use ElasticsearchNet for all versions of Elasticsearch.Net.

To update your code:

using Datadog.Trace;

var settings = TracerSettings.FromDefaultSources();

settings.Integrations["ElasticsearchNet5"].Enabled = false; // <- Delete this line
settings.Integrations["ElasticsearchNet"].Enabled = false;  // <- Add this line

Obsolete APIs have been removed

The following deprecated APIs were removed.

  • TracerSettings.DebugEnabled was removed. Set the DD_TRACE_DEBUG environment variable to 1 to enable debug mode.
  • Tags.ForceDrop and Tags.ForceKeep were removed. Use Tags.ManualDrop and Tags.ManualKeep respectively instead.
  • SpanTypes associated with automatic instrumentation spans, such as MongoDb and Redis, were removed.
  • Tags associated with automatic instrumentation spans, such as AmqpCommand and CosmosDbContainer, were removed.
  • Tracer.Create() was removed. Use Tracer.Configure() instead.
  • TracerSettings.AdoNetExcludedTypes was removed. Use TracerSettings.Integrations to configure ADO.NET automatic instrumentation.
  • Various internal APIs not intended for public consumption were removed.

In addition, some settings were marked obsolete in 2.0:

  • Environment variables DD_TRACE_ANALYTICS_ENABLED, DD_TRACE_{0}_ANALYTICS_ENABLED, and DD_TRACE_{0}_ANALYTICS_SAMPLE_RATE for controlling App Analytics are obsolete. App Analytics has been replaced with Tracing Without Limits. See our documentation for details.
  • TracerSettings.AnalyticsEnabled, IntegrationSettings.AnalyticsEnabled, and IntegrationSettings.AnalyticsSampleRate were marked obsolete.
  • Environment variable DD_TRACE_LOG_PATH is deprecated. Use DD_TRACE_LOG_DIRECTORY instead.

Introduction of interfaces ISpan, IScope, and ITracer

.NET Tracer 2.0 makes the public Scope and Span classes internal. Instead, we now expose public IScope and ISpan interfaces and the tracer API was updated accordingly. If you are currently using explicit types (instead of inferring types with var), replace usages of Scope with IScope and Span with ISpan.

This Tracer release also adds the new ITracer interface, implemented by the Tracer class. The type of static property Tracer.Instance is still Tracer, so use of ITracer is not required, but the new interface can be useful for testing with mocks and dependency injection.

To update your Scope/Span code:

using Datadog.Trace;

// No changes required here (using var)
using (var scope = Tracer.Instance.StartActive("my-operation"))
    var span = scope.Span;
    // ...

// No longer compiles (Scope and Span are no longer public)
using (Scope scope = Tracer.Instance.StartActive("my-operation"))
    Span span = scope.Span;
    // ...

// Correct usage with explicit types (using IScope and ISpan)
using (IScope scope = Tracer.Instance.StartActive("my-operation"))
    ISpan span = scope.Span;
    // ...

Simplification of the tracer interface

In addition to returning IScope, several parameters parameters in the Tracer.StartActive method signature were replaced with a single SpanCreationSettings. The span's service name can no longer be set from Tracer.StartActive. Instead, set Span.ServiceName after creating the span.

To update your Scope/Span code:

using Datadog.Trace;

// No changes required here (using only operation name)
using (var scope = Tracer.Instance.StartActive("my-operation"))
    // ...

// No longer compiles (most parameters removed)
using (var scope = Tracer.Instance.StartActive("my-operation", parent: spanContext, serviceName: "my-service", ...))
    // ...

// Correct usage
var spanCreationSettings = new SpanCreationSettings() { Parent = spanContext };
using (var scope = Tracer.Instance.StartActive("my-operation", spanCreationSettings))
    scope.Span.ServiceName = "my-service";
    // ...

Incorrect integration names are ignored

In .NET Tracer 2.0, any changes made to an IntegrationSettings object for an unknown IntegrationId will not be persisted. Instead, a warning will be logged describing the invalid access.

using Datadog.Trace;

var tracerSettings = TracerSettings.FromDefaultSources();

// Accessing settings for an unknown integration will log a warning
var settings = tracerSettings.Integrations["MyRandomIntegration"];

// changes are not persisted
settings.Enabled = false;

// isEnabled is null, not false
bool? isEnabled = tracerSettings.Integrations["MyRandomIntegration"].Enabled;

Automatic instrumentation changes


.NET Tracer 1.26.0 added the DD_TRACE_ROUTE_TEMPLATE_RESOURCE_NAMES_ENABLED feature flag, which enables improved span names for ASP.NET and ASP.NET Core automatic instrumentation spans, an additional span for ASP.NET Core requests, and additional tags.

In .NET Tracer 2.0, DD_TRACE_ROUTE_TEMPLATE_RESOURCE_NAMES_ENABLED is enabled by default. Due to the change in span names, you may need to update your monitors and dashboards to use the new resource names.

If you do not wish to take advantage of the improved route names, you can disable the feature by setting the DD_TRACE_ROUTE_TEMPLATE_RESOURCE_NAMES_ENABLED environment variable to 0.

Call-site instrumentation removed

Call-site automatic instrumentation was removed in .NET Tracer 2.0 and replaced with call-target instrumentation. This was the default mode since version 1.28.0 on .NET Framework 4.6 or above and .NET Core / .NET 5. Call-target instrumentation provides performance and reliability improvements over call-site instrumentation.

Note: Call-target instrumentation does not support instrumenting custom implementations of DbCommand yet. If you find ADO.NET spans are missing from your traces after upgrading, please raise an issue on GitHub, or contact support.

DD_INTEGRATIONS environment variable no longer needed

The integrations.json file is no longer required for instrumentation. You can remove references to this file, for example by deleting the DD_INTEGRATIONS environment variable.

User Identification

The tracer provides a convenient method to link an actor to a trace. You have to pass a UserDetails object with at least its Id property set to a non-null value.

To correlate users to web requests, you would need to use the following code snippet within each web request, after user authorization has been performed:

using Datadog.Trace;

// ...

    var userDetails = new UserDetails()
        // the systems internal identifier for the users
        Id = "d41452f2-483d-4082-8728-171a3570e930",
        // the email address of the user
        Email = "",
        // the user's name, as displayed by the system
        Name = "Jane Doh",
        // the user's session id
        SessionId = "d0632156-132b-4baa-95b2-a492c5f9cb16",
        // the role the user is making the request under
        Role = "standard",

Get in touch

If you have questions, feedback, or feature requests, reach our support.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on Datadog.Trace:

Package Downloads
Datadog.Trace.OpenTracing The ID prefix of this package has been reserved for one of the owners of this package by

Provides OpenTracing support for Datadog APM

Datadog.Monitoring.Distribution The ID prefix of this package has been reserved for one of the owners of this package by

Auto-instrumentation assets for Datadog APM

Lucca.Logs.Shared The ID prefix of this package has been reserved for one of the owners of this package by



Package Description


This package contains 2 Rebus steps. One step to be used in the producer to populate the Rebus message header and the second one to be used in the Consumer to fetch those headers and create a trace that link with the one in the producer, this way having a distributed tracing across microservice.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Datadog.Trace:

Repository Stars
.NET Library for Datadog APM
Version Downloads Last updated
2.15.0 3,760 9/26/2022
2.14.0 94,183 8/23/2022
2.13.0 82,782 8/3/2022
2.12.0 63,885 7/13/2022
2.11.0 129,413 6/22/2022
2.10.0 102,212 6/9/2022
2.9.0 196,344 5/13/2022
2.8.0 75,807 5/5/2022
2.7.0 102,712 4/22/2022
2.6.0 166,076 4/7/2022
2.5.1 92,076 3/25/2022
2.4.4 232,611 3/16/2022
2.4.3 142,023 3/2/2022
2.4.2 27,423 2/25/2022
2.4.1 2,659 2/24/2022
2.4.0 12,984 2/22/2022
2.3.0 180,901 2/10/2022
2.2.0 92,797 2/2/2022
2.1.1 160,222 1/19/2022
2.1.0 149,263 1/7/2022
2.0.1 204,848 12/20/2021
2.0.0-prerelease 5,889 12/10/2021
1.31.2 36,911 2/22/2022
1.31.1 32,187 12/21/2021
1.31.0 119,064 12/2/2021
1.30.1 118,088 11/24/2021
1.30.0 101,694 11/16/2021
1.29.1-prerelease 42,955 10/28/2021
1.29.0 351,753 10/15/2021
1.28.8 96,966 9/29/2021
1.28.7 134,408 9/14/2021
1.28.6 51,224 9/8/2021
1.28.5-prerelease 430 8/30/2021
1.28.4 121,023 8/30/2021
1.28.3-prerelease 254 8/17/2021
1.28.2 153,120 8/4/2021
1.28.1-prerelease 357 7/14/2021
1.28.0 184,449 7/12/2021
1.27.1 440,705 6/16/2021
1.27.0 108,325 6/2/2021
1.26.3 333,478 5/11/2021
1.25.2-prerelease 2,359 4/2/2021
1.25.0 279,294 3/22/2021
1.24.0 309,271 2/23/2021
1.23.0 238,060 2/3/2021
1.22.2-prerelease 272 2/1/2021
1.22.1-prerelease 276 1/28/2021
1.22.0 145,870 1/14/2021
1.21.2-prerelease 2,177 12/21/2020
1.21.1 61,197 12/17/2020
1.21.0 97,667 11/25/2020
1.20.0 143,185 11/3/2020
1.19.6-prerelease 1,358 10/15/2020
1.19.5 240,119 10/7/2020
1.19.4 76,007 9/29/2020
1.19.3 124,019 9/17/2020
1.19.2 229,193 8/31/2020
1.19.1 265,676 8/10/2020
1.19.0 68,066 8/7/2020
1.18.3 135,496 7/17/2020
1.18.2 41,676 7/9/2020
1.18.1-prerelease 409 7/6/2020
1.18.0 30,551 6/25/2020
1.17.1-prerelease 441 6/23/2020
1.17.0 357,517 5/15/2020
1.16.3-prerelease 416 5/13/2020
1.16.2 52,190 5/5/2020
1.16.1 90,701 4/20/2020
1.16.0 32,210 4/2/2020
1.15.1-prerelease 527 3/30/2020
1.15.0 167,837 3/23/2020
1.14.2 14,754 3/13/2020
1.14.1-prerelease 365 3/12/2020
1.14.0 6,047 3/9/2020
1.13.4-prerelease 1,334 3/4/2020
1.13.3-prerelease 458 2/24/2020
1.13.2 115,855 2/21/2020
1.13.0 281,141 2/14/2020
1.12.0 78,206 2/5/2020
1.11.1-prerelease 1,097 1/13/2020
1.11.0 106,324 12/11/2019
1.10.3-prerelease 532 12/11/2019
1.10.2-prerelease 455 12/10/2019
1.10.1-prerelease 549 12/10/2019
1.10.0 63,764 11/27/2019
1.9.1-prerelease 795 11/14/2019
1.9.0 130,378 11/7/2019
1.8.0 127,198 10/17/2019
1.7.0 83,287 9/10/2019
1.6.2 39,511 8/20/2019
1.6.1 21,031 8/14/2019
1.6.0 77,301 7/20/2019
1.4.1 347,775 6/26/2019
1.4.0 44,405 6/20/2019
1.2.0 65,285 5/20/2019
1.1.0 76,140 4/17/2019
1.0.0 55,450 4/5/2019
0.8.2-beta 3,575 3/28/2019
0.8.1-beta 2,129 3/21/2019
0.8.0-beta 1,744 3/11/2019
0.7.1-beta 50,408 1/31/2019
0.7.0-beta 15,923 1/17/2019
0.6.0-beta 58,433 12/21/2018
0.5.2-beta 29,190 12/4/2018
0.5.1-beta 9,145 11/20/2018
0.5.0-beta 610,566 10/30/2018
0.4.1-beta 2,685 10/23/2018
0.4.0-beta 813 10/12/2018
0.3.2-beta 1,845 9/26/2018
0.3.1-beta 913 9/21/2018
0.3.0-beta 736 9/13/2018
0.2.4-alpha 751 9/13/2018