# datadog/dd-trace-dotnet architecture

> Architecture diagram of the GitHub repository datadog/dd-trace-dotnet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/datadog/dd-trace-dotnet
- Repository: https://github.com/datadog/dd-trace-dotnet

## Overview

This repository provides Datadog’s .NET APM tracer and continuous profiler. An application is instrumented at supported call sites to create tracing scopes; the repository also includes CI coverage and security/dynamic-instrumentation capabilities. The profiler gathers runtime and platform events and produces profiling data. The sampled sources show Elasticsearch scope creation, Cosmos DB query instrumentation, global-coverage artifact publication, and Windows ETW event handling; other capability branches are represented from the README and tree, with uncertain wiring omitted.

Main entry points: [`tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs`](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs) (Elasticsearch hooks), [`tracer/src/Datadog.Trace/TracerManager.cs`](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/TracerManager.cs) (Tracer core), [`profiler/src/ProfilerEngine/Datadog.Profiler.Native`](https://github.com/datadog/dd-trace-dotnet/tree/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native) (Profiler engine), [`tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/CosmosDb/DatabaseQueryIteratorsIntegrations.cs`](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/CosmosDb/DatabaseQueryIteratorsIntegrations.cs) (Cosmos DB hooks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tracing["Tracing"]
  node_tracer_core["Tracer core<br/>[TracerManager.cs]"]
  node_calltarget["CallTarget runtime<br/>[CallTargetState.cs]"]
  node_calltarget_return["CallTarget return"]
  node_integration_ids["Integration registry<br/>[IntegrationId.cs]"]
end

subgraph group_instrumentation["Instrumentation"]
  node_elasticsearch["Elasticsearch hooks"]
  node_es_common["Elasticsearch spans"]
  node_es_request["Request adaptation<br/>[IRequestData.cs]"]
  node_es_pipeline["Pipeline adaptation"]
  node_cosmos_hooks["Cosmos DB hooks"]
  node_auto_integrations["Supported integrations"]
end

subgraph group_product_features["Product Features"]
  node_ci_coverage["CI coverage"]
  node_appsec["Application security<br/>[Datadog.Trace]"]
  node_dynamic_instrumentation["Dynamic instrumentation<br/>[Debugger]"]
end

subgraph group_profiling["Continuous Profiling"]
  node_profiler_engine["Profiler engine"]
  node_frame_store[("Frame store<br/>[FrameStore.h]")]
  node_profile_output["Profile output<br/>[Exporter.cpp]"]
end

subgraph group_platform["Platform Support"]
  node_etw_manager["ETW event manager"]
  node_linux_profiling["Linux sampling"]
  node_windows_profiling["Windows sampling"]
end

node_application((".NET application"))

node_application -.->|"calls instrumented"| node_elasticsearch
node_elasticsearch -->|"creates scope"| node_es_common
node_elasticsearch -->|"returns state"| node_calltarget
node_elasticsearch -->|"reads request"| node_es_request
node_elasticsearch -->|"adapts pipeline"| node_es_pipeline
node_es_common -->|"starts span"| node_tracer_core
node_elasticsearch -->|"returns result"| node_calltarget_return
node_cosmos_hooks -->|"returns state"| node_calltarget
node_cosmos_hooks -.->|"registers hooks"| node_auto_integrations
node_tracer_core -.->|"enables tracing"| node_auto_integrations
node_tracer_core -.->|"checks integrations"| node_integration_ids
node_application -.->|"produces coverage"| node_ci_coverage
node_ci_coverage -.->|"publishes artifact"| node_profile_output
node_application -.->|"runs protected code"| node_appsec
node_application -.->|"runs observed code"| node_dynamic_instrumentation
node_application -.->|"being profiled"| node_profiler_engine
node_profiler_engine -.->|"uses platform"| node_linux_profiling
node_profiler_engine -.->|"uses platform"| node_windows_profiling
node_etw_manager -->|"stores frames"| node_frame_store
node_etw_manager -.->|"feeds profiling"| node_profile_output

click node_tracer_core "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/TracerManager.cs"
click node_calltarget "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/CallTargetState.cs"
click node_calltarget_return "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/CallTargetReturn.cs"
click node_integration_ids "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/Configuration/IntegrationId.cs"
click node_elasticsearch "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs"
click node_es_common "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/ElasticsearchNetCommon.cs"
click node_es_request "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/IRequestData.cs"
click node_es_pipeline "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/RequestPipelineStruct.cs"
click node_cosmos_hooks "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/CosmosDb/DatabaseQueryIteratorsIntegrations.cs"
click node_auto_integrations "https://github.com/datadog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation"
click node_ci_coverage "https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/Ci/Coverage/GlobalCoverageOutputManager.cs"
click node_appsec "https://github.com/datadog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace"
click node_dynamic_instrumentation "https://github.com/datadog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace/Debugger"
click node_profiler_engine "https://github.com/datadog/dd-trace-dotnet/tree/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native"
click node_etw_manager "https://github.com/datadog/dd-trace-dotnet/blob/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows/EtwEventsManager.cpp"
click node_frame_store "https://github.com/datadog/dd-trace-dotnet/blob/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native/FrameStore.h"
click node_linux_profiling "https://github.com/datadog/dd-trace-dotnet/tree/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux"
click node_windows_profiling "https://github.com/datadog/dd-trace-dotnet/tree/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows"
click node_profile_output "https://github.com/datadog/dd-trace-dotnet/blob/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native/Exporter.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tracer_core,node_calltarget,node_calltarget_return,node_integration_ids toneBlue
class node_elasticsearch,node_es_common,node_es_request,node_es_pipeline,node_cosmos_hooks,node_auto_integrations toneAmber
class node_ci_coverage,node_appsec,node_dynamic_instrumentation toneMint
class node_profiler_engine,node_frame_store,node_profile_output toneRose
class node_etw_manager,node_linux_profiling,node_windows_profiling,node_application toneIndigo
```

## Components

### Tracing

- [Tracer core](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/TracerManager.cs): `tracer/src/Datadog.Trace/TracerManager.cs`
- [CallTarget runtime](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/CallTargetState.cs): `tracer/src/Datadog.Trace/ClrProfiler/CallTarget/CallTargetState.cs`
- [CallTarget return](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/CallTargetReturn.cs): `tracer/src/Datadog.Trace/ClrProfiler/CallTarget/CallTargetReturn.cs`
- [Integration registry](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/Configuration/IntegrationId.cs): `tracer/src/Datadog.Trace/Configuration/IntegrationId.cs`

### Instrumentation

- [Elasticsearch hooks](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs): `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs`
- [Elasticsearch spans](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/ElasticsearchNetCommon.cs): `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/ElasticsearchNetCommon.cs`
- [Request adaptation](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/IRequestData.cs): `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/IRequestData.cs`
- [Pipeline adaptation](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/RequestPipelineStruct.cs): `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/RequestPipelineStruct.cs`
- [Cosmos DB hooks](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/CosmosDb/DatabaseQueryIteratorsIntegrations.cs): `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/CosmosDb/DatabaseQueryIteratorsIntegrations.cs`
- [Supported integrations](https://github.com/datadog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation): `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation`

### Product Features

- [CI coverage](https://github.com/datadog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/Ci/Coverage/GlobalCoverageOutputManager.cs): `tracer/src/Datadog.Trace/Ci/Coverage/GlobalCoverageOutputManager.cs`
- [Application security](https://github.com/datadog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace): `tracer/src/Datadog.Trace`
- [Dynamic instrumentation](https://github.com/datadog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace/Debugger): `tracer/src/Datadog.Trace/Debugger`

### Continuous Profiling

- [Profiler engine](https://github.com/datadog/dd-trace-dotnet/tree/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native): `profiler/src/ProfilerEngine/Datadog.Profiler.Native`
- [Frame store](https://github.com/datadog/dd-trace-dotnet/blob/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native/FrameStore.h): `profiler/src/ProfilerEngine/Datadog.Profiler.Native/FrameStore.h`
- [Profile output](https://github.com/datadog/dd-trace-dotnet/blob/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native/Exporter.cpp): `profiler/src/ProfilerEngine/Datadog.Profiler.Native/Exporter.cpp`

### Platform Support

- [ETW event manager](https://github.com/datadog/dd-trace-dotnet/blob/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows/EtwEventsManager.cpp): `profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows/EtwEventsManager.cpp`
- [Linux sampling](https://github.com/datadog/dd-trace-dotnet/tree/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux): `profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux`
- [Windows sampling](https://github.com/datadog/dd-trace-dotnet/tree/master/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows): `profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows`

### Other components

- **.NET application**

## Connections

- .NET application → Elasticsearch hooks: calls instrumented
- Elasticsearch hooks → Elasticsearch spans: creates scope (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs`)
- Elasticsearch hooks → CallTarget runtime: returns state (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs`)
- Elasticsearch hooks → Request adaptation: reads request (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs`)
- Elasticsearch hooks → Pipeline adaptation: adapts pipeline (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs`)
- Elasticsearch spans → Tracer core: starts span (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/ElasticsearchNetCommon.cs`)
- Elasticsearch hooks → CallTarget return: returns result (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/V5/RequestPipeline_CallElasticsearchAsync_Integration.cs`)
- Cosmos DB hooks → CallTarget runtime: returns state (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/CosmosDb/DatabaseQueryIteratorsIntegrations.cs`)
- Cosmos DB hooks → Supported integrations: registers hooks (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/CosmosDb/DatabaseQueryIteratorsIntegrations.cs`)
- Tracer core → Supported integrations: enables tracing (evidence: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Elasticsearch/ElasticsearchNetCommon.cs`)
- Tracer core → Integration registry: checks integrations
- .NET application → CI coverage: produces coverage
- CI coverage → Profile output: publishes artifact
- .NET application → Application security: runs protected code
- .NET application → Dynamic instrumentation: runs observed code
- .NET application → Profiler engine: being profiled
- Profiler engine → Linux sampling: uses platform (evidence: `profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/ProfilerSignalManager.cpp`)
- Profiler engine → Windows sampling: uses platform (evidence: `profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows/EtwEventsManager.cpp`)
- ETW event manager → Frame store: stores frames (evidence: `profiler/src/ProfilerEngine/Datadog.Profiler.Native.Windows/EtwEventsManager.cpp`)
- ETW event manager → Profile output: feeds profiling
