Profiling .Net
Starting from Datakit Version-1.12.0, support for using dd-trace-dotnet
as an application performance monitoring tool for the .NET
platform is available.
Prerequisites¶
.NET Framework 4.5.2+
/.NET Core 2.1, 3.1, 5, 6, 7
Linux with glibc 2.17+
/Windows 10+
/Windows Server 2012+
Install dd-trace-dotnet
¶
Download the datadog-dotnet-apm-<VERSION>-x64.msi
file from here, such as datadog-dotnet-apm-2.34.0-x64.msi
, and install it with administrator privileges.
Note
The highest supported version is dd-trace-dotnet v2.34.0
. Higher versions have not been systematically tested, and compatibility is unknown. If you encounter any issues during use, please contact us.
Start Profiling¶
Linux Platform¶
Navigate to the output directory of your project's compilation or release, where you will find a datadog
directory. This directory contains the target files generated by dd-trace-dotnet
after compilation, with different subdirectories for different platforms.
Directory Explanation
The output directory of .NET Core compilation (build) is usually located under the project root directory in ./bin/<Configuration>/<Framework>. You can specify the output directory with the -o|--output <OUTPUT_DIR>
parameter. In this document, it is assumed to be ./bin/Release/net7.0.
The output directory of .NET Core release (publish) is by default located under the project root directory in ./bin/<Configuration>/<Framework>/publish. You can also specify the output directory with the -o|--output <OUTPUT_DIR>
parameter. In this document, it is assumed to be ./bin/Release/net7.0/publish.
$ ls -l bin/Release/net7.0/datadog/
total 8
-rwxr--r-- 1 zy staff 101 7 3 21:06 createLogPath.sh
drwxr-xr-x 8 zy staff 256 7 27 16:16 linux-arm64
drwxr-xr-x 8 zy staff 256 7 27 16:16 linux-musl-x64
drwxr-xr-x 8 zy staff 256 7 27 16:16 linux-x64
drwxr-xr-x 8 zy staff 256 7 27 16:16 net461
drwxr-xr-x 7 zy staff 224 7 27 16:16 net6.0
drwxr-xr-x 7 zy staff 224 7 27 16:16 netcoreapp3.1
drwxr-xr-x 12 zy staff 384 7 27 16:16 netstandard2.0
drwxr-xr-x 6 zy staff 192 7 27 16:16 osx
drwxr-xr-x 7 zy staff 224 7 27 16:16 win-x64
drwxr-xr-x 7 zy staff 224 7 27 16:16 win-x86
Set the DDTRACE_HOME
environment variable:
Check if the environment variable is set correctly:
Set the environment variable and start the project:
DD_DOTNET_TRACER_HOME="$DDTRACE_HOME" \
CORECLR_ENABLE_PROFILING=1 \
CORECLR_PROFILER="{846F5F1C-F9AE-4B07-969E-05C26BC060D8}" \
CORECLR_PROFILER_PATH="$DDTRACE_HOME/linux-x64/Datadog.Trace.ClrProfiler.Native.so" \
LD_PRELOAD="$DDTRACE_HOME/linux-x64/Datadog.Linux.ApiWrapper.x64.so" \
DD_PROFILING_ENABLED=1 \
DD_PROFILING_WALLTIME_ENABLED=1 \
DD_PROFILING_CPU_ENABLED=1 \
DD_PROFILING_EXCEPTION_ENABLED=1 \
DD_PROFILING_ALLOCATION_ENABLED=1 \
DD_PROFILING_LOCK_ENABLED=1 \
DD_PROFILING_HEAP_ENABLED=1 \
DD_PROFILING_GC_ENABLED=1 \
DD_SERVICE=dotnet-profiling-demo DD_ENV=testing DD_VERSION=1.2.3 \
DD_AGENT_HOST=127.0.0.1 DD_TRACE_AGENT_PORT=9529 \
dotnet bin/Release/net7.0/<your-project-name>.dll
Note
If your current architecture is Linux arm64
, you will need to modify the settings to CORECLR_PROFILER_PATH="$DDTRACE_HOME/linux-arm64/Datadog.Trace.ClrProfiler.Native.so"
and
LD_PRELOAD="$DDTRACE_HOME/linux-arm64/Datadog.Linux.ApiWrapper.x64.so"
After a few minutes, you should be able to view the relevant data in the Guance Cloud Console.
Windows IIS¶
-
Install the datadog-dotnet-apm-2.34.0-x64.msi component on the server.
-
Edit the
web.config
configuration file in the root path of the project deployed onIIS
, and add the<environmentVariables></environmentVariables>
tag inside the<aspNetCore>...</aspNetCore>
tag (if it does not exist, ignore this step) with the following environment variables:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\dotnet-profiling-demo.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
<environmentVariables>
<!-- Add the following environment variables here, adjust the values of DD_ENV DD_SERVICE DD_VERSION according to your actual situation -->
<!-- DD_AGENT_HOST and DD_TRACE_AGENT_PORT are the address and port that Datakit is listening on -->
<environmentVariable name="CORECLR_ENABLE_PROFILING" value="1" />
<environmentVariable name="CORECLR_PROFILER" value="{846F5F1C-F9AE-4B07-969E-05C26BC060D8}" />
<environmentVariable name="DD_PROFILING_ENABLED" value="1" />
<environmentVariable name="DD_PROFILING_CPU_ENABLED" value="1" />
<environmentVariable name="DD_PROFILING_WALLTIME_ENABLED" value="1" />
<environmentVariable name="DD_PROFILING_ALLOCATION_ENABLED" value="1" />
<environmentVariable name="DD_PROFILING_HEAP_ENABLED" value="1" />
<environmentVariable name="DD_PROFILING_EXCEPTION_ENABLED" value="1" />
<environmentVariable name="DD_PROFILING_LOCK_ENABLED" value="1" />
<environmentVariable name="DD_PROFILING_GC_ENABLED" value="1" />
<environmentVariable name="DD_ENV" value="production" />
<environmentVariable name="DD_VERSION" value="1.2.3" />
<environmentVariable name="DD_SERVICE" value="my-dotnet-core-app" />
<environmentVariable name="DD_AGENT_HOST" value="127.0.0.1" />
<environmentVariable name="DD_TRACE_AGENT_PORT" value="9529" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
- Restart the
IIS
server and visit your project.
After a few minutes, you should be able to view the relevant data in the Guance Cloud Console.