From 52726ab15b63277332c45773ef9dc2bcef6896ff Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 27 Sep 2017 11:28:59 -0700 Subject: [PATCH 1/2] adds service and version to exception handling --- src/ErrorReporting/Bootstrap.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ErrorReporting/Bootstrap.php b/src/ErrorReporting/Bootstrap.php index e7e0e22bd044..5599e91c41fc 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::$psrBatchLogger) { - self::$psrBatchLogger->error($message); + $service = self::$psrBatchLogger->getMetadataProvider()->serviceId(); + $version = self::$psrBatchLogger->getMetadataProvider()->versionId(); + self::$psrBatchLogger->error($message, [ + 'serviceContext' => [ + 'service' => $service, + 'version' => $version, + ] + ]); } else { fwrite(STDERR, $message . PHP_EOL); } From 44b146fb1256cc4c82acd5b7a380ae83f443d5e9 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 27 Sep 2017 13:23:57 -0700 Subject: [PATCH 2/2] fixes BootstrapTest --- tests/unit/ErrorReporting/BootstrapTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unit/ErrorReporting/BootstrapTest.php b/tests/unit/ErrorReporting/BootstrapTest.php index a27fcf5ea867..2c619005f3f6 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::$psrBatchLogger = $this->psrBatchLogger->reveal(); Bootstrap::exceptionHandler($exception); }