Skip to content

Commit

Permalink
log previous exception message from error writer (open-telemetry#1231)
Browse files Browse the repository at this point in the history
it's not always clear from an exception message what the underlying issue was, so
also print out the previous exception's message, if available.
  • Loading branch information
brettmc authored Feb 6, 2024
1 parent 1f187c7 commit b20c45d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/API/Behavior/Internal/LogWriter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public static function format($level, string $message, array $context): string
? $context['exception']
: null;
if ($exception) {
$previous = $exception->getPrevious() ? $exception->getPrevious()->getMessage() : '';
$message = sprintf(
'OpenTelemetry: [%s] %s [exception] %s%s%s',
'OpenTelemetry: [%s] %s [exception] %s [previous] %s%s%s',
$level,
$message,
$exception->getMessage(),
$previous,
PHP_EOL,
$exception->getTraceAsString()
);
Expand Down

0 comments on commit b20c45d

Please sign in to comment.