Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Instrumentation/Laravel/src/Watchers/LogWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
use OpenTelemetry\API\Logs\LogRecord;
use OpenTelemetry\API\Logs\Map\Psr3;
use TypeError;

class LogWatcher extends Watcher
{
Expand All @@ -36,9 +37,17 @@ public function recordLog(MessageLogged $log): void
{
$underlyingLogger = $this->logger->getLogger();

/** @phan-suppress-next-line PhanUndeclaredMethod */
if (method_exists($underlyingLogger, 'isHandling') && !$underlyingLogger->isHandling($log->level)) {
return;
/**
* This assumes that the underlying logger (expected to be monolog) would accept `$log->level` as a string.
* With monolog < 3.x, this method would fail. Let's prevent this blowing up in Laravel<10.x.
*/
try {
/** @phan-suppress-next-line PhanUndeclaredMethod */
if (method_exists($underlyingLogger, 'isHandling') && !$underlyingLogger->isHandling($log->level)) {
return;
}
} catch (TypeError) {
// Should this fail, we should continue to emit the LogRecord.
}

$attributes = [
Expand Down
Loading