Skip to content

Conversation

@Flash0ver
Copy link
Member

@Flash0ver Flash0ver commented Nov 6, 2025

Fixes #4539
Fixes #4734


Summary

Previously, the Logging-Configuration was inconsistent between SDKs (M.E.L, ASP.NET Core, MAUI, Google-Cloud-Functions):

  • M.E.L correctly ignores Logging-Configuration for Breadcrumbs and Events
  • ASP.NET Core, MAUI and Google-Cloud-Functions were incorrectly considering Logging-Configuration for Breadcrumbs and Events
  • all (M.E.L, ASP.NET Core and MAUI) were incorrectly ignoring Logging-Configuration for Structured Logs
  • Google-Cloud-Functions did not support Structured Logs

This changeset is normalizing the applied Logging-Filter-Rules across all integrations:
Logging-Configuration (i.e. Logging:LogLevel:Default and Logging:Sentry:LogLevel:Default via e.g. appsettings.json) is now respected for Structured Logs, but now ignored for Breadcrumbs and Events, since we have existing MinimumBreadcrumbLevel and MinimumEventLevel, as well as AddLogEntryFilter extension methods for filtering Breadcrumbs and Events.

New

  • Sentry.Google.Cloud.Functions now supports Structured Logs
    • when enabled via EnableLogs = true

Changed

  • remove SentryLoggingOptions.ExperimentalLogging.MinimumLogLevel for Structured-Logs
    • instead, allow configuration of Structured-Logs via the "Sentry" logging provider name
  • the minimum Log-Level Configuration (appsettings.json) now only applies to Structured Logging
  • the minimum Log-Level Configuration (appsettings.json) no longer applies to Breadcrumbs
    • instead, configure via the already existing SentryLoggingOptions.MinimumBreadcrumbLevel and SentryLoggingOptionsExtensions.AddLogEntryFilter
  • the minimum Log-Level Configuration (appsettings.json) no longer applies to Events
    • instead, configure via the already existing SentryLoggingOptions.MinimumEventLevel and SentryLoggingOptionsExtensions.AddLogEntryFilter
  • made all types that implement ILoggerProvider and IConfigureOptions internal
    • in order to ensure that LoggerFilterRules are correctly set
    • none of the now non-public types were mentioned in sentry-docs
  • SentryStructuredLoggerProvider (and derived for ASP.NET Core and MAUI) now have [ProviderAlias("Sentry")]
    • in order to enable appsettings.json configuration for Structured Logs

Testing

  • added Tests that ensure that the Logging-Filters are correctly setup (via Microsoft.Extensions.Logging.LoggerFilterRule)
    • SentryLoggerProvider (and derived) is NOT configurable via appsettings.json (for Breadcrumbs and Events)
      • by having a related non-null LoggerFilterRule.Filter
    • SentryStructuredLoggerProvider (and derived) IS configurable via appsettings.json (via the "Sentry" logging provider name)
      • with the related LoggerFilterRule.Filter being null
  • added missing tests for consistency between the ILoggerProvider for Breadcrumbs/Events and the ILoggerProvider for Structured Logs

Samples

  • added / updated the appsettings.json of these samples to show how to configure Structured Logs, in contrast to Breadcrumbs and Events
    • Sentry.Samples.AspNetCore.Basic
    • Sentry.Samples.GenericHost
    • Sentry.Samples.Google.Cloud.Functions

Important

This functionality relies on a quirk/feature of Microsoft.Extensions.Logging.LoggerFilterRule. When a filter delegate is configured, filtering via configuration bindings are ignored and only the filtering delegate is applied. When not using a filter delegate, log filtering from configuration bindings does get applied.

@Flash0ver Flash0ver self-assigned this Nov 6, 2025
@Flash0ver Flash0ver added the Logs label Nov 6, 2025
@Flash0ver Flash0ver changed the title fix(logs): fix(logs): minimum Log-Level for Structured Logs Nov 6, 2025
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.91%. Comparing base (ac97aef) to head (b26b3b0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tensions.Logging/SentryStructuredLoggerProvider.cs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4700      +/-   ##
==========================================
+ Coverage   73.85%   73.91%   +0.05%     
==========================================
  Files         485      485              
  Lines       17689    17686       -3     
  Branches     3497     3494       -3     
==========================================
+ Hits        13065    13072       +7     
+ Misses       3762     3756       -6     
+ Partials      862      858       -4     

☔ View full report in Codecov by Sentry.
📢 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.

Base automatically changed from logs/stable to version6 November 9, 2025 21:38
Base automatically changed from version6 to main November 14, 2025 02:30
@Flash0ver
Copy link
Member Author

@sentry review

@Flash0ver Flash0ver marked this pull request as ready for review November 25, 2025 19:35
@Flash0ver Flash0ver marked this pull request as draft November 26, 2025 07:42
Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

Looks great - nice work @Flash0ver !

I suggested a couple of convenience changes, but happy to merge whenever you are.

Flash0ver and others added 3 commits November 28, 2025 13:35
Comment on lines 56 to 65
services.AddSingleton<IConfigureOptions<SentryMauiOptions>, SentryMauiOptionsSetup>();
services.AddSingleton<Disposer>();

builder.Logging.AddFilter<SentryMauiStructuredLoggerProvider>(static (string? categoryName, LogLevel logLevel) =>
{
return categoryName is null
|| categoryName != "Sentry.ISentryClient";
});
// Add a delegate rule in order to ignore Configuration like "appsettings.json" and "appsettings.{HostEnvironment}.json"
builder.Logging.AddFilter<SentryMauiLoggerProvider>(_ => true);
// Add non-delegate rules in order to respect Configuration like "appsettings.json" and "appsettings.{HostEnvironment}.json"
builder.Logging.AddFilter<SentryMauiStructuredLoggerProvider>("Sentry.ISentryClient", LogLevel.None);

// Add default event binders
services.AddSingleton<IMauiElementEventBinder, MauiButtonEventsBinder>();

This comment was marked as outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested it via Sentry.Samples.Maui ... and it works end-to-end.

@Flash0ver Flash0ver merged commit 613a18d into main Dec 1, 2025
35 checks passed
@Flash0ver Flash0ver deleted the logs/fix-configuration branch December 1, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentry Logging should respect the user's global ILogger filter(s). Logging-Configuration is not applied to Sentry-Logger-Provider

3 participants