Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Updated redis instrumentation to parse host/port when a url is not provided #2463

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future readers: the alternate form is tested in another suite:

const redis = require('redis')
client = redis.createClient({ socket: { port: params.redis_port, host: params.redis_host } })

})

await client.connect()
Expand Down
Loading