rollbar-php icon indicating copy to clipboard operation
rollbar-php copied to clipboard

[Monolog][RollbarHandler] Exception passed in context override custom log message

Open benjamindulau opened this issue 6 years ago • 2 comments

Using

  • rollbar/rollbar v1.8.1
  • rollbar/rollbar-php-symfony-bundle v3.1.2
$this->logger->error(sprintf('Error thrown while projecting event "%s" on projection "%s"', $eventName, get_class($handler)), [
    'exception'    => $e,
    'eventId'      => (string)$streamEvent->getEventId() : null,
    'eventType'    => (string)$streamEvent->getEventType() : null,
]);

When throwing an exception like for instance the following:

throw new \InvalidArgumentException('What the fuck?');

When passing exception in context, Rollbar overrides the message passed as first parameter Error thrown while projecting event... with the one from the exception What the fuck?.

Why is that?

Here is the responsible code: https://github.com/rollbar/rollbar-php/blob/master/src/Monolog/Handler/RollbarHandler.php#L113

This is not convenient because we need to both have custom messages to easily identify logs in item list and the exception trace (If we do not pass the exception we get the correct message but we lose the trace context.).

benjamindulau avatar Aug 14 '19 14:08 benjamindulau

I totally support this!

Could we at least have an opinion from the Rollbar team about that? Agree? Disagree?

(the exact link for the responsible code: https://github.com/rollbar/rollbar-php/blob/f6c7f9b7f45e346ebf3d0cc724964f114ba92b15/src/Monolog/Handler/RollbarHandler.php#L113 - the line was correct, it's just that master changed since then :slightly_smiling_face:)

aubryfr avatar Mar 04 '20 11:03 aubryfr

I vote for this! It's not good to completely loose this information when issue passes to Rollbar. It this planned to be fixed?

DarthLegiON avatar Aug 11 '20 12:08 DarthLegiON

This is related to #461 and has been resolved in the upcoming v4.0.0 release by #582.

In the update, we use the context $exception->getMessage() as the message and the $message as the description. The decision to do it this way was based on our most common use case where an exception or error is caught by Rollbar not explicitly logged by the user. In that instance $message is an exception, and no description will be included in the report sent to the Rollbar service.

I agree with everyone's comments. We don't want to lose the message. It is important. I would welcome feedback on making it the description.

danielmorell avatar Dec 20 '22 18:12 danielmorell