From 2b67623afef5fb132105c7f5b1d72e23b6d56dc1 Mon Sep 17 00:00:00 2001 From: Bob Evans Date: Wed, 14 Aug 2024 08:46:31 -0400 Subject: [PATCH] fix: Updated redis instrumentation to parse host/port when a url is not provided (#2463) --- lib/instrumentation/@node-redis/client.js | 5 +++-- test/unit/instrumentation/redis.test.js | 4 ++-- test/versioned/redis/redis-v4-legacy-mode.tap.js | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/instrumentation/@node-redis/client.js b/lib/instrumentation/@node-redis/client.js index f51e5c6024..674220dd0f 100644 --- a/lib/instrumentation/@node-redis/client.js +++ b/lib/instrumentation/@node-redis/client.js @@ -104,8 +104,9 @@ function getRedisParams(clientOpts) { } return new DatastoreParameters({ - host: clientOpts?.socket?.host || 'localhost', - port_path_or_id: clientOpts?.socket?.path || clientOpts?.socket?.port || '6379', + host: clientOpts?.host || clientOpts?.socket?.host || 'localhost', + port_path_or_id: + clientOpts?.port || clientOpts?.socket?.path || clientOpts?.socket?.port || '6379', database_name: clientOpts?.database || 0 }) } diff --git a/test/unit/instrumentation/redis.test.js b/test/unit/instrumentation/redis.test.js index ebe6d20c08..1d6a56226b 100644 --- a/test/unit/instrumentation/redis.test.js +++ b/test/unit/instrumentation/redis.test.js @@ -26,8 +26,8 @@ tap.test('getRedisParams should behave as expected', function (t) { t.test('if host/port are defined incorrectly, should return expected defaults', function (t) { const params = getRedisParams({ host: 'myLocalHost', port: '1234' }) const expected = { - host: 'localhost', - port_path_or_id: '6379', + host: 'myLocalHost', + port_path_or_id: '1234', database_name: 0 } t.match(params, expected, 'should return sensible defaults if defined without socket') diff --git a/test/versioned/redis/redis-v4-legacy-mode.tap.js b/test/versioned/redis/redis-v4-legacy-mode.tap.js index 8abffe4ce3..abacc5a95f 100644 --- a/test/versioned/redis/redis-v4-legacy-mode.tap.js +++ b/test/versioned/redis/redis-v4-legacy-mode.tap.js @@ -30,7 +30,8 @@ test('Redis instrumentation', function (t) { const redis = require('redis') client = redis.createClient({ legacyMode: true, - socket: { port: params.redis_port, host: params.redis_host } + port: params.redis_port, + host: params.redis_host }) await client.connect()