diff --git a/src/ExternalEvents.php b/src/ExternalEvents.php index 9640f81..831a569 100644 --- a/src/ExternalEvents.php +++ b/src/ExternalEvents.php @@ -123,7 +123,8 @@ public static function decorateListener(string $listenerClass): \Closure $logMessage = self::$formatter->formatIncomingMessage( $event, $message[0], - $executionTimeMs + $executionTimeMs, + $exception ?? null ); self::$logger->log($level, $logMessage->message, $logMessage->context); diff --git a/src/LogMessageFormatterInterface.php b/src/LogMessageFormatterInterface.php index e8c73e0..fa42561 100644 --- a/src/LogMessageFormatterInterface.php +++ b/src/LogMessageFormatterInterface.php @@ -15,8 +15,9 @@ public function formatOutgoingMessage( ): LogMessage; public function formatIncomingMessage( - string $routingKey, - array $message, - int $executionTimeMs + string $routingKey, + array $message, + int $executionTimeMs, + ?Throwable $exception = null ): LogMessage; } diff --git a/tests/ExternalEventsTest.php b/tests/ExternalEventsTest.php index d8cb366..72ec699 100644 --- a/tests/ExternalEventsTest.php +++ b/tests/ExternalEventsTest.php @@ -350,7 +350,8 @@ public function handle(FakeMessage $message) 'data' => $message->serializeToJsonString(), 'headers' => ['xRequestId' => '7b15d663-8d55-4e2f-82cc-4473576a4a17'], ], - $this->isType('int') + $this->isType('int'), + null ) ->andReturn(new LogMessage(':message:', ['context' => ':context:'])); @@ -411,8 +412,10 @@ public function handle(FakeMessage $message) 'client' => ':client:', 'data' => $message->serializeToJsonString(), 'headers' => ['xRequestId' => '7b15d663-8d55-4e2f-82cc-4473576a4a17'], + ], - $this->isType('int') + $this->isType('int'), + $this->isInstanceOf(Exception::class) ) ->andReturn(new LogMessage(':message:', ['context' => ':context:']));