Skip to content

feat: Serilog sink no longer initializes the SDK - #5573

Draft
jamescrosswell wants to merge 4 commits into
version7from
feat/no-init-from-logging-5245
Draft

jamescrosswell wants to merge 4 commits into
version7from
feat/no-init-from-logging-5245

Conversation

@jamescrosswell

Copy link
Copy Markdown
Collaborator

The Serilog portion of #5245, following the design in this comment. The Sentry sink for Serilog now only configures the sink; Sentry has to be initialized separately via SentrySdk.Init, UseSentry, etc.

Part of #5245

Breaking changes

  • SentrySerilogOptions no longer derives from SentryOptions. It carries only sink settings: MinimumEventLevel, MinimumBreadcrumbLevel, FormatProvider, TextFormatter, RestrictedToMinimumLevel, LevelSwitch. Anything else (Dsn, Release, SampleRate, …) belongs on the options used to initialize Sentry.
  • SentrySerilogOptions.InitializeSdk is removed.
  • The WriteTo.Sentry(string dsn, …) overload is removed. Serilog.Settings.Configuration users passing dsn (or any other core SDK setting) in WriteTo args will no longer bind to a Sentry sink method.
  • ApplySerilogScopeToEvents() is renamed UseSerilog(), to match UseOpenTelemetry(). It returns void like its siblings and is now idempotent.

Before:

Log.Logger = new LoggerConfiguration()
    .WriteTo.Sentry(o =>
    {
        o.Dsn = "...";
        o.MinimumEventLevel = LogEventLevel.Error;
    })
    .CreateLogger();

After:

using var _ = SentrySdk.Init(o =>
{
    o.Dsn = "...";
    o.UseSerilog();
});

Log.Logger = new LoggerConfiguration()
    .WriteTo.Sentry(o => o.MinimumEventLevel = LogEventLevel.Error)
    .CreateLogger();

Notes for review

  • UseSerilog() registers the processor that copies Serilog LogContext properties onto events. It has to live on the SentryOptions used for init, because it enriches every event, not only ones the sink creates. To keep that discoverable, the sink logs a one-time diagnostic warning when it's missing (only visible with Debug = true).
  • The old WriteTo.Sentry(o => …) overload initialized the SDK but never registered that processor — only the dsn parameter overload did. That's why IntegrationTests.Simple snapshots gain inventory/MyTaskId tags: the test now calls UseSerilog(), and the processor is actually running.
  • The sink no longer implements IDisposable. It never owned the hub, so Log.CloseAndFlush() no longer disposes the SDK; disposing the handle from SentrySdk.Init does that.
  • SerilogAspNetSentrySdkTestFixture was initializing the SDK twice (once via WriteTo.Sentry(ValidDsn), then again via UseSentry); it now only initializes via UseSentry.
  • ApiApprovalTests.Run.Net4_8.verified.txt can't regenerate on macOS; it was byte-identical to the DotNet10_0 snapshot before this change, so it's a copy of the regenerated one.

NLog, log4net and Microsoft.Extensions.Logging follow separately. The generic host replacement for builder.Logging.AddSentry(dsn) is tracked in #5572.

🤖 Generated with Claude Code

The Sentry sink for Serilog now only configures the sink. Sentry must be
initialized separately (SentrySdk.Init, UseSentry, etc).

- SentrySerilogOptions no longer derives from SentryOptions and only
  carries sink settings; InitializeSdk is removed
- Remove the WriteTo.Sentry(string dsn, ...) overload
- Rename ApplySerilogScopeToEvents() to UseSerilog(), make it idempotent
- The sink logs a one-time diagnostic warning when UseSerilog() was not
  called on the options used to initialize Sentry

Part of #5245

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jamescrosswell jamescrosswell added Breaking Change Binary/Source/Behavioral Breaking Changes. Serilog labels Sep 14, 2026
@github-actions github-actions Bot added the public API Additions/modifications to, or removals from, the public API surface area. label Sep 14, 2026
@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (version7@21f45f0). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/Sentry.Serilog/SentrySink.cs 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             version7    #5573   +/-   ##
===========================================
  Coverage            ?   74.64%           
===========================================
  Files               ?      515           
  Lines               ?    18824           
  Branches            ?     3665           
===========================================
  Hits                ?    14051           
  Misses              ?     3894           
  Partials            ?      879           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Change Binary/Source/Behavioral Breaking Changes. public API Additions/modifications to, or removals from, the public API surface area. Serilog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants