Skip to content

Commit

Permalink
fix: Updated redis instrumentation to parse host/port when a url is n…
Browse files Browse the repository at this point in the history
…ot provided (#2463)
  • Loading branch information
bizob2828 authored Aug 14, 2024
1 parent 81fdde1 commit 2b67623
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/instrumentation/@node-redis/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/instrumentation/redis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion test/versioned/redis/redis-v4-legacy-mode.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2b67623

Please sign in to comment.