feat: Serilog sink no longer initializes the SDK - #5573
Draft
jamescrosswell wants to merge 4 commits into
Draft
jamescrosswell wants to merge 4 commits into
jamescrosswell wants to merge 4 commits into
Conversation
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>
…into feat/no-init-from-logging-5245
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SentrySerilogOptionsno longer derives fromSentryOptions. 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.InitializeSdkis removed.WriteTo.Sentry(string dsn, …)overload is removed.Serilog.Settings.Configurationusers passingdsn(or any other core SDK setting) inWriteToargs will no longer bind to aSentrysink method.ApplySerilogScopeToEvents()is renamedUseSerilog(), to matchUseOpenTelemetry(). It returnsvoidlike its siblings and is now idempotent.Before:
After:
Notes for review
UseSerilog()registers the processor that copies SerilogLogContextproperties onto events. It has to live on theSentryOptionsused 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 withDebug = true).WriteTo.Sentry(o => …)overload initialized the SDK but never registered that processor — only thedsnparameter overload did. That's whyIntegrationTests.Simplesnapshots gaininventory/MyTaskIdtags: the test now callsUseSerilog(), and the processor is actually running.IDisposable. It never owned the hub, soLog.CloseAndFlush()no longer disposes the SDK; disposing the handle fromSentrySdk.Initdoes that.SerilogAspNetSentrySdkTestFixturewas initializing the SDK twice (once viaWriteTo.Sentry(ValidDsn), then again viaUseSentry); it now only initializes viaUseSentry.ApiApprovalTests.Run.Net4_8.verified.txtcan't regenerate on macOS; it was byte-identical to theDotNet10_0snapshot 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