From 8de6e80191ed28705bb79fce098e4306ece9b207 Mon Sep 17 00:00:00 2001 From: pallam Date: Sat, 15 Feb 2025 06:18:09 +0300 Subject: [PATCH 1/2] fix: add ability to escape error, when serialized parameter is closure or callable function --- .../Laravel/src/Watchers/RedisCommand/Serializer.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php b/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php index e15b4db6f..8472b09ab 100644 --- a/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php +++ b/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php @@ -70,7 +70,17 @@ public static function serializeCommand(string $command, array $params): string } // 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); + // In additional cases, Closure are also valid parameters (Pipeline command) + $paramsToSerialize = array_map( + static function ($param) { + return match (true) { + is_array($param) => json_encode($param), + is_callable($param) => 'Callable', + default => $param, + }; + }, + $paramsToSerialize + ); return $command . ' ' . implode(' ', $paramsToSerialize); } From be13ae00a29aa27f8560d4f1199b85dc4c744182 Mon Sep 17 00:00:00 2001 From: pallam Date: Mon, 17 Feb 2025 08:33:14 +0300 Subject: [PATCH 2/2] tests: add pipeline serialization test case --- .../Laravel/tests/Unit/Watches/RedisCommand/SerializerTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Instrumentation/Laravel/tests/Unit/Watches/RedisCommand/SerializerTest.php b/src/Instrumentation/Laravel/tests/Unit/Watches/RedisCommand/SerializerTest.php index 3749f65e2..ea14ccd36 100644 --- a/src/Instrumentation/Laravel/tests/Unit/Watches/RedisCommand/SerializerTest.php +++ b/src/Instrumentation/Laravel/tests/Unit/Watches/RedisCommand/SerializerTest.php @@ -34,5 +34,7 @@ public function serializeCases(): iterable // Parameters of array type yield ['EVAL', ['param1', 'param2', ['arg1', 'arg2']], 'EVAL param1 param2 ["arg1","arg2"]']; + + yield ['pipeline', [function () {}], 'pipeline Callable']; } }