Skip to content

Commit d03b5f1

Browse files
committed
split into redis and @redis/client
1 parent 61a0daa commit d03b5f1

File tree

11 files changed

+151
-85
lines changed

11 files changed

+151
-85
lines changed

lib/subscriber-configs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const subscribers = {
2525
...require('./subscribers/openai/config'),
2626
...require('./subscribers/pino/config'),
2727
...require('./subscribers/pg/config'),
28+
...require('./subscribers/redis-client/config'),
2829
...require('./subscribers/redis/config'),
2930
...require('./subscribers/undici/config')
3031
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2026 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
const addCommand = {
7+
path: './redis-client/add-command',
8+
instrumentations: [{
9+
channelName: 'nr_addCommand',
10+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/commands-queue.js' },
11+
functionQuery: {
12+
className: 'RedisCommandsQueue',
13+
methodName: 'addCommand',
14+
kind: 'Async'
15+
}
16+
}]
17+
}
18+
19+
const sendCommand = {
20+
path: './redis-client/send-command',
21+
instrumentations: [
22+
{
23+
channelName: 'nr_sendCommand',
24+
module: { name: '@redis/client', versionRange: '>=4', filePath: 'dist/lib/client/index.js' },
25+
functionQuery: {
26+
className: 'RedisClient',
27+
methodName: 'sendCommand',
28+
kind: 'Async'
29+
}
30+
}
31+
]
32+
}
33+
34+
const commandsExecutor = {
35+
path: './redis-client/commands-executor',
36+
instrumentations: [
37+
{
38+
channelName: 'nr_commandsExecutor',
39+
module: { name: '@redis/client', versionRange: '>=1 <4', filePath: 'dist/lib/client/index.js' },
40+
functionQuery: {
41+
className: 'RedisClient',
42+
methodName: 'commandsExecutor',
43+
kind: 'Async'
44+
}
45+
}
46+
]
47+
}
48+
49+
const clientSelect = {
50+
path: './redis-client/select',
51+
instrumentations: [
52+
{
53+
channelName: 'nr_select',
54+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
55+
functionQuery: {
56+
className: 'RedisClient',
57+
methodName: 'SELECT',
58+
kind: 'Async'
59+
}
60+
}
61+
]
62+
}
63+
64+
const clientMulti = {
65+
path: './redis-client/multi',
66+
instrumentations: [
67+
{
68+
channelName: 'nr_multi',
69+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
70+
functionQuery: {
71+
className: 'RedisClient',
72+
methodName: 'MULTI',
73+
kind: 'Sync'
74+
}
75+
}
76+
]
77+
}
78+
79+
module.exports = {
80+
'@redis/client': [
81+
addCommand,
82+
sendCommand, // redis v5, @redis/client v4
83+
clientSelect,
84+
clientMulti,
85+
commandsExecutor // redis v4, @redis/client v1
86+
]
87+
}
File renamed without changes.

lib/subscribers/redis/config.js

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,23 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
const addCommand = {
7-
path: './redis/add-command',
8-
instrumentations: [{
9-
channelName: 'nr_addCommand',
10-
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/commands-queue.js' },
11-
functionQuery: {
12-
className: 'RedisCommandsQueue',
13-
methodName: 'addCommand',
14-
kind: 'Async'
15-
}
16-
}]
17-
}
18-
19-
const sendCommand = {
20-
path: './redis/send-command',
21-
instrumentations: [
22-
{
23-
channelName: 'nr_sendCommand',
24-
module: { name: '@redis/client', versionRange: '>=4', filePath: 'dist/lib/client/index.js' },
25-
functionQuery: {
26-
className: 'RedisClient',
27-
methodName: 'sendCommand',
28-
kind: 'Async'
29-
}
30-
}
31-
]
32-
}
33-
34-
const clientSelect = {
35-
path: './redis/select',
6+
const internalSendCommand = {
7+
path: './redis/internal-send-command',
368
instrumentations: [
379
{
38-
channelName: 'nr_select',
39-
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
10+
channelName: 'nr_internalSendCommand',
11+
module: { name: 'redis', versionRange: '>=2.6.0 <4', filePath: 'index.js' },
4012
functionQuery: {
41-
className: 'RedisClient',
42-
methodName: 'SELECT',
43-
kind: 'Async'
44-
}
45-
}
46-
]
47-
}
48-
49-
const clientMulti = {
50-
path: './redis/multi',
51-
instrumentations: [
52-
{
53-
channelName: 'nr_multi',
54-
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
55-
functionQuery: {
56-
className: 'RedisClient',
57-
methodName: 'MULTI',
13+
// className: 'RedisClient',
14+
methodName: 'internal_send_command',
5815
kind: 'Sync'
5916
}
6017
}
6118
]
6219
}
6320

64-
const commandsExecutor = {
65-
path: './redis/commands-executor',
66-
instrumentations: [
67-
{
68-
channelName: 'nr_commandsExecutor',
69-
module: { name: '@redis/client', versionRange: '>=1 <4', filePath: 'dist/lib/client/index.js' },
70-
functionQuery: {
71-
className: 'RedisClient',
72-
methodName: 'commandsExecutor',
73-
kind: 'Async'
74-
}
75-
}
76-
]
77-
}
78-
7921
module.exports = {
80-
'@redis/client': [
81-
addCommand,
82-
sendCommand, // >=v5
83-
clientSelect,
84-
clientMulti,
85-
commandsExecutor // v4
22+
redis: [
23+
internalSendCommand // redis v3
8624
]
8725
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2026 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
const DbOperationSubscriber = require('../db-operation')
8+
const { redisClientOpts } = require('../../symbols')
9+
10+
module.exports = class ClientInternalSendCommandSubscriber extends DbOperationSubscriber {
11+
constructor({ agent, logger }) {
12+
super({ agent, logger, channelName: 'nr_internalSendCommand', packageName: 'redis' })
13+
this.events = ['start']
14+
}
15+
16+
start(data) {
17+
const { self: client } = data
18+
if (!client[redisClientOpts]) {
19+
client[redisClientOpts] = this.getRedisParams(client.options)
20+
}
21+
return super.asyncStart(data)
22+
}
23+
24+
/**
25+
* Extracts the datastore parameters from the client options
26+
*
27+
* @param {object} clientOpts client.options
28+
* @returns {object} { host, port_path_or_id, database_name }
29+
*/
30+
getRedisParams(clientOpts) {
31+
// need to replicate logic done in RedisClient
32+
// to parse the url to assign to socket.host/port
33+
// see: https://github.com/redis/node-redis/blob/5576a0db492cda2cd88e09881bc330aa956dd0f5/packages/client/lib/client/index.ts#L160
34+
if (clientOpts?.url) {
35+
const parsedURL = new URL(clientOpts.url)
36+
clientOpts.socket = Object.assign({}, clientOpts.socket, { host: parsedURL.hostname })
37+
if (parsedURL.port) {
38+
clientOpts.socket.port = parsedURL.port
39+
}
40+
41+
if (parsedURL.pathname) {
42+
clientOpts.database = parsedURL.pathname.substring(1)
43+
}
44+
}
45+
46+
return {
47+
host: clientOpts?.host || clientOpts?.socket?.host || 'localhost',
48+
port_path_or_id:
49+
clientOpts?.port || clientOpts?.socket?.path || clientOpts?.socket?.port || '6379',
50+
database_name: clientOpts?.database || 0
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)