Datadog.Trace 2.13.0 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET 6.0 .NET Core 3.1 .NET Standard 2.0 .NET Framework 4.6.1
Install-Package Datadog.Trace -Version 2.13.0
dotnet add package Datadog.Trace --version 2.13.0
<PackageReference Include="Datadog.Trace" Version="2.13.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Datadog.Trace --version 2.13.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Datadog.Trace, 2.13.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.13.0

// Install Datadog.Trace as a Cake Tool
#tool nuget:?package=Datadog.Trace&version=2.13.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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
Tracer.Configure(settings);

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

Tracer.Configure(settings);

// 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

Tracer.Configure(settings);

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

DD_TRACE_ROUTE_TEMPLATE_RESOURCE_NAMES_ENABLED enabled by default

.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 = "test@adventure-works.com",
        // 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",
    };
    Tracer.Instance.ActiveScope?.Span.SetUser(userDetails);

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 (7)

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 NuGet.org.

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 NuGet.org.

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 NuGet.org.

Lucca.Logs

Rebus.Datadog.Tracing

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.

Rixian.Serilog.Enricher.Datadog

Adds enrichers that add the Datadog SpanID and TraceID fields to the output logs.

GitHub repositories (1)

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

Repository Stars
DataDog/dd-trace-dotnet
.NET Tracer for Datadog APM
Version Downloads Last updated
2.13.0 2,811 8/3/2022
2.12.0 33,990 7/13/2022
2.11.0 71,049 6/22/2022
2.10.0 59,829 6/9/2022
2.9.0 135,785 5/13/2022
2.8.0 55,993 5/5/2022
2.7.0 82,523 4/22/2022
2.6.0 131,707 4/7/2022
2.5.1 73,420 3/25/2022
2.4.4 176,088 3/16/2022
2.4.3 105,649 3/2/2022
2.4.2 20,150 2/25/2022
2.4.1 1,932 2/24/2022
2.4.0 11,976 2/22/2022
2.3.0 139,167 2/10/2022
2.2.0 71,279 2/2/2022
2.1.1 139,060 1/19/2022
2.1.0 116,589 1/7/2022
2.0.1 185,330 12/20/2021
2.0.0-prerelease 5,458 12/10/2021
1.31.2 27,324 2/22/2022
1.31.1 29,055 12/21/2021
1.31.0 111,041 12/2/2021
1.30.1 112,415 11/24/2021
1.30.0 81,687 11/16/2021
1.29.1-prerelease 35,656 10/28/2021
1.29.0 306,776 10/15/2021
1.28.8 93,498 9/29/2021
1.28.7 118,115 9/14/2021
1.28.6 48,786 9/8/2021
1.28.5-prerelease 400 8/30/2021
1.28.4 115,768 8/30/2021
1.28.3-prerelease 234 8/17/2021
1.28.2 143,668 8/4/2021
1.28.1-prerelease 338 7/14/2021
1.28.0 177,096 7/12/2021
1.27.1 398,466 6/16/2021
1.27.0 104,243 6/2/2021
1.26.3 306,844 5/11/2021
1.25.2-prerelease 2,334 4/2/2021
1.25.0 261,343 3/22/2021
1.24.0 297,113 2/23/2021
1.23.0 230,990 2/3/2021
1.22.2-prerelease 256 2/1/2021
1.22.1-prerelease 260 1/28/2021
1.22.0 142,003 1/14/2021
1.21.2-prerelease 1,831 12/21/2020
1.21.1 59,979 12/17/2020
1.21.0 95,178 11/25/2020
1.20.0 136,071 11/3/2020
1.19.6-prerelease 1,340 10/15/2020
1.19.5 229,745 10/7/2020
1.19.4 72,635 9/29/2020
1.19.3 115,658 9/17/2020
1.19.2 222,303 8/31/2020
1.19.1 237,330 8/10/2020
1.19.0 67,919 8/7/2020
1.18.3 128,160 7/17/2020
1.18.2 40,874 7/9/2020
1.18.1-prerelease 393 7/6/2020
1.18.0 29,881 6/25/2020
1.17.1-prerelease 421 6/23/2020
1.17.0 350,525 5/15/2020
1.16.3-prerelease 396 5/13/2020
1.16.2 51,558 5/5/2020
1.16.1 79,202 4/20/2020
1.16.0 31,650 4/2/2020
1.15.1-prerelease 516 3/30/2020
1.15.0 160,864 3/23/2020
1.14.2 13,455 3/13/2020
1.14.1-prerelease 349 3/12/2020
1.14.0 6,003 3/9/2020
1.13.4-prerelease 1,313 3/4/2020
1.13.3-prerelease 440 2/24/2020
1.13.2 115,701 2/21/2020
1.13.0 273,857 2/14/2020
1.12.0 75,951 2/5/2020
1.11.1-prerelease 1,076 1/13/2020
1.11.0 105,719 12/11/2019
1.10.3-prerelease 516 12/11/2019
1.10.2-prerelease 440 12/10/2019
1.10.1-prerelease 536 12/10/2019
1.10.0 62,352 11/27/2019
1.9.1-prerelease 744 11/14/2019
1.9.0 122,542 11/7/2019
1.8.0 122,618 10/17/2019
1.7.0 80,659 9/10/2019
1.6.2 37,856 8/20/2019
1.6.1 20,986 8/14/2019
1.6.0 77,176 7/20/2019
1.4.1 343,985 6/26/2019
1.4.0 44,139 6/20/2019
1.2.0 64,019 5/20/2019
1.1.0 75,611 4/17/2019
1.0.0 54,132 4/5/2019
0.8.2-beta 3,473 3/28/2019
0.8.1-beta 2,115 3/21/2019
0.8.0-beta 1,725 3/11/2019
0.7.1-beta 50,238 1/31/2019
0.7.0-beta 15,438 1/17/2019
0.6.0-beta 57,482 12/21/2018
0.5.2-beta 29,172 12/4/2018
0.5.1-beta 8,762 11/20/2018
0.5.0-beta 610,536 10/30/2018
0.4.1-beta 2,674 10/23/2018
0.4.0-beta 796 10/12/2018
0.3.2-beta 1,826 9/26/2018
0.3.1-beta 898 9/21/2018
0.3.0-beta 719 9/13/2018
0.2.4-alpha 730 9/13/2018