Skip to content

Commit

Permalink
adds service and version to exception handling (#689)
Browse files Browse the repository at this point in the history
* adds service and version to exception handling

* fixes BootstrapTest
  • Loading branch information
bshaffer authored and dwsupplee committed Sep 28, 2017
1 parent 359f2d5 commit d0d736e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/ErrorReporting/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/ErrorReporting/BootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d0d736e

Please sign in to comment.