# open-telemetry/opentelemetry-dotnet-instrumentation architecture

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

- Interactive diagram: https://gitdiagram.com/open-telemetry/opentelemetry-dotnet-instrumentation
- Repository: https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation

## Overview

This repository provides zero-code OpenTelemetry instrumentation for .NET applications. The principal flow starts when an application launches with the instrumentation enabled: startup components load the managed profiler, runtime profiling can rewrite application methods, and managed instrumentation configures the OpenTelemetry SDK to produce telemetry. Separate capabilities include library/API integrations, continuous profiling, plugin extensions, and OpAmp remote management. The README documents the overall flow; source excerpts and the SOURCE INDEX provide more specific component relationships, so unsampled internal links are omitted.

Main entry points: [`src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp`](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp) (Native CLR profiler), [`src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs`](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs) (Profiler manager), [`src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs`](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs) (Startup hook), [`src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs`](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs) (Plugin manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and loading"]
  node_startup_hook["Startup hook<br/>[StartupHook.cs]"]
  node_rule_engine["Startup validation<br/>[RuleEngine.cs]"]
  node_bootstrapper["ASP.NET bootstrapper"]
  node_loader["Managed loader<br/>[Loader.cs]"]
  node_load_context["Profiler load context"]
end

subgraph group_runtime["Runtime instrumentation"]
  node_native_profiler["Native CLR profiler<br/>[cor_profiler.cpp]"]
  node_rejit["Method rewriting<br/>[rejit_handler.cpp]"]
  node_configuration["Profiler configuration<br/>[configuration.cpp]"]
  node_instrumentations["Library integrations<br/>[Instrumentations]"]
end

subgraph group_telemetry["Telemetry and extensions"]
  node_sdk_setup["SDK configuration"]
  node_plugins["Plugin manager<br/>[PluginManager.cs]"]
  node_opamp["OpAmp management<br/>[OpAmpManager.cs]"]
end

subgraph group_profiling["Continuous profiling"]
  node_continuous_manager["Profiler manager"]
  node_canary["Canary thread"]
  node_sampler["Runtime sampler"]
end

node_application((".NET application"))
node_otel_sdk["OpenTelemetry .NET SDK"]
node_telemetry_output(("Telemetry destination"))

node_application -->|"loads at startup"| node_startup_hook
node_application -.->|"enables hosting startup"| node_bootstrapper
node_startup_hook -->|"validates startup"| node_rule_engine
node_startup_hook -.->|"loads profiler"| node_loader
node_loader -->|"loads assemblies"| node_load_context
node_application -->|"enables profiler"| node_native_profiler
node_native_profiler -.->|"dispatches rewriting"| node_rejit
node_native_profiler -.->|"reads configuration"| node_configuration
node_native_profiler -->|"injects instrumentation"| node_instrumentations
node_instrumentations -->|"adds telemetry"| node_otel_sdk
node_sdk_setup -->|"configures SDK"| node_otel_sdk
node_otel_sdk -->|"exports telemetry"| node_telemetry_output
node_plugins -->|"configures providers"| node_otel_sdk
node_opamp -->|"selects plugin"| node_plugins
node_continuous_manager -->|"initializes plugins"| node_plugins
node_continuous_manager -->|"starts canary thread"| node_canary
node_continuous_manager -.->|"configures sampling"| node_sampler
node_sampler -.->|"exports samples"| node_telemetry_output

click node_startup_hook "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs"
click node_rule_engine "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs"
click node_bootstrapper "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper/BootstrapperHostingStartup.cs"
click node_loader "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.cs"
click node_load_context "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Loader/ManagedProfilerAssemblyLoadContext.cs"
click node_native_profiler "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp"
click node_rejit "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/rejit_handler.cpp"
click node_configuration "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/configuration.cpp"
click node_instrumentations "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/tree/main/src/OpenTelemetry.AutoInstrumentation/Instrumentations"
click node_sdk_setup "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/HttpClientInitializer.cs"
click node_plugins "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs"
click node_opamp "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/OpAmp/OpAmpManager.cs"
click node_continuous_manager "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs"
click node_canary "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/CanaryThreadManager.cs"
click node_sampler "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/runtime_sampler_service.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_startup_hook,node_rule_engine,node_bootstrapper,node_loader,node_load_context toneBlue
class node_native_profiler,node_rejit,node_configuration,node_instrumentations toneAmber
class node_sdk_setup,node_plugins,node_opamp toneMint
class node_continuous_manager,node_canary,node_sampler toneRose
class node_application,node_otel_sdk,node_telemetry_output toneIndigo
```

## Components

### Startup and loading

- [Startup hook](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs): `src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs`
- [Startup validation](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs): `src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs`
- [ASP.NET bootstrapper](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper/BootstrapperHostingStartup.cs): `src/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper/BootstrapperHostingStartup.cs`
- [Managed loader](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.cs): `src/OpenTelemetry.AutoInstrumentation.Loader/Loader.cs`
- [Profiler load context](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Loader/ManagedProfilerAssemblyLoadContext.cs): `src/OpenTelemetry.AutoInstrumentation.Loader/ManagedProfilerAssemblyLoadContext.cs`

### Runtime instrumentation

- [Native CLR profiler](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp): `src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp`
- [Method rewriting](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/rejit_handler.cpp): `src/OpenTelemetry.AutoInstrumentation.Native/rejit_handler.cpp`
- [Profiler configuration](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/configuration.cpp): `src/OpenTelemetry.AutoInstrumentation.Native/configuration.cpp`
- [Library integrations](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/tree/main/src/OpenTelemetry.AutoInstrumentation/Instrumentations): `src/OpenTelemetry.AutoInstrumentation/Instrumentations`

### Telemetry and extensions

- [SDK configuration](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/HttpClientInitializer.cs): `src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/HttpClientInitializer.cs`
- [Plugin manager](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs): `src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs`
- [OpAmp management](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/OpAmp/OpAmpManager.cs): `src/OpenTelemetry.AutoInstrumentation/OpAmp/OpAmpManager.cs`

### Continuous profiling

- [Profiler manager](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs): `src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs`
- [Canary thread](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/CanaryThreadManager.cs): `src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/CanaryThreadManager.cs`
- [Runtime sampler](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/src/OpenTelemetry.AutoInstrumentation.Native/runtime_sampler_service.cpp): `src/OpenTelemetry.AutoInstrumentation.Native/runtime_sampler_service.cpp`

### Other components

- **.NET application**
- **OpenTelemetry .NET SDK**
- **Telemetry destination**

## Connections

- .NET application → Startup hook: loads at startup
- .NET application → ASP.NET bootstrapper: enables hosting startup
- Startup hook → Startup validation: validates startup (evidence: `src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs`)
- Startup hook → Managed loader: loads profiler
- Managed loader → Profiler load context: loads assemblies (evidence: `src/OpenTelemetry.AutoInstrumentation.Loader/ManagedProfilerAssemblyLoadContext.cs`)
- .NET application → Native CLR profiler: enables profiler
- Native CLR profiler → Method rewriting: dispatches rewriting
- Native CLR profiler → Profiler configuration: reads configuration
- Native CLR profiler → Library integrations: injects instrumentation
- Library integrations → OpenTelemetry .NET SDK: adds telemetry
- SDK configuration → OpenTelemetry .NET SDK: configures SDK
- OpenTelemetry .NET SDK → Telemetry destination: exports telemetry
- Plugin manager → OpenTelemetry .NET SDK: configures providers (evidence: `src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs`)
- OpAmp management → Plugin manager: selects plugin (evidence: `src/OpenTelemetry.AutoInstrumentation/OpAmp/OpAmpManager.cs`)
- Profiler manager → Plugin manager: initializes plugins (evidence: `src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs`)
- Profiler manager → Canary thread: starts canary thread (evidence: `src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs`)
- Profiler manager → Runtime sampler: configures sampling
- Runtime sampler → Telemetry destination: exports samples
