OpenTelemetry 1.18.0

OpenTelemetry .NET SDK

NuGet NuGet

Table of Contents

Installation

dotnet add package OpenTelemetry

Introduction

OpenTelemetry SDK is a reference implementation of the OpenTelemetry API. It implements the Logging API, Metrics API, Tracing API, Resource API, and the Context API. Once a valid SDK is installed and configured all the OpenTelemetry API methods, which were no-ops without an SDK, will start emitting telemetry. This SDK also ships with ILogger integration to automatically capture and enrich logs emitted using Microsoft.Extensions.Logging.

The SDK deals with concerns such as sampling, processing pipelines (exporting telemetry to a particular backend, etc.), metrics aggregation, and other concerns outlined in the OpenTelemetry Specification. In most cases, users indirectly install and enable the SDK when they install an exporter.

To learn how to set up and configure the OpenTelemetry SDK see: Getting started. For additional details about initialization patterns see: Initialize the SDK.

Self-Observability (Experimental)

The SDK can emit metrics about its own internal operations, enabling operators to monitor the health of the telemetry pipeline itself (e.g., detecting dropped telemetry due to queue overflow).

[!NOTE] Self-observability metrics are experimental and may change in future releases. They are emitted under the meter name otel.sdk.experimental.

Opt-in

Self-observability metrics are only emitted when explicitly enabled by subscribing to the otel.sdk.experimental meter. There is no performance cost unless enabled.

var meterProvider = Sdk.CreateMeterProviderBuilder()
    .AddMeter("otel.sdk.experimental")
    .AddOtlpExporter() // or any exporter
    .Build();

Available Metrics

These metrics follow the OpenTelemetry SDK Self-Observability Semantic Conventions.

Metric Name Instrument Unit Description
otel.sdk.processor.log.processed Counter {log_record} Number of log records processed by the SDK, tagged with outcome.
otel.sdk.processor.span.processed Counter {span} Number of spans processed by the SDK, tagged with outcome.

Attributes

Attribute Description Example
otel.component.type The processor type. batching_log_processor, simple_log_processor, batching_span_processor, simple_span_processor
otel.component.name Unique instance identifier. batching_log_processor/0, batching_span_processor/0
error.type Present only on failure. queue_full, already_shutdown

When error.type is absent, the item was successfully accepted by the processor. This means the processor completed its intended handling of the item; for the Simple and Batching processors it is recorded when the item is handed to the exporter, and it does not indicate that the export itself succeeded or that the item reached the backend. Export failures are not reflected in this metric. When present:

  • queue_full - The batch processor's internal queue was full; the item was dropped.
  • already_shutdown - The processor had already been shut down; the item was lost.

[!NOTE] Sampling affects otel.sdk.processor.span.processed as follows. Spans dropped by the sampler (DROP) are not counted, because span processors are not invoked for them at all. Spans sampled as RECORD_ONLY are counted as successfully processed because they do reach the processor and by design are never handed to an exporter.

Troubleshooting

All the components shipped from this repo uses EventSource for its internal logging. The name of the EventSource used by OpenTelemetry SDK is "OpenTelemetry-Sdk". To know the EventSource names used by other components, refer to the individual readme files.

While it is possible to view these logs using tools such as PerfView, dotnet-trace etc., this SDK also ships a self-diagnostics feature, which helps with troubleshooting.

Self-diagnostics

OpenTelemetry SDK ships with built-in self-diagnostics feature. This feature, when enabled, will listen to internal logs generated by all OpenTelemetry components (i.e EventSources whose name starts with "OpenTelemetry-") and writes them to a log file.

The self-diagnostics feature can be enabled/changed/disabled while the process is running (without restarting the process). The SDK will attempt to read the configuration file every 10 seconds in non-exclusive read-only mode. The SDK will create or overwrite a file with new logs according to the configuration. This file will not exceed the configured max size and will be overwritten in a circular way.

To enable self-diagnostics, go to the current working directory of your process and create a configuration file named OTEL_DIAGNOSTICS.json with the following content:

{
    "LogDirectory": ".",
    "FileSize": 32768,
    "LogLevel": "Warning",
    "FormatMessage": "true"
}

To disable self-diagnostics, delete the above file.

Tip: In most cases, you could just drop the file along your application. On Windows, you can use Process Explorer, double click on the process to pop up Properties dialog and find "Current directory" in "Image" tab. Internally, it looks for the configuration file located in GetCurrentDirectory, and then AppContext.BaseDirectory. You can also find the exact directory by calling these methods from your code.

Configuration Parameters

  1. LogDirectory is the directory where the output log file will be stored. It can be an absolute path or a relative path to the current directory.

  2. FileSize is a positive integer, which specifies the log file size in KiB. This value must be within range [1024, 131072] (1 MiB /<= size /<= 128 MiB), or it will be rounded to the closest upper or lower limit. The log file will never exceed this configured size, and will be overwritten in a circular way.

  3. LogLevel is the lowest level of the events to be captured. It has to be one of the values of the EventLevel enum. The level signifies the severity of an event. Lower severity levels encompass higher severity levels. For example, Warning includes the Error and Critical levels.

  4. FormatMessage is a boolean value that controls whether log messages should be formatted by replacing placeholders ({0}, {1}, etc.) with their actual parameter values. When set to false (default), messages are logged with unformatted placeholders followed by raw parameter values. When set to true, placeholders are replaced with formatted parameter values for improved readability.

    Example with FormatMessage: false (default):

    2025-07-24T01:45:04.1020880Z:Measurements from Instrument '{0}', Meter '{1}' will be ignored. Reason: '{2}'. Suggested action: '{3}'{dotnet.gc.collections}{System.Runtime}{Instrument belongs to a Meter not subscribed by the provider.}{Use AddMeter to add the Meter to the provider.}
    

    Example with FormatMessage: true:

    2025-07-24T01:44:44.7059260Z:Measurements from Instrument 'dotnet.gc.collections', Meter 'System.Runtime' will be ignored. Reason: 'Instrument belongs to a Meter not subscribed by the provider.'. Suggested action: 'Use AddMeter to add the Meter to the provider.'
    

Remarks

A FileSize-KiB log file named as ExecutableName.ProcessId.log (e.g. foobar.exe.12345.log) will be generated at the specified directory LogDirectory, into which logs are written to.

If the SDK fails to parse the LogDirectory, FileSize or LogLevel fields as the specified format, the configuration file will be treated as invalid and no log file would be generated.

When the LogDirectory or FileSize is found to be changed, the SDK will create or overwrite a file with new logs according to the new configuration. The configuration file has to be no more than 4 KiB. In case the file is larger than 4 KiB, only the first 4 KiB of content will be read.

The log file might not be a proper text file format to achieve the goal of having minimal overhead and bounded resource usage: it may have trailing NULs if log text is less than configured size; once write operation reaches the end, it will start from beginning and overwrite existing text.

References

Showing the top 20 packages that depend on OpenTelemetry.

Packages Downloads
Azure.Monitor.OpenTelemetry.Exporter
An OpenTelemetry .NET exporter that exports to Azure Monitor
68
Azure.Monitor.OpenTelemetry.Exporter
An OpenTelemetry .NET exporter that exports to Azure Monitor
70
Azure.Monitor.OpenTelemetry.Exporter
An OpenTelemetry .NET exporter that exports to Azure Monitor
76
Azure.Monitor.OpenTelemetry.Exporter
An OpenTelemetry .NET exporter that exports to Azure Monitor
78
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions
109
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions
116
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions
119
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions
122
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions
128
OpenTelemetry.Extensions.Hosting
Contains extensions to start OpenTelemetry in applications using Microsoft.Extensions.Hosting
70
OpenTelemetry.Instrumentation.AspNetCore
ASP.NET Core instrumentation for OpenTelemetry .NET
67
OpenTelemetry.Instrumentation.AspNetCore
ASP.NET Core instrumentation for OpenTelemetry .NET
68
OpenTelemetry.Instrumentation.AspNetCore
ASP.NET Core instrumentation for OpenTelemetry .NET
69
OpenTelemetry.Instrumentation.AspNetCore
ASP.NET Core instrumentation for OpenTelemetry .NET
71
OpenTelemetry.Instrumentation.Http
Http instrumentation for OpenTelemetry .NET
65
OpenTelemetry.Instrumentation.Http
Http instrumentation for OpenTelemetry .NET
66
OpenTelemetry.Instrumentation.Http
Http instrumentation for OpenTelemetry .NET
68
OpenTelemetry.Instrumentation.SqlClient
SqlClient instrumentation for OpenTelemetry .NET
83
OpenTelemetry.Resources.Azure
OpenTelemetry Resource Detectors for Azure cloud environments.
66

For highlights and announcements see: https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0/RELEASENOTES.md. For detailed changes see: https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0/src/OpenTelemetry/CHANGELOG.md.

.NET 10.0

.NET Standard 2.1

.NET Standard 2.0

.NET 9.0

.NET 8.0

.NET Framework 4.6.2

Version Downloads Last updated
1.18.0 6 08/21/2026
1.18.0-rc.1 5 08/21/2026
1.17.0 19 07/17/2026
1.17.0-rc.1 19 07/18/2026
1.16.0 23 06/10/2026
1.16.0-rc.1 24 06/10/2026
1.15.3 42 04/21/2026
1.15.2 35 04/08/2026
1.15.1 44 03/27/2026
1.15.0 45 01/21/2026
1.14.0 102 11/13/2025
1.14.0-rc.1 104 10/21/2025
1.13.1 78 10/10/2025
1.13.0 84 10/02/2025
1.12.0 104 05/02/2025
1.11.2 119 04/01/2025
1.9.0 120 04/01/2025
1.9.0-rc.1 112 04/01/2025
1.9.0-alpha.1 128 04/01/2025
1.8.1 113 04/01/2025
1.8.0 129 04/01/2025
1.8.0-rc.1 118 04/01/2025
1.8.0-beta.1 141 04/01/2025
1.7.0 112 04/01/2025
1.7.0-rc.1 133 04/01/2025
1.7.0-alpha.1 117 04/01/2025
1.6.0 131 04/01/2025
1.6.0-rc.1 108 04/01/2025
1.6.0-alpha.1 115 04/01/2025
1.5.1 140 04/01/2025
1.5.0 114 04/01/2025
1.5.0-rc.1 122 04/01/2025
1.5.0-alpha.2 112 04/01/2025
1.5.0-alpha.1 108 04/01/2025
1.4.0 119 04/01/2025
1.4.0-rc.4 108 04/01/2025
1.4.0-rc.3 135 04/01/2025
1.4.0-rc.2 115 04/01/2025
1.4.0-rc.1 110 04/01/2025
1.4.0-beta.3 135 03/31/2025
1.4.0-beta.2 124 04/01/2025
1.4.0-beta.1 113 04/01/2025
1.4.0-alpha.2 134 04/01/2025
1.4.0-alpha.1 114 04/01/2025
1.3.2 128 04/01/2025
1.3.1 115 04/01/2025
1.3.0 122 04/01/2025
1.3.0-rc.2 129 04/01/2025
1.3.0-beta.2 117 04/01/2025
1.3.0-beta.1 147 04/01/2025
1.2.0 128 04/01/2025
1.2.0-rc5 107 04/01/2025
1.2.0-rc4 126 04/01/2025
1.2.0-rc3 118 04/01/2025
1.2.0-rc2 123 04/01/2025
1.2.0-rc1 110 04/01/2025
1.2.0-beta2.1 112 04/01/2025
1.2.0-beta1 129 04/01/2025
1.2.0-alpha4 119 04/01/2025
1.2.0-alpha3 114 04/01/2025
1.2.0-alpha2 105 04/01/2025
1.2.0-alpha1 128 04/01/2025
1.1.0 132 04/01/2025
1.1.0-rc1 129 04/01/2025
1.1.0-beta4 135 04/01/2025
1.1.0-beta3 120 04/01/2025
1.1.0-beta2 117 04/01/2025
1.1.0-beta1 108 04/01/2025
1.0.1 151 04/01/2025
1.0.0-rc4 120 04/01/2025
1.0.0-rc3 122 04/01/2025
1.0.0-rc2 133 04/01/2025
1.0.0-rc1.1 132 04/01/2025
0.8.0-beta.1 133 04/01/2025
0.7.0-beta.1 127 04/01/2025
0.6.0-beta.1 116 04/06/2025
0.5.0-beta.2 107 04/01/2025
0.4.0-beta.2 144 04/01/2025
0.3.0-beta.1 136 04/01/2025
0.2.0-alpha.275 112 04/01/2025
0.2.0-alpha.220 103 04/01/2025
0.2.0-alpha.179 117 04/01/2025
0.2.0-alpha.100 115 04/01/2025
0.2.0-alpha.40 128 04/01/2025
0.2.0-alpha.5 122 04/01/2025