Overview

You can export OTLP logs from your .NET application using the Datadog SDK (dd-trace-dotnet).

This feature works by intercepting logs from the built-in Microsoft.Extensions.Logging.ILogger library and exporting them as structured OTLP data.

You should not install the official OpenTelemetry SDK or any OTLP Exporter packages. The Datadog SDK provides this functionality. Installing both can lead to runtime conflicts and duplicate data.

Prerequisites

  • Datadog SDK: dd-trace-dotnet version 3.30.0 or later.
  • An OTLP-compatible destination: You must have a destination ready to receive OTLP data, such as the Datadog Agent or OpenTelemetry Collector.

Setup

  1. Install the Datadog SDK. Follow the installation steps for your runtime:
  2. Enable OTel logs export by setting the following environment variable:
    export DD_LOGS_OTEL_ENABLED=true
    

Examples

Standard logging

using Microsoft.Extensions.Logging;

// For a Console application, manually create a logger factory
using var loggerFactory = LoggerFactory.Create(builder =>
{
    // Additional builder options can be set, such as configuring the log level
    builder.SetMinimumLevel(LogLevel.Debug);
});

// Get a logger instance
var logger = loggerFactory.CreateLogger<Program>();

// This log will be exported via OTLP
logger.LogInformation("This is a standard log message.");

Trace and log correlation

This example shows how logs emitted within an active Datadog span are automatically correlated. If you are using the OTel Tracing API or built-in .NET Activity API to create spans, ensure OTel Tracing API support is enabled.

using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.Threading.Tasks;

// For a Console application, manually create a logger factory
using var loggerFactory = LoggerFactory.Create(builder =>
{
    // Additional builder options can set, such as setting the desired log level
    builder.SetMinimumLevel(LogLevel.Debug);
});

// Get a logger instance
var logger = loggerFactory.CreateLogger<Program>();

// Create an activity source (the built-in .NET API for generating traces)
var activitySource = new ActivitySource("MyService", "1.0.0");

// Start an activity (i.e. start a span)
using (var activity = activitySource.StartActivity("do.work"))
{
    // This log is automatically correlated with the 'do.work' span
    logger.LogInformation("This log is correlated to the active span.");
    await Task.Delay(TimeSpan.FromMilliseconds(100));
    logger.LogWarning("So is this one.");
}

Supported configuration

To enable this feature, you must set DD_LOGS_OTEL_ENABLED=true.

All OTLP exporter settings (such as endpoints, protocols, and timeouts), resource attributes, and batch processor settings are configured using a shared set of OpenTelemetry environment variables.

For a complete list of all shared OTLP environment variables, see OpenTelemetry Environment Variables Interoperability.

Migrate from other setups

Existing OTel setup

If you are already using the OpenTelemetry SDK with a manual OTLP exporter configuration, follow these steps to migrate:

  1. Add the Datadog SDK (dd-trace-dotnet) to your project and enable its instrumentation.
  2. Remove any code that manually configures the OtlpExporter for logs. The Datadog SDK handles this configuration automatically.
  3. Remove the OpenTelemetry and OpenTelemetry.Exporter.OpenTelemetryProtocol packages from your project’s dependencies.
  4. Set the DD_LOGS_OTEL_ENABLED=true environment variable.

Existing Datadog log injection

If you are using Datadog’s traditional log injection (where DD_LOGS_INJECTION=true adds trace context to text logs) and an Agent to tail log files:

  1. Set the DD_LOGS_OTEL_ENABLED=true environment variable.
  2. The Datadog SDK automatically disables the old log injection style (DD_LOGS_INJECTION) to prevent duplicate trace metadata in your logs. Trace correlation is handled by the structured OTLP payload.
  3. Ensure your Datadog Agent is configured to receive OTLP logs (version 7.48.0 or greater is required)
  4. Disable any file-based log collection for this service to avoid duplicate logs.

Troubleshooting

  • Ensure DD_LOGS_OTEL_ENABLED is set to true.

  • Verify that your OTLP destination is configured correctly to receive logs.

  • If you are sending data to the Datadog Agent, ensure OTLP ingestion is enabled. See Enabling OTLP Ingestion on the Datadog Agent for details.

  • Verify Datadog automatic instrumentation is active. This feature relies on Datadog’s automatic instrumentation to function. Ensure you have completed all setup steps to enable the .NET instrumentation hooks, as these are required to intercept the log data.

Further reading

Additional helpful documentation, links, and articles: