OpenTelemetry.Instrumentation.Runtime
1.13.0
Prefix Reserved
dotnet add package OpenTelemetry.Instrumentation.Runtime --version 1.13.0
NuGet\Install-Package OpenTelemetry.Instrumentation.Runtime -Version 1.13.0
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.13.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.13.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
paket add OpenTelemetry.Instrumentation.Runtime --version 1.13.0
#r "nuget: OpenTelemetry.Instrumentation.Runtime, 1.13.0"
#:package OpenTelemetry.Instrumentation.Runtime@1.13.0
#addin nuget:?package=OpenTelemetry.Instrumentation.Runtime&version=1.13.0
#tool nuget:?package=OpenTelemetry.Instrumentation.Runtime&version=1.13.0
Runtime Instrumentation for OpenTelemetry .NET
| Status | |
|---|---|
| Stability | Stable |
| Code Owners | @twenzel, @xiang17 |
This is an Instrumentation Library, which instruments .NET Runtime and collect telemetry about runtime behavior.
Steps to enable OpenTelemetry.Instrumentation.Runtime
Step 1: Install package
Add a reference to the
OpenTelemetry.Instrumentation.Runtime
package.
dotnet add package OpenTelemetry.Instrumentation.Runtime
Step 2: Enable runtime instrumentation
Runtime instrumentation should be enabled at application startup using the
AddRuntimeInstrumentation extension on MeterProviderBuilder:
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddRuntimeInstrumentation()
.AddPrometheusHttpListener()
.Build();
Refer to Program.cs for a complete demo.
Additionally, the above example snippet sets up the OpenTelemetry Prometheus Exporter
HttpListener as well, which requires adding the package
OpenTelemetry.Exporter.Prometheus.HttpListener
to the application.
Metrics
.NET 9 introduced built-in runtime metrics. As such, when applications target
.NET 9 or greater this package instead registers a Meter to receive the built-in
System.Runtime metrics. See the .NET Runtime metrics documentation
for details of the metric and attribute names for the built-in metrics.
GC related metrics
process.runtime.dotnet.gc.collections.count
Number of garbage collections that have occurred since process start.
.NET uses a generational GC which divides the heap into different generations numbered 0, 1, and 2. In each collection the GC decides which generation to search for reclaimable memory, then it searches that generation and all the lower ones. A GC collection that searches generations 0, 1, and 2 is called a "gen2" collection, searching generations 0 and 1 is a "gen1" collection and searching generation 0 only is a "gen0" collection. The gen0, gen1, and gen2 attribute values for this metric count respectively the number of gen0, gen1, and gen2 collections which have occurred since the process started.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{collections} |
ObservableCounter | Int64 |
generation | gen0, gen1, gen2 |
The metric can be computed using the GC.CollectionCount API:
count_gen0_collections = GC.CollectionCount(0) - GC.CollectionCount(1)count_gen1_collections = GC.CollectionCount(1) - GC.CollectionCount(2)count_gen2_collections = GC.CollectionCount(2)
GC.CollectionCount(X) counts the number of times objects in generation X have
been searched during any GC collection. Although it may sound similar, notice
this is not the same as the number of genX collections. For example objects in
generation 0 are searched during gen0, gen1, and gen2 collections so
GC.CollectionCount(0) = count_gen0_collections + count_gen1_collections + count_gen2_collections.
This is why the expressions above are not direct assignments.
process.runtime.dotnet.gc.objects.size
Count of bytes currently in use by objects in the GC heap that haven't been collected yet. Fragmentation and other GC committed memory pools are excluded. The value is available even before first garbage collection has occurred.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
bytes |
ObservableUpDownCounter | Int64 |
No Attributes | N/A |
The API used to retrieve the value is:
- GC.GetTotalMemory:
Retrieves the number of bytes currently thought to be allocated.
The value is an approximate count. API is called with
falseas a value of forceFullCollection parameter. Returns an instantaneous value at the time of observation.
process.runtime.dotnet.gc.allocations.size
Count of bytes allocated on the managed GC heap since the process start. .NET objects are allocated from this heap. Object allocations from unmanaged languages such as C/C++ do not use this heap.
This metric is only available when targeting .NET 6 or later.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
bytes |
ObservableCounter | Int64 |
No Attributes | N/A |
The API used to retrieve the value is:
- GC.GetTotalAllocatedBytes: Gets a count of the bytes allocated over the lifetime of the process. The returned value does not include any native allocations. The value is an approximate count.
process.runtime.dotnet.gc.committed_memory.size
The amount of committed virtual memory for the managed GC heap, as observed during the latest garbage collection. Committed virtual memory may be larger than the heap size because it includes both memory for storing existing objects (the heap size) and some extra memory that is ready to handle newly allocated objects in the future. The value will be unavailable until at least one garbage collection has occurred.
This metric is only available when targeting .NET 6 or later.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
bytes |
ObservableUpDownCounter | Int64 |
No Attributes | N/A |
The API used to retrieve the value is:
- GCMemoryInfo.TotalCommittedBytes: Gets the total committed bytes of the managed heap.
process.runtime.dotnet.gc.heap.size
The heap size (including fragmentation), as observed during the latest garbage collection. The value will be unavailable until at least one garbage collection has occurred.
This metric is only available when targeting .NET 6 or later.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
bytes |
ObservableUpDownCounter | Int64 |
generation | gen0, gen1, gen2, loh, poh |
The API used to retrieve the value is:
- GC.GetGCMemoryInfo().GenerationInfo/[i/].SizeAfterBytes:
Represents the size in bytes of a generation on exit of the GC reported in GCMemoryInfo.
Note that this API on .NET 6 has a bug.
For .NET 6, heap size is retrieved with an internal method
GC.GetGenerationSize, which is how the well-known EventCounters retrieve the values. See source code here.
process.runtime.dotnet.gc.heap.fragmentation.size
The heap fragmentation, as observed during the latest garbage collection. The value will be unavailable until at least one garbage collection has occurred.
This metric is only available when targeting .NET 7 or later.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
bytes |
ObservableUpDownCounter | Int64 |
generation | gen0, gen1, gen2, loh, poh |
The API used to retrieve the value is:
- GCGenerationInfo.FragmentationAfterBytes Property Gets the fragmentation in bytes on exit from the reported collection.
process.runtime.dotnet.gc.duration
The total amount of time paused in GC since the process start.
This metric is only available when targeting .NET 7 or later.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
ns |
ObservableCounter | Int64 |
No Attributes | N/A |
The API used to retrieve the value is:
- GC.GetTotalPauseDuration Gets the total amount of time paused in GC since the beginning of the process.
JIT Compiler related metrics
These metrics are only available when targeting .NET6 or later.
process.runtime.dotnet.jit.il_compiled.size
Count of bytes of intermediate language that have been compiled since the process start.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
bytes |
ObservableCounter | Int64 |
No Attributes | N/A |
process.runtime.dotnet.jit.methods_compiled.count
The number of times the JIT compiler compiled a method since the process start. The JIT compiler may be invoked multiple times for the same method to compile with different generic parameters, or because tiered compilation requested different optimization settings.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{methods} |
ObservableCounter | Int64 |
No Attributes | N/A |
process.runtime.dotnet.jit.compilation_time
The amount of time the JIT compiler has spent compiling methods since the process start.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
ns |
ObservableCounter | Int64 |
No Attributes | N/A |
The APIs used to retrieve the values are:
JitInfo.GetCompiledILBytes: Gets the number of bytes of intermediate language that have been compiled. The scope of this value is global. The same applies for other JIT related metrics.
JitInfo.GetCompiledMethodCount: Gets the number of methods that have been compiled.
JitInfo.GetCompilationTime: Gets the amount of time the JIT Compiler has spent compiling methods.
Threading related metrics
These metrics are only available when targeting .NET 6 or later.
process.runtime.dotnet.monitor.lock_contention.count
The number of times there was contention when trying to acquire a monitor lock since the process start. Monitor locks are commonly acquired by using the lock keyword in C#, or by calling Monitor.Enter() and Monitor.TryEnter().
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{contended_acquisitions} |
ObservableCounter | Int64 |
No Attributes | N/A |
process.runtime.dotnet.thread_pool.threads.count
The number of thread pool threads that currently exist.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{threads} |
ObservableUpDownCounter | Int32 |
No Attributes | N/A |
process.runtime.dotnet.thread_pool.completed_items.count
The number of work items that have been processed by the thread pool since the process start.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{items} |
ObservableCounter | Int64 |
No Attributes | N/A |
process.runtime.dotnet.thread_pool.queue.length
The number of work items that are currently queued to be processed by the thread pool.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{items} |
ObservableUpDownCounter | Int64 |
No Attributes | N/A |
process.runtime.dotnet.timer.count
The number of timer instances that are currently active. Timers can be created by many sources such as System.Threading.Timer, Task.Delay, or the timeout in a CancellationSource. An active timer is registered to tick at some point in the future and has not yet been canceled.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{timers} |
ObservableUpDownCounter | Int64 |
No Attributes | N/A |
The APIs used to retrieve the values are:
- Monitor.LockContentionCount: Gets the number of times there was contention when trying to take the monitor's lock.
- ThreadPool.ThreadCount: Gets the number of thread pool threads that currently exist.
- ThreadPool.CompletedWorkItemCount: Gets the number of work items that have been processed so far.
- ThreadPool.PendingWorkItemCount: Gets the number of work items that are currently queued to be processed.
- Timer.ActiveCount: Gets the number of timers that are currently active. An active timer is registered to tick at some point in the future, and has not yet been canceled.
Assemblies related metrics
process.runtime.dotnet.assemblies.count
The number of .NET assemblies that are currently loaded.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{assemblies} |
ObservableUpDownCounter | Int64 |
No Attributes | N/A |
The API used to retrieve the value is:
- AppDomain.GetAssemblies: Gets the number of the assemblies that have been loaded into the execution context of this application domain.
Exception counter metric
process.runtime.dotnet.exceptions.count
Count of exceptions that have been thrown in managed code, since the observation started. The value will be unavailable until an exception has been thrown after OpenTelemetry.Instrumentation.Runtime initialization.
The value is tracked by incrementing a counter whenever an AppDomain.FirstChanceException event occurs. The observation starts when the Runtime instrumentation library is initialized, so the value will be unavailable until an exception has been thrown after the initialization.
| Units | Instrument Type | Value Type | Attribute Key(s) | Attribute Values |
|---|---|---|---|---|
{exceptions} |
Counter | Int64 |
No Attributes | N/A |
Relevant API:
- AppDomain.FirstChanceException Occurs when an exception is thrown in managed code, before the runtime searches the call stack for an exception handler in the application domain.
Troubleshooting
If a metric is missing, review the list of metrics to see if the metric is available in the .NET version you are running.
Some GC related metrics are unavailable until at least one garbage collection has occurred.
References
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- OpenTelemetry.Api (>= 1.13.1 && < 2.0.0)
-
.NETStandard 2.0
- OpenTelemetry.Api (>= 1.13.1 && < 2.0.0)
-
net8.0
- OpenTelemetry.Api (>= 1.13.1 && < 2.0.0)
NuGet packages (208)
Showing the top 5 NuGet packages that depend on OpenTelemetry.Instrumentation.Runtime:
| Package | Downloads |
|---|---|
|
OpenTelemetry.AutoInstrumentation.Runtime.Managed
Managed components used by the OpenTelemetry.AutoInstrumentation project. |
|
|
Grafana.OpenTelemetry.Base
Minimal Grafana distribution of OpenTelemetry .NET |
|
|
I-Synergy.Framework.AspNetCore
I-Synergy Framework AspNetCore |
|
|
Genocs.Tracing
The tracing library to setup OpenTelemetry. |
|
|
Sportradar.OddsFeed.SDKCore
The SDK simplifying the consumption of Sportradar's Unified Odds feed. (.NET Standard 2.0) |
GitHub repositories (125)
Showing the top 20 popular GitHub repositories that depend on OpenTelemetry.Instrumentation.Runtime:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
ardalis/CleanArchitecture
Clean Architecture Solution Template: A proven Clean Architecture Template for ASP.NET Core 9
|
|
|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
|
|
JustArchiNET/ArchiSteamFarm
C# application with primary purpose of farming Steam cards from multiple accounts simultaneously.
|
|
|
dotnet/orleans
Cloud Native application framework for .NET
|
|
|
dotnet/eShop
A reference .NET application implementing an eCommerce site
|
|
|
dotnet/yarp
A toolkit for developing high-performance HTTP reverse proxy applications.
|
|
|
quartznet/quartznet
Quartz Enterprise Scheduler .NET
|
|
|
fullstackhero/dotnet-starter-kit
Production Grade Cloud-Ready .NET 9 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
|
|
|
dotnet/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
microsoft/fluentui-blazor
Microsoft Fluent UI Blazor components library. For use with ASP.NET Core Blazor applications
|
|
|
ravendb/ravendb
ACID Document Database
|
|
|
oskardudycz/EventSourcing.NetCore
Examples and Tutorials of Event Sourcing in .NET
|
|
|
open-telemetry/opentelemetry-dotnet
The OpenTelemetry .NET Client
|
|
|
microsoft/kiota
OpenAPI based HTTP Client code generator
|
|
|
thomhurst/TUnit
A modern, fast and flexible .NET testing framework
|
|
|
JasperFx/marten
.NET Transactional Document DB and Event Store on PostgreSQL
|
|
|
davidfowl/TodoApp
Todo application with ASP.NET Core Blazor WASM, Minimal APIs and Authentication
|
|
|
dotnet/extensions
This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
|
|
|
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.13.0 | 78,242 | 10/22/2025 |
| 1.12.0 | 11,540,627 | 5/5/2025 |
| 1.11.1 | 5,617,013 | 3/5/2025 |
| 1.11.0 | 2,800,998 | 1/27/2025 |
| 1.10.0 | 3,416,613 | 12/6/2024 |
| 1.9.0 | 24,427,607 | 6/18/2024 |
| 1.8.1 | 2,888,193 | 5/20/2024 |
| 1.8.0 | 5,807,040 | 4/5/2024 |
| 1.7.0 | 4,515,613 | 1/4/2024 |
| 1.5.1 | 5,156,708 | 9/7/2023 |
| 1.5.0 | 3,221,845 | 6/6/2023 |
| 1.4.0 | 65,406 | 6/5/2023 |
| 1.1.0-rc.2 | 1,952,067 | 2/28/2023 |
| 1.1.0-rc.1 | 277,076 | 2/14/2023 |
| 1.1.0-beta.4 | 300,969 | 2/2/2023 |
| 1.1.0-beta.3 | 113,491 | 1/11/2023 |
| 1.1.0-beta.2 | 112,121 | 12/13/2022 |
| 1.1.0-beta.1 | 244,014 | 11/23/2022 |
| 1.0.0 | 3,388,739 | 8/4/2022 |
| 1.0.0-rc.3 | 33,314 | 7/25/2022 |
| 1.0.0-rc.2 | 8,032 | 7/20/2022 |
| 1.0.0-rc.1 | 103,769 | 6/30/2022 |
| 1.0.0-beta.1 | 3,882 | 6/25/2022 |
| 0.2.0-alpha.1 | 41,031 | 6/11/2022 |
| 0.1.0-alpha.1 | 258,865 | 3/18/2022 |