Repository navigation
feat(mel)!: the Microsoft.Extensions.Logging integration no longer initializes the SDK - #5595
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
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>
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>
The Sentry appender for log4net now only sends log events to Sentry. Sentry must be initialized separately (SentrySdk.Init, UseSentry, etc). - Remove SentryAppender.Dsn and the lazy SDK initialization on first append - Remove SentryAppender.Environment; events take the environment from the options used to initialize Sentry - Remove the OnClose override, which only disposed the SDK the appender had initialized Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…the SDK Completes the logging-integration part of #5245. The MEL integration now only wires up the logger providers; Sentry has to be initialized separately. Unlike Serilog, NLog and log4net, SentryLoggingOptions keeps deriving from SentryOptions, because SentryAspNetCoreOptions, SentryMauiOptions and SentryBlazorOptions derive from it and those integrations do initialize the SDK. InitializeSdk therefore stays as internal plumbing, now defaulting to false and opted into by the framework integrations that own it. 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-log4net-5245 #5595 +/- ##
==========================================================================
+ Coverage 74.96% 75.07% +0.10%
==========================================================================
Files 515 519 +4
Lines 18832 18872 +40
Branches 3655 3658 +3
==========================================================================
+ Hits 14118 14168 +50
+ Misses 3855 3840 -15
- Partials 859 864 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… framework options SentryLoggingOptions no longer derives from SentryOptions, matching the Serilog and NLog options: it carries only the log levels and entry filters. SentryAspNetCoreOptions, SentryMauiOptions and SentryBlazorOptions now derive from a new abstract SentryHostOptions, which keeps MinimumEventLevel, MinimumBreadcrumbLevel, ConfigureScope and AddLogEntryFilter by passing them through to an inner SentryLoggingOptions, so existing UseSentry callbacks and configuration keys keep working. InitializeSdk is removed. Integrations that initialise through DI call AddSentry<TOptions>; MAUI, which initialises in SentryMauiInitializer, uses an internal non-initialising overload. ConfigureScope callbacks are applied right after the SDK is initialised instead of when the MEL logger provider is built. Also fixes Blazor WebAssembly's logger ignoring the logging settings from UseSentry (it was built from a separate, default IOptions<SentryLoggingOptions>), and structured logs from plain MEL taking default attributes from options the SDK was not initialised with. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Some background for reviewers on why this PR splits the options class. Initialising SentryGenerally Sentry's integrations fall into two camps:
As a rule, we provide For people not using any specific platform, they can instead initialise Sentry by calling One of the features that Sentry supports is logging and it's such a common feature that we decided it might be convenient if people could initialise both logging and the Sentry SDK in a single call (e.g. when using Sentry in a console application, where you also have logging). In theory that was fine. In practice it's caused huge headaches (see #5245). If you use Serilog and ASP.NET Core, you have to tell Serilog "send logs, but don't initialise — ASP.NET Core already did that". Users constantly get this wrong, and so did we. So in v7, we're removing the ability to initialise the SDK from the logging integrations. These will now be initialised the same as all the other 'feature' integrations we do. The old wayIn version 6 the options classes look something like this: classDiagram
SentryOptions <|-- SentryLoggingOptions
SentryLoggingOptions <|-- SentryAspNetCoreOptions
SentryLoggingOptions <|-- SentryMauiOptions
SentryLoggingOptions <|-- SentryBlazorOptions
The new wayAs such, in version 7.0 we're splitting that options class up:
classDiagram
SentryOptions <|-- SentryHostOptions
SentryHostOptions <|-- SentryAspNetCoreOptions
SentryHostOptions <|-- SentryMauiOptions
SentryHostOptions <|-- SentryBlazorOptions
SentryHostOptions *-- SentryLoggingOptions : holds internally
|
There was a problem hiding this comment.
Just a note on why SentryHostOptions.Logging is a composite property:
SentryLoggingOptionsmust be a concrete public class. It's what users configure inbuilder.Logging.AddSentry(o => …), and when using MELIOptions<SentryLoggingOptions>resolves from DI for the options binding.IOptions<T>is constrained toclass, new(), so this can't be an interface.SentryHostOptionshas to be aSentryOptions. It's the object handed toSentrySdk.InitHub... so it can't descend fromSentryLoggingOptions- that's kind of the whole point of this PR stack - removing the DSN (and options that are used for SDK initialisation) from the options that are used to initialise the logging integrations.
The sample sets the DSN in code via UseSentry, so the commented-out Dsn entry is misleading. EnableTracing is declared on BindableSentryOptions but never applied, so setting it has no effect. Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Emit can run concurrently, so the check-then-set on the warned flag could let more than one thread log the warning. Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…sposes the hub Sdk.Name and Sdk.Version should identify the integration that initialised the hub, which after this PR can no longer be a logging integration. The logging integration identifies itself through the log origin (auto.log.*) instead. See #5497. With the SDK name gone, and ConfigureScope callbacks now applied at init, the scope the provider pushed has nothing left to hold, so it goes too. Disposing the hub goes as well: whoever initialises the hub owns it, and the provider is now always handed HubAdapter, which is not IDisposable. The one fixture that handed it a real Hub now disposes the Hub it created. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…into feat/no-init-from-logging-nlog-5245
Sdk.Name should identify the integration that initialised the hub, which after this change can no longer be a logging integration. The sink identifies itself through the log origin (auto.log.serilog) instead. See #5497. Events are no longer stamped with sentry.dotnet.serilog, and structured logs no longer carry it as sentry.sdk.name; both now report the SDK that initialised Sentry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…logging-nlog-5245
Sdk.Name should identify the integration that initialised the hub, which after this change can no longer be a logging integration. The target identifies itself through the log origin (auto.log.nlog) instead. See #5497. Events are no longer stamped with sentry.dotnet.nlog, and structured logs no longer carry it as sentry.sdk.name; both now report the SDK that initialised Sentry. With no remaining callers, Constants is deleted. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…from-logging-log4net-5245
Sdk.Name should identify the integration that initialised the hub, which after this change can no longer be a logging integration. The appender identifies itself through the log origin (auto.log.log4net) instead. See #5497. Events are no longer stamped with sentry.dotnet.log4net, and structured logs no longer carry it as sentry.sdk.name; both now report the SDK that initialised Sentry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…it-from-logging-mel-5245
… set the SDK name Completes the change across the four logging integrations: the SDK name on a log should identify the integration that initialised the hub, and the logging integration identifies itself through the origin (auto.log.extensions_logging). See #5497. The ASP.NET Core and MAUI structured logger providers keep passing their own SDK version: those integrations do initialise the SDK, so the name is theirs to set. With no remaining callers, Constants and SentryLoggerProvider.NameAndVersion are deleted. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ment EnableLogs belongs in the Sentry section. Since #5595, setting it under Logging:Sentry fails at startup, so the old hint sent readers to the wrong place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Blazor, where logs are opt-in (#5642) * feat(logging): Add EnableLogs to SentryHostOptions ASP.NET Core, Google Cloud Functions, MAUI and Blazor WebAssembly add the MEL integration on the user's behalf, and that isn't consent to send logs. Since #5504, these apps sent every ILogger entry to Sentry. SentryHostOptions now has EnableLogs, default false. It hides the obsolete SentryOptions.EnableLogs and binds from the existing EnableLogs configuration key. SentryStructuredLogger reads it from the hub's options, so Logging.AddSentry() on a hub created by SentrySdk.Init keeps sending logs, like the other logging integrations. With no log envelopes sent by default, the WebIntegrationTests.Versioning snapshots and the Google Cloud Functions SDK-name assertion return to how they were before #5504. Refs #5183 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(samples): Set EnableLogs again in the framework samples Restores EnableLogs = true where #5504 removed it, so these samples keep sending logs: ASP.NET Core Basic, gRPC, MVC, ME.AI and MAUI. The Google Cloud Functions sample already has it again after main was merged into version7. Refs #5183 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Accept API verifier changes * feat(logging)!: Remove SentryOptions.EnableLogs Only the integrations that derive from Sentry.Extensions.Logging (ASP.NET Core, MAUI, Blazor WebAssembly) need the option, so it now lives on SentryHostOptions alone. SentrySdk.Logger and the logging integrations always send logs, and the logs spec dropped the global option in 3.0.0. James Crosswell agreed to remove it in v7. The obsolete base property also made code that set EnableLogs through a SentryOptions reference compile, warn that logs are always enabled, and leave them off on host options. That code now fails to compile instead. NLog's SentryTarget.EnableLogs stays as an obsolete no-op with its own message, so existing NLog.config files still load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(aspnetcore): Check EnableLogs end to end through UseSentry The existing tests build a Hub directly. These run a real UseSentry host, which reaches the gate through HubAdapter, and cover the default, the opt-in in code and the opt-in from the Sentry configuration section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(samples): Clarify what EnableLogs covers in the ASP.NET Core sample Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(nlog)!: Remove SentryTarget.EnableLogs The Sentry target always sends logs, so the option was an ignored no-op. v7 removes SentryOptions.EnableLogs and Serilog's enableLogs parameter, so the NLog target drops its copy too. A leftover enableLogs attribute in NLog.config is ignored with NLog's default settings. With throwConfigExceptions or throwExceptions on, NLog refuses to load the configuration and names the attribute, so the app fails on its first run after the upgrade. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Accept API verifier changes * test: Assert the single log in the EnableLogs opt-in tests ContainSingle with a predicate passed when other logs were also sent. Asserting a single log, then its message, also catches extra logs, such as the SDK's own, and the failure shows the log that arrived. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(nlog): Keep SentryTarget.EnableLogs so v6 configurations still load Removing the property broke NLog.config files that still set enableLogs. With throwConfigExceptions on, NLog rejected the whole configuration, so the app lost every target, not only Sentry. #5652 fixed the same failure for initializeSdk="false". This reverts 8b80e53. The property stays obsolete and ignored, with its own obsolete message, because SentryOptions.ObsoleteEnableLogs is gone. LoadConfiguration_WithEnableLogs_DoesNotThrow loads both values with throwConfigExceptions on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(samples): Drop the Logging section hint from the EnableLogs comment EnableLogs belongs in the Sentry section. Since #5595, setting it under Logging:Sentry fails at startup, so the old hint sent readers to the wrong place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(logging): Declare EnableLogs on the host options, not SentryHostOptions EnableLogs is public on SentryAspNetCoreOptions, SentryMauiOptions and SentryBlazorOptions, the hosts that add the ILogger provider for the user. Each one forwards to an internal flag on SentryHostOptions, so a future host that derives from it only gets the setting if it declares one. Settling this before v7 ships avoids a breaking change later. SentryStructuredLogger still reads the flag from the hub's options, so an explicit Logging.AddSentry() in a host app stays off unless EnableLogs is set. BindableSentryHostOptions keeps binding EnableLogs from the Sentry section for all three hosts. The remarks no longer mention SentrySdk.Logger and the logging integrations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io> Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
…lder Generic-host apps lost their way to initialize Sentry when the logging integration stopped doing it (#5595). UseSentry reads the Sentry section and Logging:Sentry, runs the options callback, then maps the host environment, so an explicit Environment or SENTRY_ENVIRONMENT still wins. It registers the logger providers, so Logging.AddSentry() is not needed, and the hub, ISentryClient and HttpClientFactory instrumentation through AddSentry<SentryGenericHostOptions>. The IHostApplicationBuilder overloads are not generic: with a TBuilder overload, builder.UseSentry(o => ...) on a WebApplicationBuilder is ambiguous with Sentry.AspNetCore's whenever both packages are referenced. The IHostBuilder overloads go through ConfigureServices and AddLogging, because ConfigureLogging is not in Hosting.Abstractions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lder Generic-host apps lost their way to initialize Sentry when the logging integration stopped doing it (#5595). UseSentry reads the Sentry section and Logging:Sentry, runs the options callback, then maps the host environment, so an explicit Environment or SENTRY_ENVIRONMENT still wins. It registers the logger providers, so Logging.AddSentry() is not needed, and the hub, ISentryClient and HttpClientFactory instrumentation through AddSentry<SentryGenericHostOptions>. The IHostApplicationBuilder overloads are not generic: with a TBuilder overload, builder.UseSentry(o => ...) on a WebApplicationBuilder is ambiguous with Sentry.AspNetCore's whenever both packages are referenced. The IHostBuilder overloads go through ConfigureServices and AddLogging, because ConfigureLogging is not in Hosting.Abstractions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lder Generic-host apps lost their way to initialize Sentry when the logging integration stopped doing it (#5595). UseSentry reads the Sentry section and Logging:Sentry, runs the options callback, then maps the host environment, so an explicit Environment or SENTRY_ENVIRONMENT still wins. It registers the logger providers, so Logging.AddSentry() is not needed, and the hub, ISentryClient and HttpClientFactory instrumentation through AddSentry<SentryGenericHostOptions>. The IHostApplicationBuilder overloads are not generic: with a TBuilder overload, builder.UseSentry(o => ...) on a WebApplicationBuilder is ambiguous with Sentry.AspNetCore's whenever both packages are referenced. The IHostBuilder overloads go through ConfigureServices and AddLogging, because ConfigureLogging is not in Hosting.Abstractions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lder Generic-host apps lost their way to initialize Sentry when the logging integration stopped doing it (#5595). UseSentry reads the Sentry section and Logging:Sentry, runs the options callback, then maps the host environment, so an explicit Environment or SENTRY_ENVIRONMENT still wins. It registers the logger providers, so Logging.AddSentry() is not needed, and the hub, ISentryClient and HttpClientFactory instrumentation through AddSentry<SentryGenericHostOptions>. The IHostApplicationBuilder overloads are not generic: with a TBuilder overload, builder.UseSentry(o => ...) on a WebApplicationBuilder is ambiguous with Sentry.AspNetCore's whenever both packages are referenced. The IHostBuilder overloads go through ConfigureServices and AddLogging, because ConfigureLogging is not in Hosting.Abstractions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Logging.AddSentry() no longer initializes the SDK (#5595). An upgraded app learns that from one message: at startup for a DSN under Logging:Sentry, or at compile time for AddSentry(dsn), Dsn and InitializeSdk. It pointed to SentrySdk.Init or "UseSentry via one of the integrations", and a worker service can't get from there to Sentry.Extensions.Hosting. In a dogfooding run, an agent upgrading a v6 worker found the package only by listing the feed it installed from. The message now names UseSentry from Sentry.Extensions.Hosting, Sentry.AspNetCore and Sentry.Maui, and says UseSentry reads the removed settings from the Sentry section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ient The logging integration hasn't initialized Sentry since #5595, but it still registered IHub, ISentryClient and Func<IHub>, a leftover from when it did. Every UseSentry registers them through AddSentry<TOptions>, so they belong to whatever initializes Sentry. Logging.AddSentry() now registers its two logger providers on HubAdapter.Instance, which always forwards to the current hub, and the HttpClientFactory filter, so logging-only apps keep their outgoing-HTTP breadcrumbs and spans. The redundant-call warning still resolves IHub when it's registered: the host integration registers it, and resolving it starts the SDK, so the warning shows when Logging.AddSentry() runs first. Apps that call only SentrySdk.Init and Logging.AddSentry() and inject these services now get a DI error when they're resolved, and register them with HubAdapter.Instance instead. The regression tests from #5646 keep their host case. Their logging-only case checked a resolved hub that no longer exists; new LoggingBuilderExtensionsTests cover that path, including the HttpClientFactory handler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pps (#5739) * feat(hosting): add an empty Sentry.Extensions.Hosting package The generic-host UseSentry (#5572) needs Microsoft.Extensions.Hosting.Abstractions for IHostedService, the host environment and the host builder types. It gets its own package instead of a new dependency in Sentry.Extensions.Logging, like Serilog.Extensions.Hosting and NLog.Extensions.Hosting. SentryGenericHostOptions is the options type for this integration. SentryHostOptions stays abstract; the subclass exposes EnableLogs and reports the SDK as sentry.dotnet.extensions.hosting. Sentry and Sentry.Extensions.Logging grant the package InternalsVisibleTo, as they do for the other integrations, for the shared options setup and hub registration. On netstandard2.0 the package uses Hosting.Abstractions 3.1.0 rather than the 2.1.0 floor of Sentry.Extensions.Logging. HostBuilderContext.HostingEnvironment changed type in 3.0, from IHostingEnvironment to IHostEnvironment, so a build against 2.1.0 that reads it throws MissingMethodException on any 3.0+ host. 3.1.0 also brings IHostApplicationLifetime to netstandard2.0. Hosting 2.x is out of support. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(logging): compile SentryHostOptionsSetup for netstandard2.0 Its only caller so far, Blazor WebAssembly, targets .NET 8+, so it was only compiled for .NET 6+. The generic host's IHostBuilder overload also runs on .NET Framework through netstandard2.0. The body already builds there, and binding through BindableSentryHostOptions behaves the same on every target (checked on net48). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(hosting): register Sentry.Extensions.Hosting with craft The registry target needs the entry to add the package to the release registry on its first stable release, and sdkName makes craft create the sdks/sentry.dotnet.extensions.hosting entry that the docs and the outdated-SDK check look up. GenerateSentrySdkNamespaces reads the same lines, so the logging integrations now treat Sentry.Extensions.Hosting as SDK code and drop its own log messages. mainDocsUrl points at the .NET platform page until the generic-host guide exists (NET-857). The registry target skips prereleases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * build: add Sentry.Extensions.Hosting to the solution and filters Without it, CI never builds, tests or packs the package. The filters are regenerated with scripts/generate-solution-filters.ps1; each gains only this project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: list Sentry.Extensions.Hosting in the README and bug report form The documentation link points to the .NET platform page, the same URL as the package's .craft.yml entry, until the package has its own page (NET-857). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): add UseSentry for IHostApplicationBuilder and IHostBuilder Generic-host apps lost their way to initialize Sentry when the logging integration stopped doing it (#5595). UseSentry reads the Sentry section and Logging:Sentry, runs the options callback, then maps the host environment, so an explicit Environment or SENTRY_ENVIRONMENT still wins. It registers the logger providers, so Logging.AddSentry() is not needed, and the hub, ISentryClient and HttpClientFactory instrumentation through AddSentry<SentryGenericHostOptions>. The IHostApplicationBuilder overloads are not generic: with a TBuilder overload, builder.UseSentry(o => ...) on a WebApplicationBuilder is ambiguous with Sentry.AspNetCore's whenever both packages are referenced. The IHostBuilder overloads go through ConfigureServices and AddLogging, because ConfigureLogging is not in Hosting.Abstractions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): start Sentry when the host starts and close it on shutdown AddSentry<TOptions>() starts the SDK when something first resolves the hub. With the logging providers replaced or cleared (Serilog, ClearProviders()), that can be much later, and nothing before it is captured. ASP.NET Core had the same problem (#5721). SentryHostedService resolves Func<IHub> in its constructor. The host resolves all hosted services before it starts any, so the SDK is running before the first StartAsync, whatever the registration order and also with ServicesStartConcurrently. It closes the SDK on ApplicationStopped, after every hosted service has stopped, as ASP.NET Core does. TryAddEnumerable keeps one instance when UseSentry is called twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): step aside when Sentry.AspNetCore's UseSentry is also used A web app can reach the generic UseSentry through a helper constrained to IHostApplicationBuilder, such as Aspire's ServiceDefaults, while also calling UseSentry from Sentry.AspNetCore. Both then registered logger providers, so every logged error was sent twice, and when the generic call came last the SDK started with its options instead of ASP.NET Core's. The generic call now does nothing if ASP.NET Core's integration is already registered. If ASP.NET Core's comes later, the generic logger providers are disabled and log a diagnostic warning, and ASP.NET Core's registration replaces the SDK accessor, so the SDK starts with ASP.NET Core's options. Logging.AddSentry() steps aside the same way (#5694). To recognize the integration without depending on ASP.NET Core, Sentry.AspNetCore registers an internal HostIntegrationMarker from Sentry.Extensions.Logging next to HostLoggerProvidersMarker, and the generic call checks for that service type. Google Cloud Functions registers the ASP.NET Core logger providers too, so it registers the marker as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): step aside when Sentry.Maui's UseSentry is also used MauiAppBuilder implements IHostApplicationBuilder since MAUI 10, and the Aspire MAUI service defaults template has an AddServiceDefaults<TBuilder> helper constrained to it, so a MAUI app can reach the generic UseSentry while also calling UseSentry from Sentry.Maui. When Sentry.Maui's call came first, the generic one started the SDK again with its own options, and the app crashed when the DSN had only been set in the Sentry.Maui call. Sentry.Maui now registers the same marker as Sentry.AspNetCore, so the generic call steps aside for it too. When the generic call comes first, its logger providers are disabled, but its SDK accessor still starts the SDK; the next commit fixes that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): let the host integration own the SDK when the generic UseSentry comes first Sentry.Maui starts the SDK itself while MauiApp.Build() runs, and registers a hub accessor that doesn't start it. AddSentry only replaced an earlier accessor when the new one started the SDK, so when the generic UseSentry was called first, its accessor stayed. The first IHub resolution then started the SDK with the generic options: the app crashed when the DSN was only set in Sentry.Maui's call, and otherwise sent events with the generic SDK name and options. SentryOptions in DI had the same problem in MAUI and ASP.NET Core apps, because it was registered with TryAdd. ASP.NET Core's blocking-call detection resolves it, so its stack traces were built from the generic options. AddSentry now replaces both, so the integration registered last owns them. The generic UseSentry returns early when a host integration is already registered, so in either order that is the host integration. An app that registers its own SentryOptions or, with Sentry.Maui, its own Func<IHub> before UseSentry now gets the integration's; the SDK never started from those registrations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): register the generic UseSentry only once when it's called twice Calling UseSentry twice, for example in Aspire's AddServiceDefaults and again in Program.cs, registered the logger providers twice, so every logged error was sent as two events and every log twice. The first call now registers the integration and each call adds only its options callback, so options from both calls still apply, later ones winning. The host environment is applied in a PostConfigure, after all the callbacks, so AdjustStandardEnvironmentNameCasing set by a later call or a later services.Configure is honored too; before, the first call had already set the environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(hosting): add the Sentry.Extensions.Hosting test project The package had no tests and no API snapshot, so a change to its public API would go unnoticed. The project targets the same .NET versions as the package, plus net48 on Windows with Microsoft.Extensions.Hosting 3.1.0, the package's netstandard2.0 floor. The net48 snapshot can only be generated on Windows, so CI's verify-api job adds it. Sentry and Sentry.Extensions.Hosting expose their internals to the project for the behavior tests that follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: cover Sentry.Extensions.Hosting in the SDK namespaces test The logging integrations recognize the SDK's own log categories through SentrySdkNamespaces, which is generated from the package list in .craft.yml, so that entry is what keeps this package's own log messages out of Sentry. The new case fails if the entry is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * build: add the hosting tests to the solution and filters Without it, CI doesn't build or run them. The filters are regenerated with scripts/generate-solution-filters.ps1; each gains only this project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(hosting): cover UseSentry and the hosted service on both builders Each behavior is tested through IHostBuilder and, on .NET 8 and later, IHostApplicationBuilder: what every overload registers, including IHub and ISentryClient in DI; binding from the Sentry and Logging:Sentry sections; the host environment and its casing flag; calling UseSentry twice; Logging.AddSentry before and after UseSentry; the SDK name on captured events; and an empty Dsn read from JSON (#3875). The hosted service tests show the SDK running before the app's own hosted services start with the logger providers cleared, also when they start concurrently, and an error logged while the app stops still captured before Close. The tests log under an app category: logs from Sentry.Extensions.Hosting are the SDK's own and never reach Sentry. They use Sentry.Testing's FakeSettings, so SENTRY_DSN or SENTRY_ENVIRONMENT in the shell doesn't change the results. Sentry.Extensions.Logging and Sentry.Testing expose their internals to the project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(aspnetcore): cover the generic UseSentry in web apps With both UseSentry calls, in either order, one logged error gives one event with the ASP.NET Core SDK name, and SentryOptions in DI is the ASP.NET Core options. The generic call goes through a helper constrained to IHostApplicationBuilder, as Aspire's AddServiceDefaults does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(maui): cover the generic UseSentry next to Sentry.Maui's With both calls, in either order, one logged error gives one event with the MAUI SDK name and SentryOptions in DI is the MAUI options. The DSN is only set in Sentry.Maui's call, so if the generic options were used, the generic-first case would fail to start the SDK. The tests run in a collection with parallelization off, as in the hosting and ASP.NET Core test projects. Sentry.Maui goes through the global hub, so another test class starting or closing the SDK at the same time swapped it underneath them: on the iOS simulator one run saw no event and another an extra one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(samples): initialize Sentry with UseSentry in the generic host sample The sample called SentrySdk.Init by hand and then added the logging integration, so its options lived in code only and the host environment was ignored. It now calls UseSentry, which reads the Sentry section of appsettings.json, uses the host environment and closes the SDK on shutdown. SendDefaultPii moves to that section. EnableLogs is turned on there too: logs are opt-in with the host integrations' options, so without it the sample would stop sending the structured logs it configures. SampleHostedService still gets IHub from DI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(samples): use UseSentry in the Azure Functions sample The sample initialized the SDK with SentrySdk.Init before building the host and added the logging integration separately. It now calls the IHostBuilder overload of UseSentry on its HostBuilder, which also adds the logger providers and closes the SDK when the host shuts down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): warn when a web app uses only the generic UseSentry A web app reaches the generic UseSentry through a helper constrained to IHostApplicationBuilder, such as Aspire's AddServiceDefaults, or through builder.Host. Sentry then works, but without the ASP.NET Core integration: events have no request data and requests aren't traced, and nothing says so. When UseSentry runs on a WebApplicationBuilder or its Host, and the ASP.NET Core integration isn't registered by the time the host starts, the hosted service logs one warning through the host logger. It names UseSentry from Sentry.AspNetCore and shows the builder-type branch for shared helpers. The check reads the builder's type name, so the package still doesn't depend on ASP.NET Core. The branch calls SentryWebApplicationBuilderExtensions.UseSentry(web) as a static method. Aspire's ServiceDefaults file is declared in namespace Microsoft.Extensions.Hosting, this package's namespace, and C# looks for extension methods there before it looks at using directives, so web.UseSentry() in that file would bind to the generic overload again. A test runs the snippet from a helper declared in that namespace. An earlier version keyed off ASP.NET Core's GenericWebHostService being registered. Azure Functions apps with the ASP.NET Core integration register that service too, and for them the generic UseSentry is the right call, so they'd have been warned on every start. Their builders are HostBuilder and FunctionsApplicationBuilder, which the builder-type check never matches. The cost is that a plain HostBuilder with ConfigureWebHostDefaults isn't detected. The warning's category is filtered from Sentry structured logs, so it isn't sent to Sentry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(hosting): warn when a MAUI app uses only the generic UseSentry MauiAppBuilder implements IHostApplicationBuilder since MAUI 10, so a helper constrained to it, such as the Aspire MAUI ServiceDefaults, reaches the generic UseSentry. Sentry then works, but it starts only when the app first uses a logger or IHub, and the MAUI integration's navigation and UI breadcrumbs are missing. MAUI never runs hosted services, so the web app warning can't be used here. When UseSentry runs on a MauiAppBuilder and Sentry.Maui's integration isn't registered, the logger provider writes one warning to standard error when it's created, which is also when the SDK starts. That's the channel UninitializedSdkWarning already uses for setup mistakes, and it doesn't need Debug to be on: on the Android emulator it shows in logcat under DOTNET, and on the iOS simulator in the app's system log. A packaged Windows app has no console, so it doesn't show there. The warning names UseSentry from Sentry.Maui and shows the builder-type branch for shared helpers. As for web apps, the branch calls SentryMauiAppBuilderExtensions.UseSentry(maui) as a static method, because maui.UseSentry() in a file declared in namespace Microsoft.Extensions.Hosting binds to the generic overload. A test runs the snippet from a helper declared in that namespace. The builder type check now returns an internal enum for web, MAUI or other apps, so the shared registration still takes one parameter. SentryHostedService is registered in MAUI apps too, where nothing registers IHostApplicationLifetime. It now resolves the lifetime with GetService, so code that enumerates the hosted services, such as a library that runs them in MAUI, no longer fails to resolve it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(mel): name the packages that initialize Sentry in the v7 init error Logging.AddSentry() no longer initializes the SDK (#5595). An upgraded app learns that from one message: at startup for a DSN under Logging:Sentry, or at compile time for AddSentry(dsn), Dsn and InitializeSdk. It pointed to SentrySdk.Init or "UseSentry via one of the integrations", and a worker service can't get from there to Sentry.Extensions.Hosting. In a dogfooding run, an agent upgrading a v6 worker found the package only by listing the feed it installed from. The message now names UseSentry from Sentry.Extensions.Hosting, Sentry.AspNetCore and Sentry.Maui, and says UseSentry reads the removed settings from the Sentry section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(hosting): cover a disabled SDK and starting hosted services in MAUI Codecov reported two branches in the new package that no test reached: - The redundant generic UseSentry warns through the hub's options, which a disabled SDK ("Dsn": "", supported since #3875) doesn't have. The new test runs the generic UseSentry, then Sentry.AspNetCore's with an empty DSN, and starts the app. Only this order reaches that code: with ASP.NET Core's call first, the generic one returns early. - SentryHostedService gets IHostApplicationLifetime with GetService, because MAUI doesn't register it. The MAUI test resolved the hosted services but never started them, so StartAsync with no lifetime was untested. It now starts them. Both tests fail when the null check they cover is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ient The logging integration hasn't initialized Sentry since #5595, but it still registered IHub, ISentryClient and Func<IHub>, a leftover from when it did. Every UseSentry registers them through AddSentry<TOptions>, so they belong to whatever initializes Sentry. Logging.AddSentry() now registers its two logger providers on HubAdapter.Instance, which always forwards to the current hub, and the HttpClientFactory filter, so logging-only apps keep their outgoing-HTTP breadcrumbs and spans. The redundant-call warning still resolves IHub when it's registered: the host integration registers it, and resolving it starts the SDK, so the warning shows when Logging.AddSentry() runs first. Apps that call only SentrySdk.Init and Logging.AddSentry() and inject these services now get a DI error when they're resolved, and register them with HubAdapter.Instance instead. The regression tests from #5646 keep their host case. Their logging-only case checked a resolved hub that no longer exists; new LoggingBuilderExtensionsTests cover that path, including the HttpClientFactory handler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ient (#5740) * test(mel): get the hub from SentrySdk in LoggingTests Three LoggingTests resolved IHub from DI only to reach the SDK's hub after logging, which works only because Logging.AddSentry() registers it. They now use SentrySdk, which reaches the same hub, so they no longer depend on that registration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(mel)!: Logging.AddSentry() no longer registers IHub or ISentryClient The logging integration hasn't initialized Sentry since #5595, but it still registered IHub, ISentryClient and Func<IHub>, a leftover from when it did. Every UseSentry registers them through AddSentry<TOptions>, so they belong to whatever initializes Sentry. Logging.AddSentry() now registers its two logger providers on HubAdapter.Instance, which always forwards to the current hub, and the HttpClientFactory filter, so logging-only apps keep their outgoing-HTTP breadcrumbs and spans. The redundant-call warning still resolves IHub when it's registered: the host integration registers it, and resolving it starts the SDK, so the warning shows when Logging.AddSentry() runs first. Apps that call only SentrySdk.Init and Logging.AddSentry() and inject these services now get a DI error when they're resolved, and register them with HubAdapter.Instance instead. The regression tests from #5646 keep their host case. Their logging-only case checked a resolved hub that no longer exists; new LoggingBuilderExtensionsTests cover that path, including the HttpClientFactory handler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(mel): make AddSentryHub private AddSentry<TOptions> is its only caller now that Logging.AddSentry() doesn't use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(mel): cover a redundant Logging.AddSentry() with the SDK disabled Logging.AddSentry() in an app that also calls UseSentry warns through the hub's options, which a disabled SDK ("Dsn": "") doesn't have. Codecov reported that branch untested. The test builds the app with an empty DSN, with Logging.AddSentry() before and after UseSentry, and creates a logger. It fails in both orders when the null check is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…#19961) > [!NOTE] > This targets `dotnet-v7`, which collects the .NET docs for sentry-dotnet 7.0.0. #20641 merges that branch into `master` when 7.0.0 ships, so this PR can merge into `dotnet-v7` as soon as it's approved. ## DESCRIBE YOUR PR In sentry-dotnet 7.0.0 the Microsoft.Extensions.Logging integration no longer initializes the SDK (getsentry/sentry-dotnet#5595). Generic host apps call `UseSentry` from the new `Sentry.Extensions.Hosting` package instead, which has its own guide (#20311). This updates the parts of getsentry/sentry-dotnet#5706 that #19925 leaves out: - **Microsoft.Extensions.Logging guide**: - Generic host apps, ASP.NET Core and MAUI skip this setup and go to their own guides. The note names generic host apps that used `builder.Logging.AddSentry(...)` on 6.x. - Apps without a host call `SentrySdk.Init`, then `AddSentry()`, on a `LoggerFactory` or their own `ServiceCollection`. If they inject `IHub`, `ISentryClient` or `Func<IHub>`, they register them with `HubAdapter.Instance`, because `AddSentry()` no longer does (getsentry/sentry-dotnet#5740). .NET Framework apps on `Host.CreateApplicationBuilder()` are pointed to the Generic Host guide's .NET Framework section. - Structured logs are always sent on this page, and Configure says how to send fewer. - Removes the DSN in `AddSentry(...)`, `InitializeSdk`, and SDK settings under `Logging:Sentry`. Documents what `Logging:Sentry` still accepts, and `AddLogEntryFilter`. - **Generic Host guide**: the `AddLogEntryFilter` link pointed at `#filters`, which this page no longer has. "Replacing SentrySdk.Init" now says `UseSentry` leaves structured logs off until `EnableLogs` is set. - **ASP.NET Core guide**: `SentryAspNetCoreOptions` now extends `SentryHostOptions`, not `SentryLoggingOptions`. Closes getsentry/sentry-dotnet#5706 ### Notes for review - Checked against `origin/version7` (51e7d99fb), which includes getsentry/sentry-dotnet#5869: - Every C# snippet on the Microsoft.Extensions.Logging guide compiles on net10.0 with only `Sentry.Extensions.Logging` referenced. - With `SentrySdk.Init` and `AddSentry()`, every `ILogger` entry is sent as a structured log without `EnableLogs`. - `Logging:Sentry`, added with `AddConfiguration`, is read: `MinimumEventLevel` applies, and a category entry under `LogLevel` drops only that category's structured logs. A `Dsn` key there throws `NotSupportedException` from `LoggerFactory.Create`. - Without the `HubAdapter` lines, a service that injects `IHub` fails with `Unable to resolve service for type 'Sentry.IHub' while attempting to activate ...`. - `ClearProviders()` moved out with the generic host content. It applies to ASP.NET Core's `UseSentry` too, which the ASP.NET Core guide doesn't mention yet. - `Filters` was always internal. The page shows `AddLogEntryFilter`. - The ASP.NET Core paragraph leaves out namespaces. `SentryHostOptions` is still in `Sentry.Extensions.Logging` on `version7`. - On 6.x, `AddSentry()` after `SentrySdk.Init` initializes the SDK again without a DSN, and that throws. That's why the 7.0.0 note tells 6.x users to set the DSN in `AddSentry(...)` instead. - #20240 also edits this page, against 6.x. Whichever merges second needs a merge from `master`. This PR leaves the `Sentry` prefix alert alone, which #20240 rewrites. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. Select exactly one option. For deadlines, replace `YYYY-MM-DD` with the due date. You can update this information later by editing the PR description. - [x] Urgent deadline (GA date, etc.): 2026-11-30 - [ ] Other deadline: YYYY-MM-DD - [ ] No deadline: Not urgent, can wait up to 1 week+ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Ricardo Colombo Oliveira <github@ricoliv.com>
Brings 6.12.1 and main's changes since c73118f into version7, including getsentry#5653, getsentry#5664, getsentry#5672, getsentry#5673, getsentry#5679, getsentry#5687, getsentry#5688, getsentry#5696, getsentry#5697, getsentry#5705, getsentry#5717, getsentry#5720, getsentry#5721, getsentry#5722 and getsentry#5723. Conflict resolutions: - Directory.Build.props: keep version7's 7.0.0 / prerelease. - Scope.cs: Environment syncs through getsentry#5653's ScopeObserver property with getsentry#5671's ScopeDefaults fallback. Apply keeps getsentry#5671's rule that the event's own SDK name and version win over the scope's. - Sentry.AspNetCore.Grpc/SentryBuilderExtensions.cs and Sentry.Google.Cloud.Functions/SentryStartup.cs: keep version7's side. getsentry#5671 replaced both SDK-name event processors with options.SetSdk, so getsentry#5688's ISdkProcessor marker has nothing left to mark. - Sentry.Samples.AspNetCore.Serilog: getsentry#5720's builder.UseSentry with version7's options callback (DSN plus o.UseSerilog()). Merged cleanly but needed changes: - Scope.Clone: drop Release and Distribution, which getsentry#5671 removed. - ScopeTests.Clone_EveryFieldHandled: drop the same two fields. - IntegrationsTests: drop getsentry#5721's WebHost_LoggerFactoryReplacedInitializeSdkFalse_SdkDisabled. On version7 UseSentry always initializes the SDK (getsentry#5595), so InitializeSdk = false no longer compiles. - ApiApprovalTests DotNet11_0 snapshots: add getsentry#5664's WithMonitor and getsentry#5720's SentryWebApplicationBuilderExtensions, matching the DotNet10_0 snapshots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in everything up to and including the 6.13.0 release. Conflict resolutions: - CHANGELOG.md: the 7.0.0-rc.* sections stay above 6.13.0 until they are consolidated just before the 7.0.0 release. - Directory.Build.props: keep VersionPrefix 7.0.0-rc.3 and the dev VersionSuffix that craft cleared when it cut 6.13.0. - SystemWebRequestEventProcessor.cs: version7 no longer needs Sentry.Reflection; main's SensitiveDataFilter needs DataCollection. - SentryLoggingOptionsSetupTests.cs: keep version7's test. Since getsentry#5595 SentryLoggingOptions no longer derives from SentryOptions, so main's DataCollection assertions don't apply; BindableDataCollectionOptionsTests covers that binding. - API snapshots: add main's DataCollection API, drop ApplyDefaultTags, which version7 removed. DotNet11_0 regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The
Microsoft.Extensions.Loggingportion of #5245, stacked on #5592 (log4net) and following the same design.AddSentrynow only wires up the logger providers; Sentry has to be initialized separately viaSentrySdk.Init,UseSentry, etc.This is the last of the four logging integrations, so it closes the issue.
Closes #5245
Tip
Background for reviewers on how Sentry gets initialised today, and why this PR splits
SentryLoggingOptions: #5595 (comment)Changelog Entry
Microsoft.Extensions.Loggingintegration no longer initializes the SDK. Sentry must now be initialized separately from the logging integration (usingSentrySdk.InitorUseSentry) - #5595Logging:Sentry) now only configures the logging integration. Core SDK settings there, such asDsn, no longer have any effect and fail at startup with migration guidance: move them to theSentrysection, or pass them where Sentry is initialized - #5595MinimumEventLevel,MinimumBreadcrumbLevel, log entry filters andConfigureScopecallbacks set inUseSentry- #5595Breaking changes
SentryLoggingOptionsno longer derives fromSentryOptions, matching the Serilog and NLog options. It carries onlyMinimumBreadcrumbLevel,MinimumEventLeveland log entry filters, sobuilder.Logging.AddSentry(o => o.Dsn = "…")now fails with a migration error instead of silently doing nothing. Core SDK settings go on the options used to initialize Sentry.SentryLoggingOptions.ConfigureScopeis removed. CallSentrySdk.ConfigureScopeafter initializing Sentry.ILoggingBuilder.AddSentry(string dsn)no longer initializes Sentry. It is kept as an obsolete-as-error tombstone that throwsNotSupportedExceptionwith migration guidance, so both code callers and reflection-based callers fail loudly.ILoggerFactory.AddSentry(…)no longer initializes Sentry, replaces the current hub, or assigns aMelDiagnosticLoggeras the SDK'sDiagnosticLogger.InitializeSdkno longer has any effect.SentryLoggingOptions.DsnandSentryLoggingOptions.InitializeSdkare kept as tombstones that throw when set, including when they are bound from theSentryconfiguration section, so an app that upgrades with a config-bound DSN fails at startup instead of silently reporting nothing. On the framework options it is gone entirely.SentryAspNetCoreOptions,SentryMauiOptionsandSentryBlazorOptionsnow derive from a new abstractSentryHostOptions : SentryOptions. They still haveMinimumBreadcrumbLevel,MinimumEventLevel,ConfigureScopeandAddLogEntryFilter, and the same keys still bind from theSentryconfiguration section, so existingUseSentrycallbacks andappsettings.jsonfiles keep working. Code that treats them as aSentryLoggingOptionsno longer compiles.Logging:Sentrybinds MEL's ownLogLevelrules plusMinimumEventLevelandMinimumBreadcrumbLevel; any other key there throwsNotSupportedExceptionnaming the offending keys. Core SDK settings still bind from the rootSentrysection for the integrations that initialize Sentry, which is where every sample and docs guide already puts them.ServiceCollectionExtensions.AddSentry<TOptions>now requiresTOptions : SentryHostOptions.builder.Logging.AddSentry()no longer registersSentryOptionsin the service collection, so resolvingSentryOptionsfrom DI on that path now throws. The MEL integration no longer owns an options object that initializes the SDK. The integrations that do initialize still register it.ConfigureScopecallbacks on the framework options now run when Sentry is initialized, rather than when the Sentry logger provider is first created.AddSentry(o => …)call that only sets logging settings still compiles, and on 6.x it initialized the SDK itself, taking the DSN fromSENTRY_DSNor a[Dsn]assembly attribute. The integration therefore warns at runtime — on the first log event that would have become a Sentry event, if Sentry is not initialized but a DSN can still be found, it writes one line to standard error, at most once per logger provider.Microsoft.Extensions.Logginghas no self-diagnostics channel, so standard error is the only one available; the shared policy lives inSentry.Internal.UninitializedSdkWarning, added in feat(serilog)!: the Sentry sink no longer initializes the SDK #5573.SentryLogger.Logalso now readsIHub.IsEnabledonce per call instead of twice.Before:
After:
Fixes
UseSentry. Blazor registered the plain MEL logger provider, which dependency injection built from a separate, defaultIOptions<SentryLoggingOptions>rather than theSentryBlazorOptionsconfigured inUseSentry.MinimumEventLevel,MinimumBreadcrumbLevel, log entry filters andConfigureScopewere all silently ignored by the logger; SDK initialization itself was unaffected. The same bug exists onmain.UseSentryregisteredSentryAspNetCoreOptionsSetuptwice, once with the rootSentrysection and once with the logging provider configuration (Logging:Sentry). Different sections, but the same setup class, so everything itsConfigureadds beyond binding was applied twice: two Kestrel deduplication log filters and twoTraceIgnoreStatusCodeTransactionProcessorinstances. The setup now binds theSentrysection once, and the logging section gets its own setup that only applies logging settings. On netstandard2.0 the section was bound by a plainConfigure<SentryAspNetCoreOptions>(section)call and the setup ran once, so the extras were already applied once there; that branch is gone, and the setup now runs once on every target.DetectStartupTime,RequestBodyCompressionLevelandIsGlobalModeEnabledare set because Blazor WASM requires them (System.Diagnostics.Processisn't supported there, andHttpClientHandlercan't compress), but they are applied in the sameConfiguredelegate as theUseSentrycallback, which was registered before the configuration binding.IConfigureOptions<T>run in registration order, so aSentry:DetectStartupTimekey inwwwroot/appsettings.jsonwon over the platform default, reintroducing thePlatformNotSupportedExceptionit exists to avoid - and configuration won over anything set inUseSentry, the opposite of ASP.NET Core. The setups are now registered first, so precedence runs from theSentrysection, throughLogging:Sentry, to the callback and the platform defaults.version7has the same inversion, where the genericAddSentry<SentryBlazorOptions>(delegate)registered the callback before its options setup.sentry.environment,sentry.releaseandserver.addresswere read fromSentryLoggingOptions, which the SDK was no longer initialized with. The structured logger now reads them from the hub.Notes for review
UseSentryno longer loses aTryAddrace withLogging.AddSentry(). The logging integration registers a non-initializingFunc<IHub>, so whichever call ran first used to win. Callingbuilder.Logging.AddSentry()beforeUseSentryleft the SDK disabled with no indication, where v6 failed loudly at startup with "You must supply a DSN". The initializing registration now replaces any existing accessor, so order no longer matters; both orders are tested. Calling both is still redundant and still registers two pairs of logger providers, unchanged from v6. MAUI was never affected, since it initializes inSentryMauiInitializerrather than through the hub accessor.Why
SentryHostOptions.SentryLoggingOptionswas doing two jobs: configuring the MEL logger, and acting as the base class for integrations that initialize the SDK. Splitting them is what letsSentryLoggingOptionsgo standalone. The host options pass the log levels and filters through to an innerSentryLoggingOptionsinstance (the same object, not a copy), and that is what their logger providers receive.Why abstract. It's the natural options type for a generic-host init path (Add a non-logging way to initialise Sentry in generic host apps #5572). Making it concrete later is additive; the reverse would be breaking. It lives in
Sentry.Extensions.Loggingbecause that's the one package ASP.NET Core, MAUI and Blazor all reference. Where it ultimately belongs is the packaging question Add a non-logging way to initialise Sentry in generic host apps #5572 raises.ConfigureScopetiming. For MAUI and Blazor, the only thing that applied these callbacks used to be the MEL logger provider's constructor, gated onhub.IsEnabledwhen the provider was built. They're now applied right after init: inAddSentry<TOptions>'s hub factory (ASP.NET Core, Blazor) and inSentryMauiInitializer(MAUI). ASP.NET Core still also applies them per request inSentryMiddleware, and gRPC in its interceptor.SDK name.
SentryLoggerProviderno longer stampsSdk.Name/Sdk.Version, pushes a scope, or disposes the hub. Per Metrics andSentrySdk.Loggerlogs emitted during a request carry nosentry.sdk.name/sentry.sdk.versionon ASP.NET Core #5497 the SDK name identifies the integration that initialized the hub, and the logging integration is identified by the origin (auto.log.extensions_logging). ASP.NET Core, MAUI and gRPC set their own names, so they are unaffected; Blazor WebAssembly has none of its own, which is Blazor WebAssembly apps don't report a Blazor SDK name #5613.Migration guard. Mirrors feat(serilog): configuring a DSN on the sink now fails with a migration error #5611 (Serilog) and the NLog and log4net guards on this stack. A single
SentryLoggingConfigurationnow binds the logging section on every target framework: it applies the two levels, ignores MEL's ownLogLevelrules, and throws for anything else - the obsolete-as-error message forDsnorInitializeSdk: true, and a message naming the offending keys otherwise. That replacesBindableSentryLoggingOptionsand the separate netstandard2.0 reflection path, which is what made the tombstone setters value-dependent (the configuration binder writes each property's own value back, and the unconditional version broke Windows CI earlier on this branch). The setters stay value-dependent, since anyone can still callconfiguration.Bind(options)themselves.Which configuration each integration reads. The integrations that initialize Sentry read
Logging:Sentryfrom the app's configuration rather than throughILoggerProviderConfiguration, because an app that passes the whole configuration toAddConfiguration- asSentry.Google.Cloud.Functionsdoes - makes the rootSentrysection part of the provider section, and every core setting in it would then be rejected. Plain MEL keeps the provider configuration, where rejecting core settings is right: nothing else binds them ontoSentryLoggingOptions, so they really would be ignored.InitializeSdk. MAUI initializes inSentryMauiInitializer, so it calls an internal non-initializing overload ofAddSentry<TOptions>instead of setting a flag. Tests that setInitializeSdk = falseto avoid initializing now useDisableSdkDsnValue.UseSentry_OptionsNotInitializeSdk_DisabledSdktested the flag itself and is deleted;UseSentry_DisableDsn_DisabledSdkstill covers a disabled SDK.Blazor registrations.
UseSentrynow delegates to an internalILoggingBuilderextension so it can be unit tested (WebAssemblyHostBuilderneeds a browser runtime). The providers are registered by factory so they keep their existing types, and with them the existing provider alias and filter configuration. Configuration binding moved to a smallSentryHostOptionsSetup<TOptions>inSentry.Extensions.Logging, which has the configuration-binding source generator enabled, since Blazor WASM is trimmed.New tests.
ConfigureScopecallbacks, and the non-initializing path doesn't.ConfigureScopedata reaches events. Nothing tested that before.MinimumEventLevel.Sentrysection configures both halves of the host options, the logging section configures only the logging half, a core setting there throws, and the section's extras are applied once.AddConfigurationstill gets its rootSentrysection bound rather than rejected.SentryLoggingOptionsis a key the logging section accepts, so a new logging option can't be mistaken for an SDK setting.UseSentrycallback wins over configuration while configuration still applies to what the callback leaves alone.Each test was checked to fail with its fix reverted.
The
ApplyDefaultTagstests only usedSentryLoggingOptionsas a vehicle for a coreSentryOptionsmethod; they moved toSentryOptionsTests.The structured-logger tests now give their mocked hub options through
SentryOptionsForTestingOnlyand reset it afterwards. The MEL provider test previously passed only because another test class happened to leave it set.builder.Logging.AddSentry(dsn)was the only way to initialize Sentry in a generic-host app, sosamples/Sentry.Samples.GenericHostnow callsSentrySdk.Initdirectly. Add a non-logging way to initialise Sentry in generic host apps #5572 tracks the replacement and should land before this ships.samples/Sentry.Samples.GenericHostkept its log levels in the rootSentrysection and passed the whole configuration tobuilder.Logging.AddConfiguration, which is how they reached the logging integration. They now live underLogging:Sentry, and that call is gone.SentryWebHostBuilderExtensionsTests'IConfigurationsubstitute returned""for every key, where configuration returnsnullfor an absent one. It now returnsnull, which removed a#if NET8_0-only workaround inUseSentry_Logging_AddLoggerProviders.ApiApprovalTests.Run.Net4_8can't regenerate on macOS. It was byte-identical to the other snapshots before this change, so it's a copy of the regenerated one.🤖 Generated with Claude Code