Skip to content

.NET

Installation and Configuration

Supported Versions

Version Microsoft End-of-Life Status Supported Version Package Version
.NET 7 - GA latest (>= 2.20.0)
.NET 6 - GA latest (>= 2.0.0)
.NET 5 - GA latest (>= 2.0.0)
.NET Core 3.1 12/03/2022 GA latest
.NET Core 2.1 08/21/2021 GA latest
.NET Core 3.0 03/03/2020 EOL Not recommended
.NET Core 2.2 12/23/2019 EOL Not recommended
.NET Core 2.0 10/01/2018 EOL Not recommended

Install Agent

Info

The Datadog.NET Tracer can be installed machine-wide to instrument all services on a machine, or it can be installed on a per-application basis to allow developers to manage instrumentation through the application's dependencies. To view machine-wide installation instructions, click the Windows or Linux tab. To view per-application installation instructions, click the NuGet tab.

To install the .NET Tracer machine-wide, perform the following steps:

  1. Download the .NET Tracer MSI installer. Select the MSI installer for the architecture that matches your operating system (x64 or x86).
  2. Run the .NET Tracer MSI installer with administrator privileges. You can also script the MSI installer by running the following command in PowerShell: Start-Process -Wait msiexec -ArgumentList '/qn /i datadog-apm.msi'.

To install the .NET Tracer machine-wide, perform the following steps:

  1. Download the .NET Tracer MSI installer. Select the MSI installer for the architecture that matches your operating system (x64 or x86).
  2. Run the relevant installation package according to your operating system, and use appropriate permissions to create the directory /var/log/datadog/dotnet for .NET tracer logs:

    Debian or Ubuntu
    sudo dpkg -i ./datadog-dotnet-apm_<TRACER_VERSION>_amd64.deb && /opt/datadog/createLogPath.sh
    CentOS or Fedora
    sudo rpm -Uvh datadog-dotnet-apm<TRACER_VERSION>-1.x86_64.rpm && /opt/datadog/createLogPath.sh
    Alpine or other musl-based distributions
    sudo tar -C /opt/datadog -xzf datadog-dotnet-apm-<TRACER_VERSION>-musl.tar.gz && sh /opt/datadog/createLogPath.sh
    Other distributions
    sudo tar -C /opt/datadog -xzf datadog-dotnet-apm<TRACER_VERSION>-tar.gz && /opt/datadog/createLogPath.sh

To install the .NET Tracer in a slim or distroless Docker image (without a shell), use commands like the following in your Dockerfile:

  • Use ADD to place the tracer files into the container.
  • Use COPY --chown=$APP_UID with an empty folder as the source to create the log directory.

For example, in the Dockerfile you could write:

ADD datadog-dotnet-apm-<TRACER_VERSION>.tar.gz /opt/datadog/
COPY --chown=$APP_UID --from=<OTHER_STAGE> /empty/ /var/log/datadog/dotnet/
Info

Note: This installation does not instrument applications running in IIS. For applications running in IIS, follow the Windows machine-wide installation process.

Add the .NET Tracer to your application

  1. Add Datadog.Trace.Bundle to your application using the NuGet package.

Enable Tracer for Applications

To enable the .NET Tracer for an application service, you need to set the required environment variables and restart the application.

For information on different methods of setting environment variables, refer to the configuration process Environment Variables.

Internet Information Services (IIS):

  1. The .NET Tracer MSI installer adds all required environment variables. Additional environment variables need to be configured here.
  2. To automatically instrument applications hosted in IIS, run the following commands as an administrator to completely stop and start IIS:
    net stop /y was
    net start w3svc
    
Info

Note: Always use the commands above to completely stop and restart IIS to enable the tracer. Avoid using the IIS Manager GUI application or iisreset.exe.

Non-IIS Applications

  1. Set the following required environment variables for automatic instrumentation to attach to the application:
    CORECLR_ENABLE_PROFILING=1
    CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
    
  2. Restart the application.
  1. Add the necessary environment variables for automatic instrumentation of the application:
    CORECLR_ENABLE_PROFILING=1  
    CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}  
    CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so  
    DD_DOTNET_TRACER_HOME=/opt/datadog  
    
  2. Restart the application.

Add custom probes for .NET applications:

  1. In your application code, access the global tracer via the Datadog.Trace.Tracer.Instance property to create new spans.

Environment Variable Configuration

To attach automatic instrumentation to a service, the required environment variables must be set before starting the application. Please refer to the Enable Tracer for Applications section to determine which environment variables to set based on the .NET tracer installation method, and follow the examples below to correctly set the environment variables according to the environment of the service where the instructions are inserted.

The following variables need to be added regardless of the method

DD_TRACE_AGENT_PORT=9529

DD_AGENT_HOST=localhost

Windows

Info

Starting from v2.14.0, if the tracer was installed using the MSI, setting CORECLR_PROFILER is not required.

In the Registry Editor, create a multi-string value named Environment in the HKLM\System\CurrentControlSet\Services\<SERVICE NAME> key and set the value data to:

CORECLR_ENABLE_PROFILING=1
CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
Img

[string[]] $v = @("CORECLR_ENABLE_PROFILING=1", "CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}")
Set-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\<SERVICE NAME> -Name Environment -Value $v

After installing the MSI, IIS sites are automatically instrumented without additional configuration. To set additional environment variables inherited by all IIS sites, follow these steps:

  1. Open the Registry Editor, find the multi-string value named Environment in the HKLM\System\CurrentControlSet\Services\WAS registry key, and add environment variables, one per line. For example, to add log injection and runtime metrics, add the following lines to the value data:

    DD_LOGS_INJECTION=true
    DD_RUNTIME_METRICS_ENABLED=true
    

  2. Run the following command to restart IIS:

    net stop /y was
    net start w3svc
    # Additionally, any other services that were stopped when WAS was shut down have been started.
    
    Img

To automatically instrument a console application, set the environment variables from a batch file before starting the application:

rem Set environment variables
SET CORECLR_ENABLE_PROFILING=1
rem Unless v2.14.0+ and you installed the tracer with the MSI
SET CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}

rem Set additional Datadog environment variables
SET DD_LOGS_INJECTION=true
SET DD_RUNTIME_METRICS_ENABLED=true

rem Start application
dotnet.exe example.dll

Linux

Set the required environment variables from bash before starting the application:

# Set environment variables
export CORECLR_ENABLE_PROFILING=1
export CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
export CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so
export DD_DOTNET_TRACER_HOME=/opt/datadog

# Set additional Datadog environment variables
export DD_LOGS_INJECTION=true
export DD_RUNTIME_METRICS_ENABLED=true

# Start your application
dotnet example.dll

Configure environment variables in a Docker container:

# Set environment variables
ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so
ENV DD_DOTNET_TRACER_HOME=/opt/datadog

# Set additional Datadog environment variables
ENV DD_LOGS_INJECTION=true
ENV DD_RUNTIME_METRICS_ENABLED=true

# Start your application
CMD ["dotnet", "example.dll"]

When running a .NET application as a service using systemctl, you can add the required environment variables to be loaded for a specific service.

  1. Create a file named environment.env containing:

    # Set environment variables
    CORECLR_ENABLE_PROFILING=1
    CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
    CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so
    DD_DOTNET_TRACER_HOME=/opt/datadog
    
    # Set additional Datadog environment variables
    DD_LOGS_INJECTION=true
    DD_RUNTIME_METRICS_ENABLED=true
    

  2. In the service's configuration file, reference it as an EnvironmentFile in the service block:

    EnvironmentFile=/path/to/environment.env
    ExecStart=<command used to start the application>
    

  3. Restart the .NET service.

Info

Note: The .NET runtime will attempt to load the profiler into any .NET process started after these environment variables are set. You should limit instrumentation to only the applications that need tracing. Do not set these environment variables globally, as this will cause all .NET processes on the host to load the profiler.

When running a .NET application as a service using systemctl, you can also set environment variables to be loaded for all services run by systemctl.

  1. Set the required environment variables by running systemctl set-environment:

    systemctl set-environment CORECLR_ENABLE_PROFILING=1
    systemctl set-environment CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
    systemctl set-environment CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so
    systemctl set-environment DD_DOTNET_TRACER_HOME=/opt/datadog
    
    # Set additional Datadog environment variables
    systemctl set-environment DD_LOGS_INJECTION=true
    systemctl set-environment DD_RUNTIME_METRICS_ENABLED=true
    

  2. Run systemctl show environment to verify that the environment variables were set successfully.

  3. Restart the application service.

Tracing

Collector

Collect .NET application-related Tracing information via DDTrace.

Metrics

Runtime Metrics

Enable runtime metrics in .NET Tracer 1.23.0+ using the DD_RUNTIME_METRICS_ENABLED=true environment variable.

Runtime Metrics Compatibility

  • .NET Framework 4.6.1+
  • .NET Core 3.1
  • .NET 5
  • .NET 6
  • .NET 7

Collector

  1. Enable the statsd collector in DataKit.
  2. The default port is 8125.
  3. If running the Agent as a container, ensure DD_DOGSTATSD_NON_LOCAL_TRAFFIC is set to true and that port 8125 is open on the Agent.

Metric Information

Detailed Metric Information

Logging

File Directory

By default, log files are saved in the following directories. These paths can be changed using the DD_TRACE_LOG_DIRECTORY setting.

Platform Directory
Windows %ProgramData%\Datadog .NET Tracer\logs\
Linux /var/log/datadog/dotnet/
Linux (when using Kubernetes library injection) /datadog-lib/logs
Azure App Service %AzureAppServiceHomeDirectory%\LogFiles\datadog

Note: On Linux, the log directory must be created before debug mode can be enabled.

  • dotnet-tracer-managed-{processName}-{timestamp}.log contains configuration logs.

  • dotnet-tracer-native.log contains diagnostic logs (if generated).

Profiler

Refer to the documentation .NET profiling

Official Documentation

.NET Parameter Documentation

.NET Tracer

.NET Logs

.NET Runtime Metrics

Feedback

Is this page helpful? ×