Repository navigation
Conversation
After UseSentry, ClearProviders() removes Sentry's logger providers, and without a later Logging.AddSentry() nothing says that ILogger entries no longer reach Sentry. The generic host now checks while the host is built, in the hook that starts the SDK, and ASP.NET Core checks in app.UseSentry() when the host starts. If the host's providers are gone and no Sentry logger provider is registered, the SDK logs a warning through its diagnostic logger, so it shows with Debug = true. The check reads the service collection first, so apps that keep the registrations, such as those that replace the logger factory with Serilog, never have providers created by it. HostLoggerProviders now keeps the service collection it was added to, which lets app.UseSentry() run the check and spares Logging.AddSentry() capturing it. Refs #5755 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## fix/logging-addsentry-after-clearproviders #5789 +/- ##
===========================================================================
Coverage 76.22% 76.22%
===========================================================================
Files 528 528
Lines 19307 19318 +11
Branches 3734 3737 +3
===========================================================================
+ Hits 14716 14725 +9
Misses 3734 3734
- Partials 857 859 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ction The legacy WebHostBuilder copies the service collection before Startup.ConfigureServices, so checking the collection UseSentry used brought back NullLoggerProviders there. Only the warning uses it now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generic host now leaves the check to the other host integration, as it already does for the logger providers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IHostBuilder apps use ConfigureLogging(), so the warning now names the logging builder and gives builder.Logging.AddSentry() as an example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
With
Debug = true, the SDK now warns when the app removed the logger providers thatUseSentryadded, for example withClearProviders(), and didn't add them back withbuilder.Logging.AddSentry(). Until nowLogErrorcalls silently stopped reaching Sentry.The generic host checks during
Build(), in the hook from #5772, so it also covers hosts that are never started. ASP.NET Core and Google Cloud Functions check inapp.UseSentry()at startup. With bothUseSentrycalls, only ASP.NET Core checks.The check reads the service collection first and stops if the host's providers are still there, so apps that replace the logger factory, as
AddSerilog()does, get no providers created. Otherwise it looks for any Sentry logger provider, which coversLogging.AddSentry()after the clear.Limitations:
Debug = true, so NLog, Serilog and log4net apps that clear on purpose don't see it by default.ILogger, so an app with no providers left won't see it.WebHostBuilder, a clear insideStartup.ConfigureServicesisn't detected, because that builder copies the service collection first.Stacked on #5776.
Refs #5755