diff --git a/CHANGELOG.md b/CHANGELOG.md index ce43cc22b..ce2a8210d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix `TypeError` in `Sentry\Monolog\Handler` when the extra data array has numeric keys (#833). + ## 2.1.1 (2019-06-13) - Fix the behavior of the `excluded_exceptions` option: now it's used to skip capture of exceptions, not to purge the diff --git a/src/Monolog/Handler.php b/src/Monolog/Handler.php index 40c646a35..d1a7ea1b3 100644 --- a/src/Monolog/Handler.php +++ b/src/Monolog/Handler.php @@ -59,7 +59,7 @@ protected function write(array $record): void if (isset($record['context']['extra']) && \is_array($record['context']['extra'])) { foreach ($record['context']['extra'] as $key => $value) { - $scope->setExtra($key, $value); + $scope->setExtra((string) $key, $value); } } diff --git a/tests/Monolog/HandlerTest.php b/tests/Monolog/HandlerTest.php index c065f9211..8b544b333 100644 --- a/tests/Monolog/HandlerTest.php +++ b/tests/Monolog/HandlerTest.php @@ -281,5 +281,30 @@ public function handleDataProvider(): \Generator 'bar.tag' => 'bar tag value', ], ]; + + yield [ + [ + 'message' => 'foo bar', + 'level' => Logger::INFO, + 'level_name' => Logger::getLevelName(Logger::INFO), + 'channel' => 'channel.foo', + 'context' => [ + 'extra' => [ + 1 => 'numeric key', + ], + ], + 'extra' => [], + ], + [ + 'level' => Severity::info(), + 'message' => 'foo bar', + ], + [ + 'monolog.channel' => 'channel.foo', + 'monolog.level' => Logger::getLevelName(Logger::INFO), + '1' => 'numeric key', + ], + [], + ]; } }