Skip to content

Commit 2b67623

Browse files
authored
fix: Updated redis instrumentation to parse host/port when a url is not provided (#2463)
1 parent 81fdde1 commit 2b67623

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lib/instrumentation/@node-redis/client.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ function getRedisParams(clientOpts) {
104104
}
105105

106106
return new DatastoreParameters({
107-
host: clientOpts?.socket?.host || 'localhost',
108-
port_path_or_id: clientOpts?.socket?.path || clientOpts?.socket?.port || '6379',
107+
host: clientOpts?.host || clientOpts?.socket?.host || 'localhost',
108+
port_path_or_id:
109+
clientOpts?.port || clientOpts?.socket?.path || clientOpts?.socket?.port || '6379',
109110
database_name: clientOpts?.database || 0
110111
})
111112
}

test/unit/instrumentation/redis.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ tap.test('getRedisParams should behave as expected', function (t) {
2626
t.test('if host/port are defined incorrectly, should return expected defaults', function (t) {
2727
const params = getRedisParams({ host: 'myLocalHost', port: '1234' })
2828
const expected = {
29-
host: 'localhost',
30-
port_path_or_id: '6379',
29+
host: 'myLocalHost',
30+
port_path_or_id: '1234',
3131
database_name: 0
3232
}
3333
t.match(params, expected, 'should return sensible defaults if defined without socket')

test/versioned/redis/redis-v4-legacy-mode.tap.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ test('Redis instrumentation', function (t) {
3030
const redis = require('redis')
3131
client = redis.createClient({
3232
legacyMode: true,
33-
socket: { port: params.redis_port, host: params.redis_host }
33+
port: params.redis_port,
34+
host: params.redis_host
3435
})
3536

3637
await client.connect()

0 commit comments

Comments
 (0)