Skip to content

Commit 613a18d

Browse files
authored
fix(logs)!: minimum Log-Level for Structured Logs (#4700)
1 parent ac97aef commit 613a18d

File tree

48 files changed

+689
-213
lines changed

Some content is hidden

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

48 files changed

+689
-213
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,23 @@
22

33
## Unreleased
44

5+
### BREAKING CHANGES
6+
7+
- Remove `SentryLoggingOptions.ExperimentalLogging.MinimumLogLevel`. _Structured Logs_ can now be configured via the `"Sentry"` logging provider (e.g. in `appsettings.json` and `appsettings.{HostEnvironment}.json`) ([#4700](https://github.com/getsentry/sentry-dotnet/pull/4700))
8+
- All logging provider types are _internal_ now in order to ensure configuration as intended ([#4700](https://github.com/getsentry/sentry-dotnet/pull/4700))
9+
10+
### Features
11+
12+
- Add support for _Structured Logs_ in `Sentry.Google.Cloud.Functions` ([#4700](https://github.com/getsentry/sentry-dotnet/pull/4700))
13+
514
### Fixes
615

16+
- Minimum Log-Level for _Structured Logs_, _Breadcrumbs_ and _Events_ in all Logging-Integrations ([#4700](https://github.com/getsentry/sentry-dotnet/pull/4700))
17+
- for `Sentry.Extensions.Logging`, `Sentry.AspNetCore`, `Sentry.Maui` and `Sentry.Google.Cloud.Functions`
18+
- the Logger-Provider for _Breadcrumbs_ and _Events_ ignores Logging-Configuration (e.g. via `appsettings.json`)
19+
- use the intended `SentryLoggingOptions.MinimumBreadcrumbLevel`, `SentryLoggingOptions.MinimumEventLevel`, or add filter functions via `SentryLoggingOptionsExtensions.AddLogEntryFilter`
20+
- the Logger-Provider for _Structured Logs_ respects Logging-Configuration (e.g. via `appsettings.json`)
21+
- when enabled by `SentryOptions.EnableLogs`
722
- Avoid appending `/NODEFAULTLIB:MSVCRT` to NativeAOT linker arguments on Windows when targetting non-Windows platforms (Android, Browser) ([#4760](https://github.com/getsentry/sentry-dotnet/pull/4760))
823

924
## 6.0.0-rc.2

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public void Setup()
2323
{
2424
Dsn = DsnSamples.ValidDsn,
2525
EnableLogs = true,
26-
ExperimentalLogging =
27-
{
28-
MinimumLogLevel = LogLevel.Information,
29-
}
3026
};
3127
options.SetBeforeSendLog((SentryLog log) =>
3228
{

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
options.Debug = true;
1717
#endif
1818

19-
// This option enables Logs sent to Sentry.
19+
// Configure the minimum Log Level of Breadcrumbs and Events
20+
options.MinimumBreadcrumbLevel = LogLevel.Information;
21+
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"
2025
options.EnableLogs = true;
2126
});
2227

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
},
7+
"Sentry": {
8+
"LogLevel": {
9+
"Default": "Trace"
10+
}
11+
}
12+
},
13+
"AllowedHosts": "*"
14+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323
"DiagnosticLevel": "Error",
2424
"DefaultTags": {
2525
"default-key-in-config": "default-value"
26-
}
26+
},
27+
// Record log messages as Structured Logs (configure via "Logging" section)
28+
"EnableLogs": true
2729
},
2830
"Logging": {
2931
"IncludeScopes": false,
3032
"LogLevel": {
3133
"Default": "Trace"
34+
},
35+
// Configure the "Sentry" provider for Structured Logs
36+
"Sentry": {
37+
"LogLevel": {
38+
"Default": "Information"
39+
}
3240
}
3341
},
3442
"Kestrel": {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323
"DiagnosticLevel": "Error",
2424
"DefaultTags": {
2525
"default-key-in-config": "default-value"
26-
}
26+
},
27+
// Record log messages as Structured Logs (configure via "Logging" section)
28+
"EnableLogs": true
2729
},
2830
"Logging": {
2931
"LogLevel": {
3032
"Default": "Information",
3133
"Microsoft.AspNetCore": "Warning"
34+
},
35+
// Configure the "Sentry" provider for Structured Logs
36+
"Sentry": {
37+
"LogLevel": {
38+
"Default": "Warning"
39+
}
3240
}
3341
},
3442
"AllowedHosts": "*"

samples/Sentry.Samples.GenericHost/SampleHostedService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ internal class SampleHostedService(IHub hub, ILogger<SampleHostedService> logger
77
{
88
public Task StartAsync(CancellationToken cancellationToken)
99
{
10+
// Configure structured logging via appsettings.json (Logging:Sentry:LogLevel:)
11+
logger.LogTrace("LogLevel.Trace is not configured to be sent as structured log");
1012
// Logging integration by default keeps informational logs as Breadcrumb
1113
logger.LogInformation("Starting sample hosted service. This goes as a breadcrumb");
1214
// You can also add breadcrumb directly through Sentry.Hub:

samples/Sentry.Samples.GenericHost/appsettings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
"Logging": {
33
"LogLevel": {
44
"Default": "Trace"
5+
},
6+
"Sentry": {
7+
"LogLevel": {
8+
"Default": "Information" // Configure structured logs
9+
}
510
}
611
},
712
"Sentry": {
813
//"Dsn": "TODO: Configure your DSN here and uncomment this line",
914
"MinimumBreadcrumbLevel": "Debug",
1015
"MinimumEventLevel": "Warning",
11-
"SendDefaultPii": true // Send user name and machine name
16+
"SendDefaultPii": true, // Send user name and machine name
17+
"EnableLogs": true // Send structured logs
1218
}
1319
}

samples/Sentry.Samples.Google.Cloud.Functions/Function.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
public class Function : IHttpFunction
1313
{
1414
private readonly ILogger<Function> _logger;
15+
1516
public Function(ILogger<Function> logger) => _logger = logger;
1617

1718
public Task HandleAsync(HttpContext context)
1819
{
20+
// Configure structured logging via appsettings.json (Logging:Sentry:LogLevel:)
21+
_logger.LogTrace("LogLevel.Trace is not configured to be sent as structured log");
22+
23+
// Logging integration by default keeps informational logs as Breadcrumb
1924
_logger.LogInformation("Useful info that is added to the breadcrumb list.");
25+
26+
// Results in an Event/Error in Sentry, including the Breadcrumb from above
2027
throw new Exception("Bad function");
2128
}
2229
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug"
5+
},
6+
"Sentry": {
7+
"LogLevel": {
8+
"Default": "Information"
9+
}
10+
}
11+
},
212
"Sentry": {
313
//"Dsn": "TODO: Configure your DSN here and uncomment this line",
414
"MaxRequestBodySize": "Always",
515
"SendDefaultPii": true,
6-
"EnableTracing": true
16+
"EnableTracing": true,
17+
"EnableLogs" : true
718
}
819
}

0 commit comments

Comments
 (0)