Repository navigation
feat!: EnableLogs moves from SentryOptions to ASP.NET Core, MAUI and Blazor, where logs are opt-in - #5642
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## version7 #5642 +/- ##
============================================
+ Coverage 74.65% 75.16% +0.51%
============================================
Files 505 520 +15
Lines 18372 18896 +524
Branches 3535 3664 +129
============================================
+ Hits 13715 14203 +488
- Misses 3796 3831 +35
- Partials 861 862 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
b326284 to
76122be
Compare
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 <[email protected]>
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 <[email protected]>
a0ac96c to
7bbe8ac
Compare
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 <[email protected]>
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 <[email protected]>
…mple Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 <[email protected]>
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 <[email protected]>
jamescrosswell
left a comment
There was a problem hiding this comment.
Generally looks good. The only blocker is the removal of the property from the NLog target.
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 <[email protected]>
…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 <[email protected]>
7aaec7d to
5c5ccfd
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5c5ccfd. Configure here.
…HostOptions 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 <[email protected]>
5c5ccfd to
fd82438
Compare
…gs-opt-in-5183 Resolve the conflict in SentryBlazorOptions by keeping both the SetSdk constructor from #5671 and EnableLogs. #5671 also removed the sdk parameter from SentryStructuredLogger and made the structured logger provider fixtures use the host options types, which now default to logs off. Drop the stale argument and opt the fixtures in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
) sentry-dotnet 7.0.0 is out, and the onboarding installs it because it takes the version from the release registry. Two things in the .NET onboarding break with it. 7.0.0 removed `SentryOptions.EnableLogs` (getsentry/sentry-dotnet#5642). With Logs selected, the .NET, ASP.NET, WinForms and WPF snippets set it in `SentrySdk.Init`. So does the .NET Logs onboarding, which the Explore Logs tab shows until a project sends logs. None of these compile now. The compiler reports CS1061. The Logs onboarding and the Metrics onboarding tell every .NET platform to install the core `Sentry` package at the latest version. On an app whose platform package is still 6.x, that puts `Sentry` 7.0.0 next to it, for example next to `Sentry.AspNetCore` 6.12.1. That app builds with no warnings and crashes at startup with a `MissingMethodException`. With this PR: - `dotnet`, `dotnet-aspnet`, `dotnet-winforms` and `dotnet-wpf` no longer set `EnableLogs`. In 7.0.0, `SentrySdk.Logger` sends logs without it. - `dotnet-aspnetcore`, `dotnet-awslambda`, `dotnet-gcpfunctions` and `dotnet-maui` keep `EnableLogs`, because their `UseSentry` options still have it. Its comment now says what it does. It sends `ILogger` entries to Sentry as logs. - The verify step on those four platforms logs through `ILogger`. `SentrySdk.Logger` logs arrive whether `EnableLogs` is on or off, so the old step didn't check the setting. The step logs an information entry and a warning. It doesn't log an error, because `ILogger` entries at `Error` and above also create an issue. Where the snippet logs through a bare `logger`, the text says it is an `ILogger<T>` taken from dependency injection. - The Logs onboarding takes a `logger` option, the same way the Logs onboarding for JS, Go and Ruby takes options. The four platforms above pass it and get the `EnableLogs` text and the `ILogger` verify step. Their Configure step says to set `EnableLogs` in the `UseSentry` callback or in `appsettings.json`, and shows the code for both. Google Cloud Functions has no `UseSentry` call, so its text and code show only `appsettings.json`. The other platforms get the `SentrySdk.Init` setup without `EnableLogs`, with a note that 6.x needed the option and that it has to go when upgrading. The Logs onboarding gives 6.0.0 as the minimum version, not 5.14.0. On 5.x the option and the logger were under `Experimental`, so the snippets shown don't compile there. - The Logs onboarding and the Metrics onboarding install the package that the platform's getting-started page installs: `Sentry.AspNetCore` for ASP.NET Core and AWS Lambda, `Sentry.AspNet`, `Sentry.Maui` and `Sentry.Google.Cloud.Functions`. Each of these platforms passes the same package to both. `dotnet`, `dotnet-winforms` and `dotnet-wpf` still install `Sentry`. - The Logs onboarding links ASP.NET Core, AWS Lambda and MAUI to the guide's logs page. The generic .NET page it linked before doesn't cover `EnableLogs`. Google Cloud Functions has no logs page in the docs yet, so it keeps the generic link. - On the four `UseSentry` platforms, the Metrics onboarding's verify step shows only the `SentrySdk.Metrics` calls. It used to show a `SentrySdk.Init` call as well, which would initialize the SDK a second time in an app the host already initializes. - ASP.NET Core calls `builder.UseSentry(...)` on the `WebApplicationBuilder`. That overload returns the builder, so the note about keeping `builder.Build()` on its own line is gone. The overload is new in 7.0.0, so the step says that `Sentry.AspNetCore` 6.x needs `builder.WebHost.UseSentry`. - Every `getPackageVersion` fallback under `dotnet*` is 7.0.0. These versions only show when the release registry can't be reached. The `Sentry.EntityFramework` line on ASP.NET now takes its version from the `sentry.dotnet.ef` registry entry, not `sentry.dotnet.aspnet`. I left `dotnet-xamarin` alone, because `Sentry.Xamarin` ships from getsentry/sentry-xamarin with its own versions. The snippets can't be compiled in CI, so I checked them against the 7.0.0 packages by hand: - The ASP.NET Core snippet and the Logs onboarding's `SentrySdk.Init` snippet compile. I ran them with an HTTP handler that captured what the SDK sent. In ASP.NET Core, `ILogger` entries arrived as logs with `EnableLogs = true` and didn't with it off. `LogError` also sent an event, and `LogWarning` didn't. With `SentrySdk.Init`, `SentrySdk.Logger` logs arrived without any option. - A `dotnet new web` app with `Sentry.AspNetCore` 6.12.1 and `Sentry` 7.0.0 reproduces the startup crash. With `o.EnableLogs = true` in code it fails earlier, at build, with CS1061. For each change to the code in a snippet, one spec fails if the change is reverted. Changes to comments, prose and fallback versions have no spec. Each platform that passes options to the Logs or Metrics onboarding has one spec for each of them that fails if one of its options is dropped or its registry key is wrong. Refs getsentry/sentry-dotnet#5700 --------- Co-authored-by: Claude Opus 5.5 <[email protected]>

Refs #5183
On
version7, #5504 madeSentryOptions.EnableLogsignored, so ASP.NET Core, Google Cloud Functions, MAUI and Blazor WebAssembly apps send everyILoggerentry to Sentry as a log. These integrations add Sentry.Extensions.Logging on the user's behalf, so installing them isn't consent to send logs. This PR brings back their opt-in, with the same default as 6.x, and removes the global option, which the logs spec dropped in 3.0.0.SentryAspNetCoreOptions,SentryMauiOptionsandSentryBlazorOptionsget anEnableLogsproperty that defaults tofalse. Users opt in withoptions.EnableLogs = trueor"Sentry": { "EnableLogs": true }, as in 6.x.SentryStructuredLogger.IsEnabledreads the setting from the hub's options.Logging.AddSentry()on a hub created bySentrySdk.Initis a plain logging integration, so its logs stay on, as with Serilog, NLog and Log4Net.SentrySdk.Loggerdoesn't change.Breaking changes
SentryOptions.EnableLogsis removed, as agreed with @jamescrosswell. Only the integrations that add theILoggerprovider for the user need the option, so it now lives on their options classes.options.EnableLogs = truefromSentrySdk.Init.SentrySdk.Loggerand the logging integrations always send logs.EnableLogsonSentryAspNetCoreOptions,SentryMauiOptionsorSentryBlazorOptionskeeps working.SentryOptionsand setsEnableLogsno longer compiles. Give it the host options type instead. Before this change, that code compiled and silently left logs off.Notes for review
SentryBlazorOptions, so the setting reaches the logger. Three tests inWebAssemblyHostBuilderExtensionsTestscheck the default and the opt-in in code and in configuration.IntegrationMockedBackgroundWorkerrun a realUseSentryhost. They check that no logs go out by default, and that logs go out whenEnableLogsis set in code or in theSentryconfiguration section.EnableLogsand forwards it to an internal flag onSentryHostOptions. A future host that derives from it, like the generic host in Add a non-logging way to initialise Sentry in generic host apps #5572, gets the public setting only if it declares one. Moving a public property offSentryHostOptionsafter v7 ships would break binary compatibility, so this settles it now.builder.Logging.AddSentry()doesn't opt in by itself. It registers a second provider, and the host'sEnableLogscontrols both.LogWarning_ExplicitLoggingAddSentry_NoLogSentcovers it. WithEnableLogson, such an app sends each log twice, and even with it off, each error and breadcrumb is captured twice. That comes from the double registration, which also happens onmain, and UseSentry plus Logging.AddSentry() captures each error, breadcrumb and log twice #5677 covers it.SentryTarget.EnableLogsstays, obsolete and ignored. Without it, an app that upgrades withenableLogsstill inNLog.configandthrowConfigExceptionson loses its whole NLog configuration, the failure fix(nlog): report a stale dsn and accept initializeSdk=false #5652 fixed forinitializeSdk.LoadConfiguration_WithEnableLogs_DoesNotThrowcovers both values. The target now has its own obsolete message, becauseSentryOptions.ObsoleteEnableLogsis gone.EnableLogsunderLogging:Sentry. That now fails at startup with a message that points to theSentrysection, since feat(mel)!: the Microsoft.Extensions.Logging integration no longer initializes the SDK #5595.IsEnabledruns on everyILoggercall. The check adds about 4 ns and allocates nothing, measured with BenchmarkDotNet throughHubAdapterwith host options and logs on.EnableLogson brings the duplicate back, so the docs need to mention it.🤖 Generated with Claude Code