Skip to content

Commit 13dc30d

Browse files
feat: Logs are always enabled and SentryOptions.EnableLogs is ignored (#5504)
* feat: Logs are always enabled and `SentryOptions.EnableLogs` is ignored 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> * Remove redundant comments Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com> * ref: Create a disabled structured logger for a disabled Hub 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> * test: Update Versioning snapshots for net8.0/net9.0 `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> * test: Assert only on transactions in PreFlightIgnoresTransaction 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> * Revert "ref: Create a disabled structured logger for a disabled Hub" This reverts commit 12ec118. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent a4e3ca3 commit 13dc30d

68 files changed

Lines changed: 412 additions & 218 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎benchmarks/Sentry.Extensions.Logging.Benchmarks/SentryStructuredLoggerBenchmarks.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public void Setup()
1919
SentryLoggingOptions options = new()
2020
{
2121
Dsn = DsnSamples.ValidDsn,
22-
EnableLogs = true,
2322
};
2423
options.SetBeforeSendLog((SentryLog log) =>
2524
{

‎samples/Sentry.Samples.AspNetCore.Basic/Program.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
// Configure the minimum Log Level of Breadcrumbs and Events
2020
options.MinimumBreadcrumbLevel = LogLevel.Information;
2121
options.MinimumEventLevel = LogLevel.Error;
22-
23-
// This option enables Logs sent to Sentry
24-
// Configure the minimum Log Level of Structured-Logs via e.g. "appsettings.json" and "appsettings.{HostEnvironment}.json"
25-
options.EnableLogs = true;
2622
});
2723

2824
var app = builder.Build();

‎samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"DiagnosticLevel": "Error",
2424
"DefaultTags": {
2525
"default-key-in-config": "default-value"
26-
},
27-
// Record log messages as Structured Logs (configure via "Logging" section)
28-
"EnableLogs": true
26+
}
2927
},
3028
"Logging": {
3129
"IncludeScopes": false,

‎samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"DiagnosticLevel": "Error",
2424
"DefaultTags": {
2525
"default-key-in-config": "default-value"
26-
},
27-
// Record log messages as Structured Logs (configure via "Logging" section)
28-
"EnableLogs": true
26+
}
2927
},
3028
"Logging": {
3129
"LogLevel": {

‎samples/Sentry.Samples.GenericHost/appsettings.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//"Dsn": "TODO: Configure your DSN here and uncomment this line",
1414
"MinimumBreadcrumbLevel": "Debug",
1515
"MinimumEventLevel": "Warning",
16-
"SendDefaultPii": true, // Send user name and machine name
17-
"EnableLogs": true // Send structured logs
16+
"SendDefaultPii": true // Send user name and machine name
1817
}
1918
}

‎samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//"Dsn": "TODO: Configure your DSN here and uncomment this line",
1414
"MaxRequestBodySize": "Always",
1515
"SendDefaultPii": true,
16-
"EnableTracing": true,
17-
"EnableLogs" : true
16+
"EnableTracing": true
1817
}
1918
}

‎samples/Sentry.Samples.ME.AI.AspNetCore/Program.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
options.DiagnosticLevel = SentryLevel.Debug;
1515
options.SampleRate = 1;
1616
options.TracesSampleRate = 1.0;
17-
options.EnableLogs = true;
1817
});
1918

2019
// This sample uses Microsoft.Extensions.AI.OpenAI

‎samples/Sentry.Samples.ME.Logging/Program.cs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
options.MinimumBreadcrumbLevel = LogLevel.Information; // It requires at least this level to store breadcrumb
2525
options.MinimumEventLevel = LogLevel.Error; // This level or above will result in event sent to Sentry
2626

27-
// This option enables Logs sent to Sentry.
28-
options.EnableLogs = true;
2927
options.SetBeforeSendLog(static log =>
3028
{
3129
log.SetAttribute("attribute-key", "attribute-value");

‎samples/Sentry.Samples.Maui/MauiProgram.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public static MauiApp CreateMauiApp()
3535
options.AttachScreenshot = true;
3636

3737
options.Debug = true;
38-
options.EnableLogs = true;
3938
options.SampleRate = 1.0F;
4039

4140
// The Sentry MVVM Community Toolkit integration automatically creates traces for async relay commands,
@@ -79,7 +78,7 @@ public static MauiApp CreateMauiApp()
7978
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
8079
});
8180

82-
// Configure Logging, including Structured Logs sent to Sentry (see 'EnableLogs = true')
81+
// Configure Logging, including Structured Logs sent to Sentry
8382
builder.Logging.AddFilter(null, LogLevel.Warning);
8483
builder.Logging.AddFilter("Sentry.Samples.Maui", LogLevel.Information);
8584

‎samples/Sentry.Samples.NLog/NLog.config‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
ignoreEventsWithNoException="False"
2323
includeEventDataOnBreadcrumbs="False"
2424
includeEventPropertiesAsTags="True"
25-
minimumEventLevel="Error"
26-
enableLogs="True">
25+
minimumEventLevel="Error">
2726

2827
<!-- Advanced options can be configured here-->
2928
<options

0 commit comments

Comments
 (0)