Skip to content

feat: Logs are always enabled and SentryOptions.EnableLogs is ignored - #5504

Merged
jamescrosswell merged 7 commits into
version7from
feat/remove-enable-logs-5479
Sep 10, 2026
Merged

jamescrosswell merged 7 commits into
version7from
feat/remove-enable-logs-5479

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

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 enableLogs outright. Here it's marked [Obsolete] and ignored instead, which keeps this source- and binary-compatible — nobody's build breaks, nobody's appsettings.json stops binding:

  • SentryOptions.EnableLogs and SentryTarget.EnableLogs (NLog) — getter always returns true, setter is a no-op.
  • BindableSentryOptions.EnableLogs still binds, so an existing "EnableLogs": true in configuration is accepted and ignored rather than throwing.
  • The enableLogs parameter on the Serilog WriteTo.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

  • Changelog. scripts/verify-changelog.sh fails PRs that add a manual ## Unreleased section, so the rationale the issue asks for lives in this description and the commit body rather than in CHANGELOG.md. Happy to add a hand-written note at release time if you'd rather it be in the file.
  • Serilog.SentrySink.IsEnabled is gone. It short-circuited Emit when an event was below both the breadcrumb and event minimums and logs were off. With logs always on, it could only ever return true, so it was removed rather than left as a vacuous check.
  • Three tests changed meaning, not just setup, because "nothing is sent" is no longer true once logs are on by default:
    • WebIntegrationTests.PreFlightIgnoresTransaction now asserts no non-log envelope items, which is what #1835 was actually about.
    • Google.Cloud.Functions.IntegrationTests.SentryIntegrationTest_CaptureUnhandledException asserted the sentry.dotnet.google-cloud-function SDK name on every request; it now asserts it on the envelopes carrying the error. The SDK-name override is an ISentryEventProcessor, so it doesn't apply to log envelopes — pre-existing for anyone who had EnableLogs = true, but now visible by default. Worth a follow-up if we want log envelopes attributed to the wrapping SDK.
    • Several Verify snapshots gain a log envelope. Only the DotNet10_0 variants 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/log4net Simple and ApiApprovalTests snapshots (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.
  • Native Cocoa's own enableLogs is untouched. We never set it from the managed side, so native Cocoa logging stays as it was.

🤖 Generated with Claude Code

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>
Comment thread samples/Sentry.Samples.AspNetCore.Basic/Program.cs Outdated
Comment thread samples/Sentry.Samples.Console.Basic/Program.cs Outdated
Comment thread samples/Sentry.Samples.ME.Logging/Program.cs Outdated
Comment thread samples/Sentry.Samples.Serilog/Program.cs Outdated
Comment thread src/Sentry/SentryStructuredLogger.cs
Comment thread test/Sentry.AspNetCore.Tests/WebIntegrationTests.verify.cs Outdated
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,

@jamescrosswell jamescrosswell Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jamescrosswell jamescrosswell Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

jamescrosswell and others added 3 commits August 24, 2026 21:19
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

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (version7@d589ac5). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/Sentry.Log4Net/SentryAppender.cs 50.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jamescrosswell and others added 2 commits August 25, 2026 10:19
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>
@jamescrosswell
jamescrosswell marked this pull request as ready for review August 25, 2026 00:51
@github-actions github-actions Bot added the risk: high PR risk score: high label Aug 25, 2026
@jamescrosswell jamescrosswell added the Next Major Changes scheduled for the next Major release. label Aug 26, 2026
@jamescrosswell jamescrosswell added this to the 7.0.0 milestone Aug 26, 2026
@jamescrosswell

Copy link
Copy Markdown
Collaborator Author

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:

  • Phase 1 — now (feat: Logs sent via SentrySdk.Logger no longer require EnableLogs #5512). EnableLogs is ignored for logs created directly via SentryStructuredLogger / SentrySdk.Logger. Non-breaking, so it can ship in a minor. The whole change is one branch in SentryStructuredLogger.Create; the logging integrations gate on EnableLogs before calling hub.Logger.CaptureLog, so they sit in front of that gate and are untouched — no Verify snapshot or API-approval file moves.
  • Phase 2 — 7.0.0 (this PR). Removing the option outright and taking the gate out of the four logging integrations. Breaking, and more nuanced than it looked: those integrations instrument a general-purpose ILogger-style surface where configuring logging says much less about whether you want the logs in Sentry, and each produces breadcrumbs and events and structured logs from one call.

Everything here still applies to phase 2 and CI was green at 47c133d, so this should be a case of rebasing onto main when 7.0.0 comes around rather than rewriting. The review threads are all resolved and the findings are worth keeping — in particular #5506 (logs and metrics not attributed to the wrapping SDK), which phase 2 will surface again.

@jamescrosswell
jamescrosswell marked this pull request as draft August 26, 2026 23:55
@jamescrosswell
jamescrosswell changed the base branch from main to version7 September 7, 2026 01:08
…e-logs-5479

# Conflicts:
#	src/Sentry/BindableSentryOptions.cs
#	src/Sentry/SentryOptions.cs
#	test/Sentry.Tests/HubTests.cs
#	test/Sentry.Tests/SentryStructuredLoggerTests.cs
@jamescrosswell
jamescrosswell marked this pull request as ready for review September 9, 2026 23:06

@lucas-zimerman lucas-zimerman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jamescrosswell
jamescrosswell merged commit 13dc30d into version7 Sep 10, 2026
42 checks passed
@jamescrosswell
jamescrosswell deleted the feat/remove-enable-logs-5479 branch September 10, 2026 22:21
jamescrosswell added a commit that referenced this pull request Sep 14, 2026
#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>
jamescrosswell added a commit that referenced this pull request Sep 14, 2026
#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>
jamescrosswell added a commit that referenced this pull request Sep 16, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Next Major Changes scheduled for the next Major release. risk: high PR risk score: high

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Remove SentryOptions.EnableLogs

2 participants