Repository navigation
feat(monolog): Allow skipping Sentry issue reporting via 'sentry' => false log context - #2400
giosh94mhz wants to merge 1 commit into
Conversation
…alse` log context Records whose context contains `'sentry' => false` are no longer captured as Sentry issues by `LogToSentryIssueHandler`, `ExceptionToSentryIssueHandler` and the deprecated `Handler`. The record still reaches every other handler, including `BreadcrumbHandler` and `LogsHandler`, so it remains available as context if another record later triggers an issue. This is useful for records that are worth logging at warning level or above (e.g. validation errors on user-provided data) but are known, at the call site, not to indicate a bug worth reporting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the PR. I'm not sure if this is really required as a built-in feature. You could pretty easily get the same functionality by having a small 'before_send' => function (\Sentry\Event $event): ?\Sentry\Event {
if ($event->getExtra()['monolog.context']['sentry'] === false) {
return null;
}
return $event;
}edit: corrected to the proper before_send |
|
Thanks for the suggestion! I tried it and it does work as a workaround, but a few caveats made me prefer a handler-level check — let me know what you think. A Also, the event is fully built and then thrown away, even though the call site already knows it's not worth reporting. For frequent logs like validation warnings that's wasted work. And events dropped in In my opinion this is a very minor feature that improves quality of life, especially when migrating legacy code, much like That said, if you'd rather not have it built in, I'm fine with closing this. I started the implementation because the |
|
Thanks for the explanation @giosh94mhz! I do agree with many points and I now think it makes sense to include it. While I believe it's a rather niche issue, it's still justified to have considering how small the PR is. I personally don't have a strong preference towards the naming, but I'm slightly leaning towards Thank you for opening the PR and starting the discussion, appreciate it |
Description
Adds a simple per-record "kill switch" to the Monolog handlers that create Sentry issues: when a log record's context contains
'sentry' => false, the record is not captured as a Sentry issue.The record is still passed on to every other handler. That includes
BreadcrumbHandlerandLogsHandler, so it stays available as context: if a later record triggers an issue, this one appears in its breadcrumbs.Only a strict
falsedisables reporting.null,0,'','false', etc. are ignored, so an issue can't be dropped by accident.This probably needs a short mention in the Monolog docs and in the changelog.
Use case
some conditions should be logged at warning level or above, but the we already knows there is no bug or anomalies to report. For example, validation errors on user-provided data, such as a CSV import. Today you can only suppress them by building custom handlers, processors or
before_sendfilters.A context flag keeps the decision next to the log call, it's easy to implement and survive message logging changes.