Giter Club home page Giter Club logo

Comments (8)

bruno-garcia avatar bruno-garcia commented on June 1, 2024

You can configure the minimal level which a log entry has to be equal or higher in order to record a breadcrumb:

public LogLevel MinimumBreadcrumbLevel { get; set; } = LogLevel.Information;

There's the same for sending event:

public LogLevel MinimumEventLevel { get; set; } = LogLevel.Error;

Besides that, you can use the MEL filter settings, like in this example:

logging.AddFilter<SentryAspNetCoreLoggerProvider>(

In this example, I completely disable log messages coming from ExceptionHandlerMiddleware for the SentryLogger. Your other loggers will still get those messages, but they won't reach the SentryLogger.

One other approach is using the Filter property in the SentryLoggingOptions object:

options.Filters = new[]
{
new DelegateLogEventFilter((category, level, eventId, exception)
// https://github.com/aspnet/KestrelHttpServer/blob/0aff4a0440c2f393c0b98e9046a8e66e30a56cb0/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs#L33
// 13 = Application unhandled exception, which is captured by the middleware so the LogError of kestrel ends up as a duplicate with less info
=> eventId.Id == 13
&& string.Equals(
category,
"Microsoft.AspNetCore.Server.Kestrel",
StringComparison.Ordinal))
};

One caveat is that besides the first switches that set different levels for Breadcrumb and Sending event, the others will avoid the log message becoming a either a breadcrumb or an event.

from sentry-dotnet.

bruno-garcia avatar bruno-garcia commented on June 1, 2024

To give a better API to add filters, I raised this PR: #90

Having the IReadOnlyList<IFilter> wasn't really the best experience I believe.

from sentry-dotnet.

lunim avatar lunim commented on June 1, 2024

Great, thanks for all the details

from sentry-dotnet.

bruno-garcia avatar bruno-garcia commented on June 1, 2024

Let me know how that works out for you. I'm using the API on a project but haven't had to filter too much stuff yet

from sentry-dotnet.

lunim avatar lunim commented on June 1, 2024

I'm having trouble getting a Log filter working with an Asp.Net core app running Sentry 1.0, here is my sample code:

.UseSentry(o =>
{
    o.Dsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
     o.MinimumEventLevel = LogLevel.Critical;
     o.MinimumBreadcrumbLevel = LogLevel.Warning;

     o.AddLogEntryFilter((category, level, eventId, exception) => string.Equals(category, "Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager", StringComparison.Ordinal));
}                

I am seeing breadcrumbs with this category.

from sentry-dotnet.

xt0rted avatar xt0rted commented on June 1, 2024

From what I can tell in SentryLogger.cs, even though the extension method says it's for messages & breadcrumbs, the filters are only applied to logged messages. So even if a message is filtered from going to Sentry it's still added to the breadcrumb list.

from sentry-dotnet.

bruno-garcia avatar bruno-garcia commented on June 1, 2024

Perhaps it was documented wrong in this case, could you please point me where it mentions filtering breadcrumbs so I can fix it?

There's a BeforeBreadcrumb callback that could be used to filter breadcrumbs. The logger category goes into the breadcrumb category so it's a good way to filter IMHO.

In case you don't want it either as event nor as breadcrumb, perhaps using the framework's filter?

Somethingnlike on appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager": "None"
    }
}

from sentry-dotnet.

lunim avatar lunim commented on June 1, 2024

Perhaps it was documented wrong in this case, could you please point me where it mentions filtering breadcrumbs so I can fix it?

There's a BeforeBreadcrumb callback that could be used to filter breadcrumbs. The logger category goes into the breadcrumb category so it's a good way to filter IMHO.

In case you don't want it either as event nor as breadcrumb, perhaps using the framework's filter?

Somethingnlike on appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager": "None"
    }
}

In SentryLoggingOptionsExtensions.cs, the extension method comment says:

/// Filters are called before recording a log message as a breadcrumb or sending event.
/// This allows the filter to decide whether the log message should not be recorded at all.

from sentry-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.