feat: Logs are always enabled and SentryOptions.EnableLogs is ignored - #5504
feat: Logs are always enabled and SentryOptions.EnableLogs is ignored#5504jamescrosswell wants to merge 6 commits into
SentryOptions.EnableLogs is ignored#5504Conversation
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 @@
## main #5504 +/- ##
==========================================
- Coverage 74.87% 74.78% -0.09%
==========================================
Files 513 513
Lines 18659 18749 +90
Branches 3636 3665 +29
==========================================
+ Hits 13970 14022 +52
- Misses 3819 3857 +38
Partials 870 870 ☔ 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.
Resolves #5479
Summary
Aligns the .NET SDK with the other SDKs (see sentry-cocoa #8769) by removing the explicit opt-in for logs.
Adding one of the logging integrations —
Sentry.Extensions.Logging,Sentry.Serilog,Sentry.NLog,Sentry.Log4Net— is already an explicit statement that you want your logs in Sentry. RequiringEnableLogs = trueon top of that was just an extra hoop, so every branch that gated on the option now assumes it'strueand structured logs are captured unconditionally.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