getsentry / getsentry/sentry-dotnet

Add support to export logs directly via OTLP

Open
#5,358 1 comment 1 reaction 0 assignees View on GitHub
.NET Feature Logs OpenTelemetry
Dominant language
C#
Stars
770
Forks
248
Avg merge
2d 22h
Merged PRs (30d)
51

Description

### Description

Whilst we can't support all of the variants suggested below, we should be able to support:
```cs
.WithLogging(logging =>logging.AddSentryExporter())
```

Sentry already [documents an OTLP endpoint for logs](https://docs.sentry.io/concepts/otlp/direct/logs/) so with a bit of fiddling we should be able to build an extension method that would work with the OTEL logging builder.

[Original feedback](https://github.com/getsentry/sentry-dotnet/issues/5350#issuecomment-4901465105) from @yasmoradi:

```cs
services.AddLogging(loggingBuilder =>
{
loggingBuilder.ConfigureLoggers(configuration);

loggingBuilder.AddOpenTelemetry(options =>
{
options.IncludeScopes = true;
options.IncludeFormattedMessage = true;
configuration.Bind("Logging:OpenTelemetry", options);
});
});

var openTelemetry = services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddConsoleExporter(); // Console
metrics.AddSentryExporter(); // ⚠️Not supported
})
.WithTracing(tracing=>
{
tracing.AddConsoleExporter(); // Console
tracing.AddSentryExporter(); // ✅Supported
)
.WithLogging(logging =>
{
logging.AddConsoleExporter(); // Console
logging.AddSentryExporter(); //⚠️Not supported
})
.ConfigureResource(resource =>
{
resource.AddAttributes([new("service.name", Application.ProductName!)]);
});

openTelemetry.UseOtlpExporter(); // Aspire Dashboard

openTelemetry.UseAzureMonitorExporter(); // Azure Application Insights

openTelemetry.UseSentryExporter(); //⚠️ Not supported
```

Also worth considering the extensions on the `OpenTelemetryBuilder` in that case - these are likely/potentially shortcuts for adding exporters to logging and tracing in a single method call.

> [!NOTE]
> At thist stage, we don't export Sentry metrics to OTEL - that would be blocked by:
> - https://github.com/getsentry/sentry/issues/111136

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing AddSentryExporter support for OpenTelemetry tracing and the OpenTelemetry logging builder entry point. Determine how the Sentry OTLP logs endpoint should integrate with logging.AddSentryExporter() and the OpenTelemetryBuilder extensions. Done means the logging exporter works with the documented builder usage and is covered by the project's relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
observability
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.