feat: Logs are always enabled and SentryOptions.EnableLogs is ignored - #5504
Conversation
Adding one of the logging integrations (`Sentry.Extensions.Logging`, `Sentry.Serilog`, `Sentry.NLog`, `Sentry.Log4Net`) is already an explicit opt-in to sending logs, so requiring `EnableLogs = true` on top of that was just an extra hoop. Structured logs are now captured unconditionally. `SentryOptions.EnableLogs` and `SentryTarget.EnableLogs` are marked obsolete rather than removed: the getters always return `true`, the setters are ignored, and existing configuration (including `"EnableLogs"` in appsettings.json and `enableLogs` on the Serilog sink) still binds without error. To drop logs, use `SetBeforeSendLog` and return `null`. Resolves #5479 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
| Assert.True(requests.Any(p => p.Contains(ExpectedMessage)), | ||
| "Expected error to be captured"); | ||
| Assert.True(requests.All(p => p.Contains("sentry.dotnet.google-cloud-function")), | ||
| // Structured logs are always captured, and those envelopes carry the ASP.NET Core SDK name, |
There was a problem hiding this comment.
The sentry.dotnet.google-cloud-function SDK name is applied by SentryGoogleCloudFunctionEventProcessor, an ISentryEventProcessor - so it's not being applied to logs (they're not events).
This was true before but with logs on by default, it's now visible.
For this PR, assertion scoped to the envelopes carrying the error, which is what it was checking in substance. It does need fixing properly though.
There was a problem hiding this comment.
Opened #5506 for this.
Events, logs and metrics each read their SdkVersion from a different source (event-processor chain / the registered ILoggerProvider / scope.Sdk), so an integration that overrides only the event path gets the other two wrong. Sentry.AspNetCore.Grpc has the same issue as Google Cloud Functions, and Sentry.AspNet does too (though only with a logging integration wired up).
MAUI and the Serilog/NLog/log4net sinks are fine — maybe a model to copy there.
Leaving the scoped assertion here so as not to block this PR.
Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
Belt-and-braces: `DefaultSentryStructuredLogger` asserts `hub.IsEnabled`, so `Create` now honours that by construction and returns the disabled logger otherwise. Restores the disabled-path coverage that the `EnableLogs` test removed, keyed off the Hub instead of the option. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`WebIntegrationTests.Versioning` has per-TFM snapshots; only the net10.0 one was regenerated locally (no net8/net9 runtimes on the dev machine). Taken byte-for-byte from the CI artifacts, which produced an identical delta on every platform. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## version7 #5504 +/- ##
===========================================
Coverage ? 74.68%
===========================================
Files ? 515
Lines ? 18899
Branches ? 3687
===========================================
Hits ? 14115
Misses ? 3901
Partials ? 883 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Review feedback: the hub isn't disabled, so logs are captured as usual — excluding logs was the wrong way round. Assert directly that no transaction envelope item is sent, which is the only thing the test needs to show. Uses the existing EnvelopeItem.TryGetType() and TypeValueTransaction rather than a hand-rolled header lookup. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This reverts commit 12ec118.
|
Superseded in part by #5512, and converting this back to a draft so it doesn't merge by accident. Per updated guidance, #5479 is being split into two phases:
Everything here still applies to phase 2 and CI was green at 47c133d, so this should be a case of rebasing onto |
…e-logs-5479 # Conflicts: # src/Sentry/BindableSentryOptions.cs # src/Sentry/SentryOptions.cs # test/Sentry.Tests/HubTests.cs # test/Sentry.Tests/SentryStructuredLoggerTests.cs
#5504 was branched before #5529 added the DotNet11_0 snapshots, so when both merged into version7 the DotNet11_0 copies never picked up #5504's changes (the [Obsolete] on EnableLogs, and the extra envelope item in WebIntegrationTests.Versioning). version7 has been failing these three tests on net11.0 on every platform since. The new files are the .received.txt files from CI, which are identical across linux, macOS and Windows and to the DotNet10_0 snapshots. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
#5504 (logs always enabled) landed on version7 after this branch was cut and updated the logging snapshots for net8.0, net9.0 and net10.0 but not net11.0, which failed the Linux jobs once this PR was tested merged with version7. Regenerated locally for net11.0. Each diff is the same added lines #5504 made to the DotNet10_0 snapshot: the [Obsolete] on EnableLogs in the Sentry and Sentry.NLog API approvals, and the extra envelope item in WebIntegrationTests.Versioning. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* feat: add support for .NET 11 RC 1 Bumps the SDK, workload set and prerelease Microsoft.* package references from preview 7 to RC 1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(android): drop TombstoneParser.parse(Tombstone) from the bindings The android 37 (RC 1) binding generator keeps methods whose parameter types are unbound, where android 36 dropped them before the Metadata.xml transforms ran. epitaph is referenced with Bind="false", so the generated binding emitted an unresolvable global::Com.Abovevacant.Epitaph.Core.Tombstone (CS0400), failing every job that builds the Android bindings. Scoped to net11.0+ via an explicit TransformFile Remove, because the Android SDK auto-globs Transforms/**/*.xml into every TFM and the entry would warn BG8A00 on android 36, where the node no longer exists by transform time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(maui): cast gesture breadcrumb collection expressions to a concrete array The RC 1 SDK ships a CsWinRT that rejects a collection expression whose target is a non-mutable interface type (CsWinRT1032), because the type the compiler synthesises isn't trim/AOT-safe for WinRT. BreadcrumbEvent's extraData is params IEnumerable<(string key, string value)>, so the four gesture breadcrumbs tripped it on both -windows TFMs. Verified by building src/Sentry.Maui for net10.0-windows under each SDK: 8 errors under RC 1, 0 under preview 7. Casting to a concrete array clears it without touching the public BreadcrumbEvent signature. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * build: demote IL2037 to a warning; document the .NET 11 RC 1 breakages MAUI 11 RC 1 emits 154 IL2037s from its own Compatibility handler descriptors when linking an Apple app, and ILLinkTreatWarningsAsErrors defaults to TreatWarningsAsErrors, so those failed the build. Verified as an RC 1 regression by rebuilding Sentry.Samples.Maui for net11.0-maccatalyst under each SDK: 154 under RC 1, 0 under preview 7. Demoted rather than silenced so it stays visible and gets removed when MAUI fixes the descriptors. We ship no ILLink descriptors of our own, so every IL2037 is external; Sentry.TrimTest and Sentry.MauiTrimTest opt out of Directory.Build.props, so the "Trim analysis" job keeps the strict setting. Also extends the CONTRIBUTING upgrade checklist, as that section asks: rows for the three failures this bump hit (CS0400, CsWinRT1032, IL2037), the two traps that make a local samples build misleading, and the global.json swap that distinguishes a toolchain regression from local noise. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(apple): upload framework symbols from the renamed trimmer output dir Sentry.targets collected the framework assemblies' PDBs (Microsoft.iOS, Microsoft.Maui.*) from $(IntermediateOutputPath)linked. .NET 11 RC 1 renamed that directory to postprocessed-assemblies, and because the glob is Exists()-guarded it started failing silently - no error, just six fewer debug files uploaded and no symbolication for framework frames. This ships in buildTransitive, so it affects any customer building a .NET 11 Apple app with Sentry, not just this repo. Same class of bug as the Native AOT _CopyAotSymbols breakage in #5529. Verified on the same project, TFM and RID under each SDK: preview 7 produces linked/ with 11 PDBs and no postprocessed-assemblies; RC 1 produces postprocessed-assemblies with the identical 11 and no linked/. The two names are mutually exclusive per SDK, so probing both double-counts nothing. Caught by integration-test/cli.Tests.ps1, which asserts the exact upload set. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * ci: run the win-arm64 .NET job on the Visual Studio 2026 runner image The Native AOT integration test failed on win-arm64 with LNK1322 (Cortex-A53 erratum 843419). dotnet/runtime#133835 identified it as VS 2022's linker: .NET 10+ requires Visual Studio 2026, whose linker no longer applies that check. windows-11-arm only has VS 2022 (MSVC 14.44); windows-11-vs2026-arm has VS 2026 (MSVC 14.51). Verified in a standalone repro: the same failing build links on windows-11-vs2026-arm and still fails on windows-11-arm (jamescrosswell/dotnet-nativeaot-lnk1322-repro, run 34805799061). build-sentry-native stays on windows-11-arm on purpose. The sentry-native.lib it compiles ships in the package, and MSVC libraries can only be linked by a toolset at least as new as the one that built them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * test: update net11.0 snapshots for #5504 #5504 (logs always enabled) landed on version7 after this branch was cut and updated the logging snapshots for net8.0, net9.0 and net10.0 but not net11.0, which failed the Linux jobs once this PR was tested merged with version7. Regenerated locally for net11.0. Each diff is the same added lines #5504 made to the DotNet10_0 snapshot: the [Obsolete] on EnableLogs in the Sentry and Sentry.NLog API approvals, and the extra envelope item in WebIntegrationTests.Versioning. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * ci: move Windows jobs to VS 2026 images, pin sentry-native to the VS 2022 toolset GitHub is moving hosted Windows runners to Visual Studio 2026: windows-latest already runs the VS 2026 image and windows-11-arm follows between September 21 and 30 (actions/runner-images#14602). Use the explicit VS 2026 labels for every Windows job rather than relying on those labels changing underneath us. The shipped sentry-native.lib is the exception: VS 2022 can't link a library built with VS 2026's MSVC, and VS 2022 is still supported for .NET 8 and 9. The VS 2026 images still install the VS 2022 toolset (MSVC 14.44), so build-sentry-native.ps1 selects it with -T v143. The reasoning is in #5566 (comment). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * More concise comments Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com> * fix(maui): restore the array cast in OnPanGesture The comment edit in 8ba1bc7 replaced the cast instead of preceding it, so OnPanGesture's collection expression failed CsWinRT1032 on the -windows TFMs. Also shortens the remaining binding-transform comments. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Apply suggestion from @jamescrosswell * docs: move local-verification tips out of CONTRIBUTING Removes the samples/global.json debugging notes from CONTRIBUTING.md, which is for humans, and keeps the two generic points as short bullets in AGENTS.md. Also drops PR-specific details from the upgrade table rows. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Resolves #5479
Summary
Aligns the .NET SDK with the other SDKs (see sentry-cocoa #8769) by removing the explicit opt-in for logs.
If someone adds any of the logging integrations —
Sentry.Extensions.Logging,Sentry.Serilog,Sentry.NLog,Sentry.Log4Net— this is taken as a sign that they want logs in Sentry. If people want to disable logs, they can filter these out via the configuration for ILogger etc.Deprecate rather than remove
Cocoa deleted
enableLogsoutright. Here it's marked[Obsolete]and ignored instead, which keeps this source- and binary-compatible — nobody's build breaks, nobody'sappsettings.jsonstops binding:SentryOptions.EnableLogsandSentryTarget.EnableLogs(NLog) — getter always returnstrue, setter is a no-op.BindableSentryOptions.EnableLogsstill binds, so an existing"EnableLogs": truein configuration is accepted and ignored rather than throwing.enableLogsparameter on the SerilogWriteTo.Sentry(...)overloads stays in place (it can't be attributed) but is documented as ignored and no longer applied.The escape hatch for anyone who genuinely wants logs off is
SetBeforeSendLog(log => null)— same guidance Cocoa gives.Notes for review
scripts/verify-changelog.shfails PRs that add a manual## Unreleasedsection, so the rationale the issue asks for lives in this description and the commit body rather than inCHANGELOG.md. Happy to add a hand-written note at release time if you'd rather it be in the file.Serilog.SentrySink.IsEnabledis gone. It short-circuitedEmitwhen an event was below both the breadcrumb and event minimums and logs were off. With logs always on, it could only ever returntrue, so it was removed rather than left as a vacuous check.WebIntegrationTests.PreFlightIgnoresTransactionnow asserts no non-log envelope items, which is what #1835 was actually about.Google.Cloud.Functions.IntegrationTests.SentryIntegrationTest_CaptureUnhandledExceptionasserted thesentry.dotnet.google-cloud-functionSDK name on every request; it now asserts it on the envelopes carrying the error. The SDK-name override is anISentryEventProcessor, so it doesn't apply to log envelopes — pre-existing for anyone who hadEnableLogs = true, but now visible by default. Worth a follow-up if we want log envelopes attributed to the wrapping SDK.DotNet10_0variants could be regenerated locally (no net8/net9 runtimes on this machine), so the rest were updated by hand and CI checked them: the first run confirmed the hand-edited Serilog/NLog/log4netSimpleandApiApprovalTestssnapshots (net8/net9/net48 all green) and caught one family I had missed entirely,WebIntegrationTests.Versioning. Its net8.0/net9.0 snapshots are now taken byte-for-byte from the CI artifacts, which produced an identical delta on all seven platforms.enableLogsis untouched. We never set it from the managed side, so native Cocoa logging stays as it was.🤖 Generated with Claude Code