This folder contains the source code for the Datadog .NET APM Tracer. The .NET Tracer automatically instruments supported libraries out-of-the-box and also supports custom instrumentation to instrument your own code.
Configure the Datadog Agent for APM as described in our documentation. For automatic instrumentation, install and enable the .NET Tracer as described in our documentation.
The Datadog .NET APM Tracer allows you to manually instrument your application (in addition to automatic instrumentation). To use it, please follow the NuGet package documentation
You can develop the tracer on various environments.
- Visual Studio 2022 (v17) or newer
- Workloads
- Desktop development with C++
- .NET desktop development
- Optional: ASP.NET and web development (to build samples)
- Individual components
- When opening a solution, Visual Studio will prompt you to install any missing components. The prompt will appear in the "Solution Explorer". A list of all recommended components can be found in our .vsconfig-file.
- Workloads
- .NET 7.0 SDK
- Optional: .NET 7.0 x86 SDK to run 32-bit tests locally
- Optional: ASP.NET Core Runtimes to run tests locally
- Optional: nuget.exe CLI v5.3 or newer
- Optional: WiX Toolset 3.11.1 or newer to build Windows installer (msi)
- WiX Toolset Visual Studio Extension to build installer from Visual Studio
- Optional: Docker for Windows to build Linux binaries and run integration tests on Linux containers.
- Requires Windows 10 (1607 Anniversary Update, Build 14393 or newer)
Microsoft provides evaluation developer VMs with Windows and Visual Studio pre-installed.
This repository uses Nuke for build automation. To see a list of possible targets run:
.\build.cmd --help
For example:
# Clean and build the main tracer project
.\build.cmd Clean BuildTracerHome
# Build and run managed and native unit tests. Requires BuildTracerHome to have previously been run
.\build.cmd BuildAndRunManagedUnitTests BuildAndRunNativeUnitTests
# Build NuGet packages and MSIs. Requires BuildTracerHome to have previously been run
.\build.cmd PackageTracerHome
# Build and run integration tests. Requires BuildTracerHome to have previously been run
.\build.cmd BuildAndRunWindowsIntegrationTests
- Install the Dev Containers Extension in VS Code.
- Open a local VS Code window on the cloned repository.
- Open the command palette (
Ctrl+Shift+P
orCmd+Shift+P
on macOS) and select "Dev Containers: Reopen in Container". - Choose the Tracer.
- VS Code will open a new window connected to the selected container.
- Open the command palette again and select .NET: Open Solution. Choose the
Datadog.Trace.Minimal.slnf
solution file. Read more at Project Management. - You can now build and run the tracer in the devcontainer.
- [Optional] Open the command palette, select
Tasks: Run Build Task
,Tracer: Build on {OS} with Target
and choose the target you want to build.
- Ensure the Dev Containers plugin is enabled (it comes bundled with Rider).
- Open Rider, select Remote Development, then choose Dev Containers.
- Since we want to use the Dev Container from the repository, select "From Local Project" and choose
.devcontainer/devcontainer.json
. - In the Select a Solution to Open window, pick
Datadog.Trace.Minimal.slnf
. - You can now build and run the tracer inside the Dev Container.
- Currently, the devcontainer is configured to use
debian.dockerfile
, but you can change it to either a local Dockerfile or a remote image as per your requirements. - Building Tracer can be resource-intensive and may even run out of memory (OOM) in some cases. If you encounter the error
MSB6006: "csc.dll" exited with code 137.
, increase the memory allocated to the devcontainer (16GB is recommended). Datadog.Trace.Minimal.slnf
is a minimal solution file that includes all the projects required to build the tracer. You can open other solutions as well, but they may not be fully supported in the devcontainer.
The recommended approach for Linux is to build using Docker. You can use this approach for both Windows and Linux hosts. The build_in_docker.sh script automates building a Docker image with the required dependencies, and running the specified Nuke targets. For example, on Linux:
# Clean and build the main tracer project
./build_in_docker.sh Clean BuildTracerHome
# Build and run managed unit tests. Requires BuildTracerHome to have previously been run
./build_in_docker.sh BuildAndRunManagedUnitTests
# Build and run integration tests. Requires BuildTracerHome to have previously been run
./build_in_docker.sh BuildAndRunLinuxIntegrationTests
Alternatively, on Windows:
./build_in_docker.ps1 BuildTracerHome BuildAndRunLinuxIntegrationTests
You can use Rider and CLion, or Visual Studio Code to develop on macOS. When asked to select a solution file select Datadog.Trace.OSX.slnf
. If using CLion for the native code make sure to select "Let CMake decide" for the generator.
Building and testing can be done through the following Nuke targets:
# Clean and build the main tracer project
./build.sh Clean BuildTracerHome
# Build and run managed and native unit tests. Requires BuildTracerHome to have previously been run
./build.sh BuildAndRunManagedUnitTests BuildAndRunNativeUnitTests
# Build NuGet packages and MSIs. Requires BuildTracerHome to have previously been run
./build.sh PackageTracerHome
# Start IntegrationTests dependencies.
docker-compose up StartDependencies.OSXARM64
# Build and run integration tests. Requires BuildTracerHome to have previously been run
./build.sh BuildAndRunOsxIntegrationTests
# Build and run integration tests filtering on one framework, one set of tests and a sample app.
./build.sh BuildAndRunOsxIntegrationTests --framework "net6.0" --filter "rabbit" --SampleName "Samples.Rabbit"
# Stop IntegrationTests dependencies.
docker-compose down
Troubleshooting tips for build errors:
- Try deleting the
cmake-build-debug
andobj_*
directories. - Verify your xcode developer tools installation with
xcode-select --install
. You may need to repeat this process after an operating system update.
- Implementing an automatic instrumentation
- Duck typing: usages, best practices, and benchmarks
- Datadog.Trace NuGet package README
Datadog APM
- Datadog APM
- Datadog APM - Tracing .NET Core Applications
- Datadog APM - Tracing .NET Framework Applications
Microsoft .NET Profiling APIs
OpenTracing