How open-telemetry/opentelemetry-dotnet-instrumentation works
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: cor_profiler.cpp Native CLR profiler · ContinuousProfilerManager.cs Profiler manager · StartupHook.cs Startup hook · PluginManager.cs Plugin manager
Components 18
Startup and loading
- Startup hook
src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs - Startup validation
src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs - ASP.NET bootstrapper
src/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper/BootstrapperHostingStartup.cs - Managed loader
src/OpenTelemetry.AutoInstrumentation.Loader/Loader.cs - Profiler load context
src/OpenTelemetry.AutoInstrumentation.Loader/ManagedProfilerAssemblyLoadContext.cs
Runtime instrumentation
- Native CLR profiler
src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp - Method rewriting
src/OpenTelemetry.AutoInstrumentation.Native/rejit_handler.cpp - Profiler configuration
src/OpenTelemetry.AutoInstrumentation.Native/configuration.cpp - Library integrations
src/OpenTelemetry.AutoInstrumentation/Instrumentations
Telemetry and extensions
- SDK configuration
src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/HttpClientInitializer.cs - Plugin manager
src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs - OpAmp management
src/OpenTelemetry.AutoInstrumentation/OpAmp/OpAmpManager.cs
Continuous profiling
- Profiler manager
src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs - Canary thread
src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/CanaryThreadManager.cs - Runtime sampler
src/OpenTelemetry.AutoInstrumentation.Native/runtime_sampler_service.cpp
Other components
- .NET application
- OpenTelemetry .NET SDK
- Telemetry destination
Connections 18
- .NET application → Startup hook: loads at startup
- .NET application → ASP.NET bootstrapper: enables hosting startup
- Startup hook → Startup validation: validates startup
src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs - Startup hook → Managed loader: loads profiler
- Managed loader → Profiler load context: loads assemblies
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
src/OpenTelemetry.AutoInstrumentation/Plugins/PluginManager.cs - OpAmp management → Plugin manager: selects plugin
src/OpenTelemetry.AutoInstrumentation/OpAmp/OpAmpManager.cs - Profiler manager → Plugin manager: initializes plugins
src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs - Profiler manager → Canary thread: starts canary thread
src/OpenTelemetry.AutoInstrumentation/ContinuousProfiler/ContinuousProfilerManager.cs - Profiler manager → Runtime sampler: configures sampling
- Runtime sampler → Telemetry destination: exports samples