diff --git a/src/ErrorReporting/Bootstrap.php b/src/ErrorReporting/Bootstrap.php index 0571a1586d91..b321c86a4952 100644 --- a/src/ErrorReporting/Bootstrap.php +++ b/src/ErrorReporting/Bootstrap.php @@ -117,7 +117,14 @@ public static function exceptionHandler($ex) { $message = sprintf('PHP Notice: %s', (string)$ex); if (self::$psrLogger) { - self::$psrLogger->error($message); + $service = self::$psrLogger->getMetadataProvider()->serviceId(); + $version = self::$psrLogger->getMetadataProvider()->versionId(); + self::$psrLogger->error($message, [ + 'serviceContext' => [ + 'service' => $service, + 'version' => $version, + ] + ]); } else { fwrite(STDERR, $message . PHP_EOL); } diff --git a/tests/unit/ErrorReporting/BootstrapTest.php b/tests/unit/ErrorReporting/BootstrapTest.php index d6cd09e48eee..6c9f9bb04b14 100644 --- a/tests/unit/ErrorReporting/BootstrapTest.php +++ b/tests/unit/ErrorReporting/BootstrapTest.php @@ -104,8 +104,17 @@ public function testExceptionHandler( $exception ) { $expectedMessage = sprintf('PHP Notice: %s', (string)$exception); - $this->psrBatchLogger->error($expectedMessage) + $expectedContext = [ + 'serviceContext' => [ + 'service' => '', + 'version' => '' + ] + ]; + $this->psrBatchLogger->error($expectedMessage, $expectedContext) ->shouldBeCalledTimes(1); + $this->psrBatchLogger->getMetadataProvider() + ->willReturn(new SimpleMetadataProvider()) + ->shouldBeCalledTimes(2); Bootstrap::$psrLogger = $this->psrBatchLogger->reveal(); Bootstrap::exceptionHandler($exception); }