Troubleshooting

Learn how to troubleshoot OpenTelemetry .NET

You are viewing the English version of this page because it has not yet been fully translated. Interested in helping out? See Contributing.

All components shipped from the OpenTelemetry .NET repositories (opentelemetry-dotnet and opentelemetry-dotnet-contrib) report their internal state, such as dropped measurements, rejected configuration, and failed exports, through EventSource. The EventSource names all begin with OpenTelemetry-, for example OpenTelemetry-Sdk, OpenTelemetry-Api, and OpenTelemetry-Exporter-OpenTelemetryProtocol.

Self-diagnostics

You can capture these events with general-purpose tools such as PerfView or dotnet-trace, but the SDK also includes a self-diagnostics feature that subscribes to all of them and writes readable entries to rolling log files, to the console, or to both.

This page covers self-diagnostics as configured through SelfDiagnosticsOptions, available from version 1.20.0 of the OpenTelemetry package. Automatic binding from appsettings.json requires version 1.21.0 or later. For the complete reference, see the self-diagnostics documentation in the opentelemetry-dotnet repository.

Self-diagnostics is off by default. Nothing is written until you enable at least one output, called a sink. It isn’t supported in browser-based apps, such as Blazor WebAssembly.

If you use .NET automatic instrumentation, see its troubleshooting page first. The agent already includes SDK events in its own logs.

Enable with environment variables

Environment variables need no code changes. Set them before the process starts.

Write rolling log files to a directory of your choice. Setting the directory is enough to turn on file output, and the directory is created if it doesn’t exist:

export OTEL_DOTNET_SELF_DIAGNOSTICS_LOG_DIRECTORY=./otel-logs
$env:OTEL_DOTNET_SELF_DIAGNOSTICS_LOG_DIRECTORY = "C:\otel-logs"

Write rolling log files to the default log directory for your platform:

export OTEL_DOTNET_SELF_DIAGNOSTICS_SINKS=file

Write to the console, including Debug entries:

export OTEL_DOTNET_SELF_DIAGNOSTICS_SINKS=stdout,stderr
export OTEL_LOG_LEVEL=debug

Turn off output that the other environment variables enabled:

export OTEL_DOTNET_SELF_DIAGNOSTICS_SINKS=none

OTEL_LOG_LEVEL sets the level only. On its own, it produces no output.

Enable with appsettings.json

The SDK automatically reads the OpenTelemetry:SelfDiagnostics section from your application’s configuration. In an app that loads appsettings.json, add any of the following settings:

{
  "OpenTelemetry": {
    "SelfDiagnostics": {
      "MinimumLevel": "Debug",
      "LogDirectory": "/var/log/otel",
      "FileSizeLimitKilobytes": 4096,
      "MaxRetainedFiles": 5
    }
  }
}

If your configuration supports reloading, as appsettings.json does under the default .NET host, changes apply to the running process without a restart. This lets you switch to Debug during an incident and switch back afterward. Changes to environment variables always require a restart.

When a setting is defined in more than one place, the usual .NET configuration order applies: in the default host, environment variables override appsettings.json, and command-line arguments override both. Settings made in code override all of these.

Enable with code

Configure SelfDiagnosticsOptions through the standard .NET options pattern. Settings made in code take precedence over environment variables and configuration files.

using Microsoft.Extensions.Logging;
using OpenTelemetry.SelfDiagnostics;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

builder.Services.Configure<SelfDiagnosticsOptions>(options =>
{
    options.MinimumLevel = LogLevel.Debug;
    options.LogDirectory = SelfDiagnosticsOptions.GetDefaultLogDirectory()
        ?? "/var/log/otel";
});

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing.AddOtlpExporter());

When you build providers with Sdk.CreateTracerProviderBuilder() or the other Sdk.Create*ProviderBuilder() methods, make the same Configure call inside ConfigureServices. Self-diagnostics settings apply to the whole process, so configure them once.

Settings

OptionEnvironment variableDefaultDescription
MinimumLevelOTEL_LOG_LEVELWarningLowest level captured. See Log levels.
LogDirectoryOTEL_DOTNET_SELF_DIAGNOSTICS_LOG_DIRECTORYNot setDirectory for log files. Setting it turns on file output.
LogToStdoutOTEL_DOTNET_SELF_DIAGNOSTICS_SINKSfalseWrites entries to standard output.
LogToStderrOTEL_DOTNET_SELF_DIAGNOSTICS_SINKSfalseWrites entries to standard error. With both console options on, Error and above go here.
FileSizeLimitKilobytesNone10240 (10 MiB)Size at which a new log file is started. 0 or less means a single file with no size limit.
MaxRetainedFilesNone10Number of log files kept before the oldest is deleted. 0 or less keeps every file.
EnvironmentVariablesOTEL_DOTNET_SELF_DIAGNOSTICS_ENV_VARSKnownSafeValuesHow much of the OTEL_* environment is written to each log file. See Sensitive data.

OTEL_DOTNET_SELF_DIAGNOSTICS_SINKS takes a comma-separated list of file, stdout, stderr, and console (short for stdout,stderr), or none. If the list doesn’t include file, no files are written, even when a log directory is set. This lets a single service opt out when a deployment sets a log directory for every service.

Default log directory

With OTEL_DOTNET_SELF_DIAGNOSTICS_SINKS=file and no log directory set, the SDK writes to a per-user directory that doesn’t need elevated permissions:

PlatformDefault path
Windows%LOCALAPPDATA%\OpenTelemetry\dotnet-diagnostics
macOS~/Library/Logs/OpenTelemetry/dotnet-diagnostics
Linux / other Unix$XDG_STATE_HOME/opentelemetry/dotnet-diagnostics, or ~/.local/state/opentelemetry/dotnet-diagnostics if unset

In code, SelfDiagnosticsOptions.GetDefaultLogDirectory() returns the same path. If no per-user directory is available, file output stays off and the SDK writes a warning to standard error. Set an explicit directory in that case.

Log levels

OTEL_LOG_LEVEL accepts error, warn, info, debug, trace, and none, as well as .NET LogLevel names. Values are case-insensitive. The OpenTelemetry values map to LogLevel names, for example warn to Warning and info to Information.

The default is Warning, which differs from the OpenTelemetry specification default of Information. Lower levels produce much more output without usually adding value until you are investigating a problem. When you are, use Debug: it also logs each loaded assembly with its version, the quickest way to confirm which build is running.

Reading the output

File preamble

Each log file starts with a preamble that describes the process, so a single file is useful on its own. The following example is shortened:

=== OpenTelemetry .NET SDK self-diagnostics ===
SDK version          : 1.21.0
Runtime              : .NET 10.0.0
OS                   : Ubuntu 24.04.1 LTS
Process name         : MyCompany.MyService
Log directory        : /home/app/.local/state/opentelemetry/dotnet-diagnostics
...
Environment Variables (mode: KnownSafeValues):
OTEL_EXPORTER_OTLP_ENDPOINT_TRACES = [REDACTED]
OTEL_SERVICE_NAME = my-service
OTEL_TRACES_SAMPLER = parentbased_traceidratio
=== end preamble ===

The preamble lists every OTEL_* environment variable that is set, whether the SDK recognizes it or not. This makes misspelled names easy to spot. In the example, OTEL_EXPORTER_OTLP_ENDPOINT_TRACES should be OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.

If an environment variable has a value that can’t be parsed, a Configuration Warnings: block names the variable, the rejected value, and the accepted values.

Console output contains log entries only, without a preamble.

Log entries

Each entry has the following format:

[<timestamp>][<threadId>][<spanId>][<level>]  <message> {EventId} <traceparent>

For example:

[2026-08-06T09:14:31.4471190Z][000014][00f067][Error]       OpenTelemetry-Exporter-OpenTelemetryProtocol: Exporter failed send data to collector to https://otlp.example.com:4317 endpoint. Data will not be sent. Exception: System.Net.Http.HttpRequestException: No connection could be made because the target machine actively refused it. {EventId: 2, EventName: FailedToReachCollector} <00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01>

The message starts with the name of the EventSource that wrote it, which tells you which component to look at. When a span was active, the entry ends with its W3C traceparent, so you can match the entry to a trace.

Log files are named otel-dotnet-{pid}-{processName}-{processStartTime}-{index}.log. When a file reaches FileSizeLimitKilobytes, the SDK closes it and starts the next one. When the number of files exceeds MaxRetainedFiles, the SDK deletes the oldest. This limit applies to each run of a process separately. Files from other processes, or from earlier runs of the same application, are never deleted, so remove them yourself when you no longer need them.

Sensitive data

The file preamble includes the process’s OTEL_* environment variables, and nothing outside that namespace. The EnvironmentVariables option, or OTEL_DOTNET_SELF_DIAGNOSTICS_ENV_VARS, controls how much is shown:

ModeVariable valueShows
NonenoneNothing.
NamesnamesVariable names only.
KnownSafeValuesknownsafeNames, plus values the SDK knows are safe. Other values are [REDACTED]. The default.
AllValuesallAll values, unredacted.

Under KnownSafeValues, endpoints are reduced to their scheme, host, and port, and OTEL_RESOURCE_ATTRIBUTES keeps values only for well-known keys such as service.name.

Treat a file written with AllValues as a secret: it can contain API keys and authentication headers. Enable it for a single reproduction run, not permanently.

On Linux and macOS with .NET 10 or later, the SDK creates the log directory and files so that only the owning user can read them. Other accounts, such as a log shipper, must be granted access explicitly.

Collect logs for a bug report

A self-diagnostics log at the Debug level is one of the most useful things to include in a bug report. Run your reproduction with the following settings:

export OTEL_LOG_LEVEL=debug
export OTEL_DOTNET_SELF_DIAGNOSTICS_LOG_DIRECTORY=./otel-logs

Then open an issue and include:

  • The log files.
  • A minimal reproduction, if you have one.
  • What you expected to happen and what happened instead.
  • The approximate time of the failure, to help find the related entries.

Migrate from OTEL_DIAGNOSTICS.json

Earlier versions of the SDK enabled self-diagnostics through an OTEL_DIAGNOSTICS.json file in the process’s working directory. That file still works but is deprecated and will be removed in a future major version.

Starting with version 1.21.0, the file uses the same mechanism described on this page. As a result:

  • Output goes to rolling otel-dotnet-*.log files instead of a single circular {executable}.{pid}.log file.
  • FormatMessage is ignored. Messages are always formatted.
  • If self-diagnostics output is configured any other way, through environment variables, appsettings.json, or code, the file is ignored.

To migrate, delete the file and move its settings to the OpenTelemetry:SelfDiagnostics section or to environment variables:

OTEL_DIAGNOSTICS.jsonReplacement
LogDirectoryLogDirectory
LogLevelMinimumLevel. Informational becomes Information and Verbose becomes Debug.
FileSizeFileSizeLimitKilobytes and MaxRetainedFiles. The old size was the total for all files.