feat: NLog target no longer initializes the SDK - #5585
Draft
jamescrosswell wants to merge 3 commits into
Draft
jamescrosswell wants to merge 3 commits into
jamescrosswell wants to merge 3 commits into
Conversation
The Sentry target for NLog now only configures the target. Sentry must be initialized separately (SentrySdk.Init, UseSentry, etc). - SentryNLogOptions no longer derives from SentryOptions and only carries target settings; FlushTimeout moves onto it directly - Remove InitializeSdk, Dsn/DsnLayout, Release/ReleaseLayout, Environment/EnvironmentLayout and ShutdownTimeoutSeconds. Events take release and environment from the SDK options - Collapse the AddSentry overloads into AddSentry(optionsConfig, targetName); the dsn overloads are removed - The target no longer routes SDK diagnostics to NLog's InternalLogger Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/no-init-from-logging-5245 #5585 +/- ##
==================================================================
- Coverage 74.67% 74.58% -0.09%
==================================================================
Files 515 514 -1
Lines 18834 18745 -89
Branches 3667 3646 -21
==================================================================
- Hits 14064 13981 -83
+ Misses 3893 3891 -2
+ Partials 877 873 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jamescrosswell
commented
Sep 17, 2026
jamescrosswell
commented
Sep 17, 2026
jamescrosswell
commented
Sep 17, 2026
jamescrosswell
commented
Sep 17, 2026
Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
Remove SentryTarget.FlushTimeoutSeconds and SentryNLogOptions.FlushTimeout. When NLog flushes the target, the hub is now flushed with the FlushTimeout from the options used to initialize Sentry, since the target no longer owns the SDK. Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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 NLog portion of #5245, stacked on #5573 (Serilog) and following the same design. The Sentry target for NLog now only configures the target; Sentry has to be initialized separately via
SentrySdk.Init,UseSentry, etc.Part of #5245
Breaking changes
SentryNLogOptionsno longer derives fromSentryOptions. It carries only target settings.SentryNLogOptionsandSentryTarget:InitializeSdk,Dsn/DsnLayout,Release/ReleaseLayout,Environment/EnvironmentLayout,ShutdownTimeoutSeconds,FlushTimeout/FlushTimeoutSeconds. Events now take release and environment from the options used to initialize Sentry, rather than per-target overrides.SentryOptions.FlushTimeoutfrom the options used to initialize Sentry. That defaults to 2 seconds; the NLog target previously defaulted to 15. SetFlushTimeoutinSentrySdk.Initto keep the old wait.NLog.config, thedsn,release,environment,initializeSdk,shutdownTimeoutSecondsandflushTimeoutSecondstarget attributes are gone, as is setting arbitrarySentryOptionsproperties through the<options>element (e.g.<options attachStacktrace="true" />). WiththrowConfigExceptions="true"these now fail config loading.AddSentryoverloads collapse into one:AddSentry(Action<SentryNLogOptions>? optionsConfig = null, string targetName = "sentry").InternalLogger. Previously, enabling NLog internal logging at any level made the target set the SDK'sDiagnosticLoggerto write there and turn onDebug. To see SDK diagnostics, setDebug(and optionallyDiagnosticLogger) on the options used to initialize Sentry.Before:
After:
Notes for review
targetNamemoved to the last parameter on purpose. Keeping a(string targetName, Action<SentryNLogOptions>)overload would let existingAddSentry(dsn, o => …)calls keep compiling, with the DSN silently used as the target name and Sentry never initialized. WithtargetNamelast, every old DSN-taking call fails to compile instead.LogManager.Flush(), onLogManager.Shutdown()(which NLog also calls itself on process exit, sinceAutoShutdownis on by default), when the configuration is replaced (includingautoReload), and from wrappers such asAutoFlushTargetWrapper. NLog doesn't pass its own timeout down to targets, so the target has to pick one, and the SDK-wide flush it triggers covers events from every integration, not only NLog. Previously the target owned the SDK, so this flush on shutdown was how an NLog-only app got its last events sent. Now the app initializes and disposes Sentry itself, and disposing the handle fromSentrySdk.Initflushes on its own. The NLog-triggered flush is still useful for explicit flushes, config reloads and auto-flush wrappers, but it's an SDK operation, so it uses the SDK's setting instead of a target-level duplicate.NLogDiagnosticLoggeris deleted. Routing SDK diagnostics toInternalLoggerwas SDK configuration applied at target initialization. The target's options are no longerSentryOptions, and applying it to the live hub options instead would mean the target silently reconfiguring (and switching onDebugfor) an SDK the user initialized. With no remaining callers, the internal class was dead code.UseNLog(): tags, user and properties are all applied by the target to the events it creates, and the SDK name is stamped per event.IntegrationTests.Simplesnapshot changes are only a stack-frame line/column shift from restructuring the test.Net4_8got the same edit by hand, andApiApprovalTests.Run.Net4_8is a copy of the regeneratedDotNet10_0one, which it matched byte-for-byte beforehand. Neither can regenerate on macOS.usingbefore verifying.🤖 Generated with Claude Code