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()