Skip to content

Logging-Configuration is not applied to Sentry-Logger-Provider #4539

Closed

Description

@Flash0ver

Description

Logging-Configuration (e.g. appsettings.json: Logging:LogLevel:Default) is not applied to Sentry-Logger-Provider

  • Sentry.Extensions.Logging
    • Events & Breacrumbs
    • Structured Logs
  • Sentry.AspNetCore
    • Structured Logs

For Breadcrumbs and Events, the Logging-Configuration is applied in Sentry.AspNetCore.

Also consider and review the Serilog integration (see #4462 (comment)).


Thanks @wondertalik for discovering and reporting the issue.
See #4132 (comment).

Activity

  1. self-assigned this
    on Sep 18, 2025
  2. Flash0ver commented on Sep 24, 2025

    @Flash0ver
    ContributorAuthor

    TIL, when adding a LoggerFilterRule (via AddFilter) we opt-out of the "Minimum-Log-Level-From-Configuration" rule:

    builder.AddFilter<SentryLoggerProvider>(_ => true);

    But just adding a Category and Level, just as via appsettings.json, does not replace the default rule:

    _ = logging.AddFilter<SentryAspNetCoreLoggerProvider>(
    "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware",
    LogLevel.None);

  3. Flash0ver commented on Sep 24, 2025

    @Flash0ver
    ContributorAuthor

    Indeed ... the intended behavior for Structured Logs is to be configurable through "standard" Logging-Configuration, like appsettings.json.
    For Breadcrumbs and Events we have explicit Sentry-Options:

    • Sentry.Extensions.Logging.SentryLoggingOptions.MinimumBreadcrumbLevel
    • Sentry.Extensions.Logging.SentryLoggingOptions.MinimumEventLevel

    But we got different behavior in Sentry.Extensions.Logging and Sentry.AspNetCore

    • Configuration added for Microsoft.Extensions.Logging is ignored and only the options are evaluated.
    • Usually, in ASP.NET Core, there is configuration and this it is included in the IsEnabled-Check (before the options are evaluated).

    For Sentry.Extensions.Logging, see:

    // All logs should flow to the SentryLogger, regardless of level.
    // Filtering of events is handled in SentryLogger, using SentryOptions.MinimumEventLevel
    // Filtering of breadcrumbs is handled in SentryLogger, using SentryOptions.MinimumBreadcrumbLevel
    builder.AddFilter<SentryLoggerProvider>(_ => true);

    Questions:

    Breadcrumbs + Events

    • Should Sentry.Extensions.Logging and all inheriting SDKs (like Sentry.AspNetCore) have the same behavor, or is it intended that there is different behavior?
      • If the behavior should be identical, should it include Configuration, or only consider SentryLoggingOptions?

    Structured Logs

    • Should the behavior be different or identical for Breadcrumbs+Events and Structured Logs?
      • In other words, do we only want Logging-Configuration, like appsettings.json (originally intended)
      • or should we only have a MinimumLogLevel in SentryLoggingOptions
      • or both, where the Logging-Configuration is applied first, and then the SentryLoggingOptions are evaluated
  4. wondertalik commented on Sep 24, 2025

    @wondertalik

    Hi, there.

    Just MinimumLogLevel it's not enough for sure. It's my biggest pain right now. The logs in sentry have a lot of noisy logs. I have diferent level for specific categories, some warning, some information or error. Using opentelemetry and otel collector standard logging configuration give me option filter that before send to anywhere else. But right now sentry is just collecting everything.

    Thanks for your work, btw.

  5. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 24, 2025
  6. 23 remaining items

  7. Flash0ver commented on Oct 7, 2025

    @Flash0ver
    ContributorAuthor

    I'm afraid the Runtime Switch option wouldn't be "clean" either ... but only half-working and half-breaking.
    I do now prefer to ship this change in 6.0.0 (and upcoming pre-releases), due to the inherently behavior-breaking change.

    .NET 10 GA is now roughly one month away.
    However, now having learned more about the nitty-gritty of Microsoft.Extensions.Logging in ASP.NET Core, there may be a temporary workaround for your scenario in the meantime:

    // after invoking `UseSentry` on the ASP.NET Core Web-App-Builder
    builder.Logging.Services.Configure<LoggerFilterOptions>(static (LoggerFilterOptions options) =>
    {
        LoggerFilterRule rule = options.Rules.Single(static (LoggerFilterRule rule) => rule.ProviderName == "Sentry.AspNetCore.SentryAspNetCoreStructuredLoggerProvider");
        bool removed = options.Rules.Remove(rule);
        if (!removed)
        {
            throw new InvalidOperationException("Rule for Sentry's Structured Logs not found.");
        }
    
        rule = new LoggerFilterRule(rule.ProviderName, "Sentry.ISentryClient", LogLevel.None, null);
        options.Rules.Add(rule);
        rule = new LoggerFilterRule(rule.ProviderName, "Sentry.AspNetCore.SentryMiddleware", LogLevel.None, null);
        options.Rules.Add(rule);
    });
    // before invoking `Build` on the ASP.NET Core Web-App-Builder
    {
      "Logging": {
        "LogLevel": {
        },
        "SentryLogs": {
          "LogLevel": {
            "Default": "Warning",
            "Program": "Error",
            "MyCategory": "Critical"
          }
        }
      }
    }

    This should get you through [5.16.0, 6.0.0), until we ship the actually intended behavior across all Microsoft.Extensions.Logging integrations in 6.0.0 together with the .NET 10 release.

    Warning

    This is unsupported and dangerous (accessing internal implementation details).
    This will stop working with 6.0.0 (and pre-releases), and may then actually cause unintended / undefined behavior.

    @wondertalik, would you mind pinging me if that works for you.
    I'll ping you once we got the intended behavior fixed in an upcoming 6.0.0-preview.* that we'd love to get feedback on.

  8. TimSalomons commented on Oct 30, 2025

    @TimSalomons

    @Flash0ver I have tried your suggested temporary workaround and can confirm the expected results. For our use case this works great since it prevents Sentry from being spammed by great amounts of database query logs.

  9. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 30, 2025
  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 3, 2025
  11. wondertalik commented on Nov 14, 2025

    @wondertalik

    @Flash0ver hi there

    1. Sorry, this month was kind of crazy. I will try right now
    2. .net 10 is GA, when do you plan to release 6.0?

    Updates, i tried solution above and i got an exception.

    Example, https://github.com/wondertalik/azure-container-apps/blob/b0123cbb6e92fc0f588946c9a615555d41459593/src/HttpApi/Program.cs#L21

    System.InvalidOperationException: Sequence contains no matching element
       at System.Linq.ThrowHelper.ThrowNoMatchException()
       at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
       at Program.<>c.<<Main>$>b__0_1(LoggerFilterOptions options) in /Users/admin/Works/Caropticom/Training/AzureContainerApps/src/HttpApi/Program.cs:line 24
       at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options)
       at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
       at Microsoft.Extensions.Options.OptionsMonitor`1.<>c.<Get>b__10_0(String name, IOptionsFactory`1 factory)
       at Microsoft.Extensions.Options.OptionsCache`1.<>c__DisplayClass3_1`1.<GetOrAdd>b__2()
       at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)

    I use this repo as example in ahother issue

  12. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 14, 2025
  13. jamescrosswell commented on Nov 18, 2025

    @jamescrosswell
    Collaborator

    2. .net 10 is GA, when do you plan to release 6.0?

    Should be within the next couple of weeks. There's a 6.0.0-rc.1 release available already... although we did discover an issue in this related to tracing on ASP.NET Core - so will be at least one more RC release.

  14. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions