Skip to content

Commit a5d9cc4

Browse files
committed
removes exception from context
1 parent 6f4230d commit a5d9cc4

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/Instrumentation/Laravel/src/Watchers/LogWatcher.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,21 @@ public function recordLog(MessageLogged $log): void
5454
// Should this fail, we should continue to emit the LogRecord.
5555
}
5656

57+
$contextToEncode = array_filter($log->context);
58+
59+
$exception = $this->getExceptionFromContext($log->context);
60+
61+
if ($exception !== null) {
62+
unset($contextToEncode['exception']);
63+
}
64+
5765
$attributes = [
58-
'context' => json_encode(array_filter($log->context)),
59-
...$this->parseExceptionFromContext($log->context),
66+
'context' => json_encode($contextToEncode),
67+
...$exception !== null ? [
68+
'exception.type' => $exception::class,
69+
'exception.message' => $exception->getMessage(),
70+
'exception.stacktrace' => StackTraceFormatter::format($exception),
71+
] : [],
6072
];
6173

6274
$logger = $this->instrumentation->logger();
@@ -69,21 +81,15 @@ public function recordLog(MessageLogged $log): void
6981
$logger->emit($record);
7082
}
7183

72-
private function parseExceptionFromContext(array $context): array
84+
private function getExceptionFromContext(array $context): ?Throwable
7385
{
7486
if (
7587
! isset($context['exception']) ||
7688
! $context['exception'] instanceof Throwable
7789
) {
78-
return [];
90+
return null;
7991
}
8092

81-
$exception = $context['exception'];
82-
83-
return [
84-
'exception.type' => $exception::class,
85-
'exception.message' => $exception->getMessage(),
86-
'exception.stacktrace' => StackTraceFormatter::format($exception),
87-
];
93+
return $context['exception'];
8894
}
8995
}

0 commit comments

Comments
 (0)