question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MinimumEventLevel and MinimumBreadcrumbLevel options ignored when configured through AddSentry extension

See original GitHub issue

Package

Sentry.Extensions.Logging

.NET Flavor

.NET

.NET Version

6.0.0

OS

Windows

SDK Version

3.22.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

Console app:

using var loggingFactory = LoggerFactory.Create(builder =>
{
    builder.AddSentry(o => {
        o.Dsn = "<your dsn here>";
        o.MinimumBreadcrumbLevel = LogLevel.Trace;
        o.MinimumEventLevel = LogLevel.Information;
        o.IsGlobalModeEnabled = true;
    });
});


var logger = loggingFactory.CreateLogger<Program>();

// should add a breadcrumb
logger.LogTrace("test trace");

// should send an event to Sentry.io, with the "test trace" breadcrumb above
logger.LogInformation("test information");

// should send a 2nd event to Sentry.io
logger.LogWarning("test warning");

Expected Result

Two events sent to Sentry.io. The first should include a breadcrumb “test trace”.

Actual Result

A single event is sent to Sentry.io, with a breadcrumb “test information”.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mattjohnsonpintcommented, Oct 15, 2022

Changing my mind about this - it certainly is a bug, not an enhancement. The intent was always that MinimumEventLevel and MinimumBreadcrumbLevel could be set independently of any other logging configuration and would work correctly, but presently it is constrained by the default global log level, or the log level set for a particular component or logging category.

Fixed in #1992, so that the MinimumEventLevel and MinimumBreadcrumbLevel can be set lower than the default.

0reactions
mattjohnsonpintcommented, Oct 15, 2022

Ok, researching more, this was helpful (both “Default log level” and “Filter function” right below it). https://learn.microsoft.com/en-us/dotnet/core/extensions/logging#default-log-level

Thus, instead of SetMinimumLevel, we can use:

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

That will send all logs to the SentryLogger regardless of level, then our own MinimumBreadcrumbLevel and MinimumEventLevel will always work as expected. I’ll see if we can add this to AddSentry so it’s the default, but you can add it safely to your own code as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NLog | Sentry Documentation
Features. Store log messages as breadcrumbs; Send events to sentry. Two separate settings define the minimum log level to keep the log entry...
Read more >
Microsoft.Extensions.Logging
Features. Store log messages as breadcrumbs; Send events to sentry. Two separate settings define the minimum log level to keep the log entry...
Read more >
Sentry.Extensions.Logging 1.0.0-rc2
Extensions.Logging integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.
Read more >
How to make Sentry Ignore some Exceptions?
I would like to read those exceptions from the app settings file if possible. I tried this, but it did not work. I'm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found