Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into spi/laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLightfootWild committed Oct 27, 2024
2 parents a3cf950 + 0a41216 commit 504796e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: PHP QA

on:
Expand All @@ -19,28 +18,30 @@ jobs:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
# Sorted alphabetically to ease finding the desired run in the GitHub Workflow UI.
project: [
'Aws',
'Context/Swoole',
'Instrumentation/CakePHP',
'Instrumentation/CodeIgniter',
'Instrumentation/ExtAmqp',
'Instrumentation/ExtRdKafka',
'Instrumentation/Guzzle',
'Instrumentation/HttpAsyncClient',
'Instrumentation/Slim',
'Instrumentation/CakePHP',
'Instrumentation/IO',
'Instrumentation/Laravel',
'Instrumentation/MongoDB',
'Instrumentation/OpenAIPHP',
'Instrumentation/PDO',
# Sort PSRs numerically.
'Instrumentation/Psr3',
'Instrumentation/Psr6',
'Instrumentation/Psr14',
'Instrumentation/Psr15',
'Instrumentation/Psr16',
'Instrumentation/Psr18',
'Instrumentation/IO',
'Instrumentation/PDO',
'Instrumentation/Slim',
'Instrumentation/Symfony',
'Instrumentation/OpenAIPHP',
'Instrumentation/Laravel',
'Instrumentation/MongoDB',
'Instrumentation/CodeIgniter',
'Instrumentation/Yii',
'Logs/Monolog',
'Propagation/ServerTiming',
Expand All @@ -49,7 +50,7 @@ jobs:
'ResourceDetectors/Container',
'Sampler/RuleBased',
'Shims/OpenTracing',
'Symfony'
'Symfony',
]
exclude:
- project: 'Instrumentation/Guzzle'
Expand Down
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\Logs\LoggerInterface;
use OpenTelemetry\API\Logs\LogRecord;
use OpenTelemetry\API\Logs\Severity;
use TypeError;

class LogWatcher extends Watcher
{
Expand Down Expand Up @@ -37,9 +38,17 @@ public function recordLog(MessageLogged $log): void
{
$underlyingLogger = $this->logManager->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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public static function serializeCommand(string $command, array $params): string
$paramsToSerialize[] = '[' . (count($params) - $paramsToSerializeNum) . ' other arguments]';
}

// In some cases (for example when using LUA scripts) arrays are valid parameters
$paramsToSerialize = array_map(function($param) { return is_array($param) ? json_encode($param) : $param; }, $paramsToSerialize);

return $command . ' ' . implode(' ', $paramsToSerialize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ public function serializeCases(): iterable

// Serialize all params
yield ['DEL', ['param1', 'param2', 'param3', 'param4'], 'DEL param1 param2 param3 param4'];

// Parameters of array type
yield ['EVAL', ['param1', 'param2', ['arg1', 'arg2']], 'EVAL param1 param2 ["arg1","arg2"]'];
}
}

0 comments on commit 504796e

Please sign in to comment.