Skip to content

fix(monolog): apply processors in ExceptionToSentryIssueHandler - #2290

Merged
Litarnus merged 2 commits into
getsentry:masterfrom
giosh94mhz:fix/monolog-exception-handler-processors
Oct 22, 2026
Merged

Litarnus merged 2 commits into
getsentry:masterfrom
giosh94mhz:fix/monolog-exception-handler-processors

Conversation

@giosh94mhz

Copy link
Copy Markdown
Contributor

Description

ExceptionToSentryIssueHandler extends AbstractHandler, so it has no processor stack: processors pushed on the handler, or configured on it by a framework integration, never run. The visible effect is that the monolog.message extra keeps the raw PSR-3 template instead of the interpolated message, and any extra data added by a processor is lost.

$handler = new ExceptionToSentryIssueHandler($hub);
$handler->pushProcessor(new PsrLogMessageProcessor()); // Error: undefined method

$logger->error('Failed to sync user {username}', [
    'username' => 'john',
    'exception' => $e,
]);
// monolog.message: "Failed to sync user {username}"

LogToSentryIssueHandler, and the deprecated Handler that both replace, extend AbstractProcessingHandler, so switching from Handler to the new pair makes the exception events lose the interpolated message, while the log events keep it.

This PR makes ExceptionToSentryIssueHandler extend AbstractProcessingHandler and use CompatibilityProcessingHandlerTrait, the same way LogToSentryIssueHandler does:

  • handle() keeps its existing checks: records without a Throwable in context.exception, or below the level, are still skipped and return false. Otherwise it delegates to parent::handle(), which runs the processors and handles bubbling.
  • The capture logic moves to doWrite(). It reads the exception again from the processed record and returns early if a processor removed it.

Issues

giosh94mhz and others added 2 commits October 21, 2026 13:07
ExceptionToSentryIssueHandler extended AbstractHandler, so the processors
pushed on it never ran: the monolog.message extra kept the raw PSR-3
template (e.g. "Failed to sync user {username}") and processor-added extra
data was lost, unlike LogToSentryIssueHandler and the deprecated Handler it
replaces.

It now extends AbstractProcessingHandler like LogToSentryIssueHandler:
handle() keeps its exception and level checks and delegates to the parent,
which runs the processors before doWrite() captures the exception.
Constructor, return value and bubbling are unchanged.

@Litarnus Litarnus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks for opening the PR

@Litarnus
Litarnus merged commit 50751da into getsentry:master Oct 22, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants