-
-
Notifications
You must be signed in to change notification settings - Fork 461
Description
We have many log calls that are structured in the suggested way, i.e. context is an array with arbitrary fields:
$this->logger->error('Could not find channel of order', [
'order_id' => $orderId,
'channel_id' => $channelId,
]);
Up until this week, we were still using Sentry 1.10 and the deprecated handler from Monolog upstream. The handler was configured with a LineFormatter and the line format %message% %context% %extra%
. Sentry received messages like:
Could not find channel of order {"order_id": "FOO-1", "channel_id": "42"} []
Now we upgraded to Sentry 2.x and switched to the Sentry\Monolog\Handler
. The message is now:
Could not find channel of order
The context is missing and also cannot be found under "Additional Data". Looking in the source of the integrated handler, the reasons become clear:
l. 49
: The Sentry fieldmessage
ist set using the Monolog fieldmessage
, which ignores theformatted
field set by the LineFormatter.- The arbitary context fields are not set in the Sentry scope.
The old behavior with the context added to the message as JSON object was not ideal, because Sentry would have had a hard time automatically merging the issues, resulting in many separate issues that needed manual merging. Therefore I would send a PR that adds the arbitrary context fields to the Sentry scope via setExtra
.