diff --git a/src/Watchers/LogWatcher.php b/src/Watchers/LogWatcher.php index 7bacfa7..7adcddd 100644 --- a/src/Watchers/LogWatcher.php +++ b/src/Watchers/LogWatcher.php @@ -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 { @@ -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 = [