Serilog sink: add `MinimumLogLevel` to filter logs separately from events and breadcrumbs

Đang mở
#5,995 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
backend

Hướng nghiên cứu

Read SentrySink.InnerEmit alongside NLog's SentryTarget.InnerWrite (#5913) to see where the log-level check belongs, then look at SentrySerilogOptions and the WriteTo.Sentry(...) overload that already exposes minimumEventLevel and minimumBreadcrumbLevel. The open questions — how to express "off" with LogEventLevel and which default keeps 7.0 behaviour — should be settled on the thread before writing code, since they shape the option's type and the Serilog.Settings.Configuration binding. Done means the sink options, the WriteTo.Sentry argument and the sink's filtering are in place, with tests covering each level combination from the table in the issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

.NET Feature Logs Serilog State: Needs Discussion
Problem Statement

Since 7.0.0, the Serilog sink sends every entry it receives to Sentry as a log. Serilog's restrictedToMinimumLevel and levelSwitch decide which entries reach the sink, so raising them also cuts events and breadcrumbs. The sink has MinimumEventLevel and MinimumBreadcrumbLevel, but no level for logs.

Measured against 7.0.1, writing one info, one warning and one error:

Sink setup Logs Breadcrumbs Events
default 3 3 1
restrictedToMinimumLevel: Error 1 1 1
restrictedToMinimumLevel: Fatal 0 0 0

An app that uses the sink for errors and breadcrumbs, and doesn't want Sentry Logs, can only use SetBeforeSendLog. To leave SentrySdk.Logger alone, the callback has to match on the sink's origin:

options.SetBeforeSendLog(log =>
    log.TryGetAttribute("sentry.origin", out var origin) && origin is "auto.log.serilog" ? null : log);

That builds each log before dropping it, counts it as discarded in client reports, and can't be set from Serilog.Settings.Configuration.

The other logging integrations already have a switch for logs alone:

  • NLog: MinimumLogLevel, which can be Off (#5913). That PR noted that Serilog has no threshold for logs.
  • Logging.AddSentry(): the Sentry provider alias, Logging:Sentry:LogLevel:Default = None (#5988, getsentry/sentry-docs#20947).
Solution Brainstorm

Add MinimumLogLevel to SentrySerilogOptions, and a minimumLogLevel argument to WriteTo.Sentry(...) next to minimumEventLevel and minimumBreadcrumbLevel, so it binds from appsettings.json. SentrySink.InnerEmit checks it before CaptureStructuredLog, as SentryTarget.InnerWrite does for NLog, so a filtered entry never becomes a log.

Open points:

  • How to say "off". LogEventLevel has no Off member. LevelAlias.Off exists from Serilog 3.0, but Sentry.Serilog references Serilog 2.7.1 and 2.10.0, and it's a constant rather than an enum member, so configuration binding can't parse "Off". Options: a nullable level where null means no logs, Fatal + 1, or a separate switch.
  • Default. To ship in a 7.x minor, the default has to keep 7.0's behaviour and send every level that reaches the sink. NLog defaults to Info, but changing Serilog's default to match would be a behaviour change.

This was raised while sanity-checking getsentry/sentry-docs#20947, which documents the Logging.AddSentry() switch.

Ngôn ngữ chính
C#
Star
775
Fork
262
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
118

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/sentry-dotnet

Tất cả issue của getsentry/sentry-dotnet

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.