File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
src/Instrumentation/Laravel/src/Watchers Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1010use OpenTelemetry \API \Instrumentation \CachedInstrumentation ;
1111use OpenTelemetry \API \Logs \LogRecord ;
1212use OpenTelemetry \API \Logs \Map \Psr3 ;
13+ use TypeError ;
1314
1415class LogWatcher extends Watcher
1516{
@@ -36,9 +37,17 @@ public function recordLog(MessageLogged $log): void
3637 {
3738 $ underlyingLogger = $ this ->logger ->getLogger ();
3839
39- /** @phan-suppress-next-line PhanUndeclaredMethod */
40- if (method_exists ($ underlyingLogger , 'isHandling ' ) && !$ underlyingLogger ->isHandling ($ log ->level )) {
41- return ;
40+ /**
41+ * This assumes that the underlying logger (expected to be monolog) would accept `$log->level` as a string.
42+ * With monolog < 3.x, this method would fail. Let's prevent this blowing up in Laravel<10.x.
43+ */
44+ try {
45+ /** @phan-suppress-next-line PhanUndeclaredMethod */
46+ if (method_exists ($ underlyingLogger , 'isHandling ' ) && !$ underlyingLogger ->isHandling ($ log ->level )) {
47+ return ;
48+ }
49+ } catch (TypeError ) {
50+ // Should this fail, we should continue to emit the LogRecord.
4251 }
4352
4453 $ attributes = [
You can’t perform that action at this time.
0 commit comments