Skip to content

Commit 504796e

Browse files
Merge remote-tracking branch 'upstream/main' into spi/laravel
2 parents a3cf950 + 0a41216 commit 504796e

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

.github/workflows/php.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: PHP QA
32

43
on:
@@ -19,28 +18,30 @@ jobs:
1918
fail-fast: false
2019
matrix:
2120
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
21+
# Sorted alphabetically to ease finding the desired run in the GitHub Workflow UI.
2222
project: [
2323
'Aws',
2424
'Context/Swoole',
25+
'Instrumentation/CakePHP',
26+
'Instrumentation/CodeIgniter',
2527
'Instrumentation/ExtAmqp',
2628
'Instrumentation/ExtRdKafka',
2729
'Instrumentation/Guzzle',
2830
'Instrumentation/HttpAsyncClient',
29-
'Instrumentation/Slim',
30-
'Instrumentation/CakePHP',
31+
'Instrumentation/IO',
32+
'Instrumentation/Laravel',
33+
'Instrumentation/MongoDB',
34+
'Instrumentation/OpenAIPHP',
35+
'Instrumentation/PDO',
36+
# Sort PSRs numerically.
3137
'Instrumentation/Psr3',
3238
'Instrumentation/Psr6',
3339
'Instrumentation/Psr14',
3440
'Instrumentation/Psr15',
3541
'Instrumentation/Psr16',
3642
'Instrumentation/Psr18',
37-
'Instrumentation/IO',
38-
'Instrumentation/PDO',
43+
'Instrumentation/Slim',
3944
'Instrumentation/Symfony',
40-
'Instrumentation/OpenAIPHP',
41-
'Instrumentation/Laravel',
42-
'Instrumentation/MongoDB',
43-
'Instrumentation/CodeIgniter',
4445
'Instrumentation/Yii',
4546
'Logs/Monolog',
4647
'Propagation/ServerTiming',
@@ -49,7 +50,7 @@ jobs:
4950
'ResourceDetectors/Container',
5051
'Sampler/RuleBased',
5152
'Shims/OpenTracing',
52-
'Symfony'
53+
'Symfony',
5354
]
5455
exclude:
5556
- project: 'Instrumentation/Guzzle'

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OpenTelemetry\API\Logs\LoggerInterface;
1111
use OpenTelemetry\API\Logs\LogRecord;
1212
use OpenTelemetry\API\Logs\Severity;
13+
use TypeError;
1314

1415
class LogWatcher extends Watcher
1516
{
@@ -37,9 +38,17 @@ public function recordLog(MessageLogged $log): void
3738
{
3839
$underlyingLogger = $this->logManager->getLogger();
3940

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

4554
$attributes = [

src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public static function serializeCommand(string $command, array $params): string
6969
$paramsToSerialize[] = '[' . (count($params) - $paramsToSerializeNum) . ' other arguments]';
7070
}
7171

72+
// In some cases (for example when using LUA scripts) arrays are valid parameters
73+
$paramsToSerialize = array_map(function($param) { return is_array($param) ? json_encode($param) : $param; }, $paramsToSerialize);
74+
7275
return $command . ' ' . implode(' ', $paramsToSerialize);
7376
}
7477
}

src/Instrumentation/Laravel/tests/Unit/Watches/RedisCommand/SerializerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ public function serializeCases(): iterable
3131

3232
// Serialize all params
3333
yield ['DEL', ['param1', 'param2', 'param3', 'param4'], 'DEL param1 param2 param3 param4'];
34+
35+
// Parameters of array type
36+
yield ['EVAL', ['param1', 'param2', ['arg1', 'arg2']], 'EVAL param1 param2 ["arg1","arg2"]'];
3437
}
3538
}

0 commit comments

Comments
 (0)