@adalo/metrics 0.1.57 → 0.1.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/redisUtils.d.ts +13 -1
- package/lib/redisUtils.d.ts.map +1 -1
- package/lib/redisUtils.js +47 -2
- package/lib/redisUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/redisUtils.js +58 -2
package/lib/redisUtils.d.ts
CHANGED
|
@@ -4,5 +4,17 @@
|
|
|
4
4
|
* @param {string} [defaultAppName='undefined-app'] - Fallback app name if METRICS_APP_NAME is not set.
|
|
5
5
|
* @returns {(client: import('redis').RedisClient, name: string) => void}
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function createSetClientNameForRedisV3(defaultAppName?: string | undefined): (client: import('redis').RedisClient, name: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a function to set Redis client name for node-redis v4
|
|
10
|
+
* @param {string} defaultAppName
|
|
11
|
+
* @returns {(client: ReturnType<createClient>, name: string) => void}
|
|
12
|
+
*/
|
|
13
|
+
export function createSetClientNameForRedisV4(defaultAppName?: string): (client: ReturnType<createClient>, name: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a function to set Redis client name for ioredis
|
|
16
|
+
* @param {string} defaultAppName
|
|
17
|
+
* @returns {(client: Redis, name: string) => void}
|
|
18
|
+
*/
|
|
19
|
+
export function createSetClientNameForIoredis(defaultAppName?: string): (client: Redis, name: string) => void;
|
|
8
20
|
//# sourceMappingURL=redisUtils.d.ts.map
|
package/lib/redisUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,6FAFsB,OAAO,OAAO,EAAE,WAAW,QAAQ,MAAM,KAAK,IAAI,CAuBvE;AA2BD;;;;GAIG;AACH,+DAHW,MAAM,YACK,wBAAwB,QAAQ,MAAM,KAAK,IAAI,CAsBpE;AAlDD;;;;GAIG;AACH,+DAHW,MAAM,yBACkB,MAAM,KAAK,IAAI,CAoBjD"}
|
package/lib/redisUtils.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @param {string} [defaultAppName='undefined-app'] - Fallback app name if METRICS_APP_NAME is not set.
|
|
7
7
|
* @returns {(client: import('redis').RedisClient, name: string) => void}
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
|
|
10
10
|
return (client, name) => {
|
|
11
11
|
const appName = process.env.METRICS_APP_NAME || defaultAppName;
|
|
12
12
|
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno';
|
|
@@ -23,7 +23,52 @@ const createSetClientName = (defaultAppName = 'undefined-app') => {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a function to set Redis client name for ioredis
|
|
29
|
+
* @param {string} defaultAppName
|
|
30
|
+
* @returns {(client: Redis, name: string) => void}
|
|
31
|
+
*/
|
|
32
|
+
const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
|
|
33
|
+
return (client, name) => {
|
|
34
|
+
const appName = process.env.METRICS_APP_NAME || defaultAppName;
|
|
35
|
+
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno';
|
|
36
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
37
|
+
client.once('connect', () => {
|
|
38
|
+
client.call('CLIENT', ['SETNAME', `${appName}:${dyno}:${name}`]).then(() => {
|
|
39
|
+
console.log(`Connected to Redis for pid:${process.pid} (${name})`);
|
|
40
|
+
}).catch(err => {
|
|
41
|
+
console.error(`Failed to set client name for ${name}:`, err);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a function to set Redis client name for node-redis v4
|
|
50
|
+
* @param {string} defaultAppName
|
|
51
|
+
* @returns {(client: ReturnType<createClient>, name: string) => void}
|
|
52
|
+
*/
|
|
53
|
+
const createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {
|
|
54
|
+
return (client, name) => {
|
|
55
|
+
const appName = process.env.METRICS_APP_NAME || defaultAppName;
|
|
56
|
+
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno';
|
|
57
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
58
|
+
client.on('ready', async () => {
|
|
59
|
+
try {
|
|
60
|
+
await client.sendCommand(['CLIENT', 'SETNAME', `${appName}:${dyno}:${name}`]);
|
|
61
|
+
console.log(`Connected to Redis for pid:${process.pid} (${name})`);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(`Failed to set client name for ${name}:`, err);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
26
69
|
module.exports = {
|
|
27
|
-
|
|
70
|
+
createSetClientNameForRedisV3,
|
|
71
|
+
createSetClientNameForRedisV4,
|
|
72
|
+
createSetClientNameForIoredis
|
|
28
73
|
};
|
|
29
74
|
//# sourceMappingURL=redisUtils.js.map
|
package/lib/redisUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redisUtils.js","names":["
|
|
1
|
+
{"version":3,"file":"redisUtils.js","names":["createSetClientNameForRedisV3","defaultAppName","client","name","appName","process","env","METRICS_APP_NAME","dyno","BUILD_DYNO_PROCESS_TYPE","NODE_ENV","on","send_command","err","console","error","log","pid","createSetClientNameForIoredis","once","call","then","catch","createSetClientNameForRedisV4","sendCommand","module","exports"],"sources":["../src/redisUtils.js"],"sourcesContent":["/**\n * Creates a configured setClientName function.\n *\n * @param {string} [defaultAppName='undefined-app'] - Fallback app name if METRICS_APP_NAME is not set.\n * @returns {(client: import('redis').RedisClient, name: string) => void}\n */\nconst createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n const appName = process.env.METRICS_APP_NAME || defaultAppName\n const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\n\n if (process.env.NODE_ENV !== 'test') {\n client.on('connect', () => {\n client.send_command(\n 'CLIENT',\n ['SETNAME', `${appName}:${dyno}:${name}`],\n err => {\n if (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n } else {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n }\n }\n )\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for ioredis\n * @param {string} defaultAppName\n * @returns {(client: Redis, name: string) => void}\n */\nconst createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n const appName = process.env.METRICS_APP_NAME || defaultAppName\n const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\n\n if (process.env.NODE_ENV !== 'test') {\n client.once('connect', () => {\n client\n .call('CLIENT', ['SETNAME', `${appName}:${dyno}:${name}`])\n .then(() => {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n })\n .catch(err => {\n console.error(`Failed to set client name for ${name}:`, err)\n })\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for node-redis v4\n * @param {string} defaultAppName\n * @returns {(client: ReturnType<createClient>, name: string) => void}\n */\nconst createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n const appName = process.env.METRICS_APP_NAME || defaultAppName\n const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\n\n if (process.env.NODE_ENV !== 'test') {\n client.on('ready', async () => {\n try {\n await client.sendCommand([\n 'CLIENT',\n 'SETNAME',\n `${appName}:${dyno}:${name}`,\n ])\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n } catch (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n }\n })\n }\n }\n}\n\nmodule.exports = {\n createSetClientNameForRedisV3,\n createSetClientNameForRedisV4,\n createSetClientNameForIoredis,\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,6BAA6B,GAAGA,CAACC,cAAc,GAAG,eAAe,KAAK;EAC1E,OAAO,CAACC,MAAM,EAAEC,IAAI,KAAK;IACvB,MAAMC,OAAO,GAAGC,OAAO,CAACC,GAAG,CAACC,gBAAgB,IAAIN,cAAc;IAC9D,MAAMO,IAAI,GAAGH,OAAO,CAACC,GAAG,CAACG,uBAAuB,IAAI,gBAAgB;IAEpE,IAAIJ,OAAO,CAACC,GAAG,CAACI,QAAQ,KAAK,MAAM,EAAE;MACnCR,MAAM,CAACS,EAAE,CAAC,SAAS,EAAE,MAAM;QACzBT,MAAM,CAACU,YAAY,CACjB,QAAQ,EACR,CAAC,SAAS,EAAE,GAAGR,OAAO,IAAII,IAAI,IAAIL,IAAI,EAAE,CAAC,EACzCU,GAAG,IAAI;UACL,IAAIA,GAAG,EAAE;YACPC,OAAO,CAACC,KAAK,CAAC,iCAAiCZ,IAAI,GAAG,EAAEU,GAAG,CAAC;UAC9D,CAAC,MAAM;YACLC,OAAO,CAACE,GAAG,CAAC,8BAA8BX,OAAO,CAACY,GAAG,KAAKd,IAAI,GAAG,CAAC;UACpE;QACF,CACF,CAAC;MACH,CAAC,CAAC;IACJ;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMe,6BAA6B,GAAGA,CAACjB,cAAc,GAAG,eAAe,KAAK;EAC1E,OAAO,CAACC,MAAM,EAAEC,IAAI,KAAK;IACvB,MAAMC,OAAO,GAAGC,OAAO,CAACC,GAAG,CAACC,gBAAgB,IAAIN,cAAc;IAC9D,MAAMO,IAAI,GAAGH,OAAO,CAACC,GAAG,CAACG,uBAAuB,IAAI,gB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AI,GAAG,EAAEU,GAAG,CAAC;QAC9D;MACF,CAAC,CAAC;IACJ;EACF,CAAC;AACH,CAAC;AAEDY,MAAM,CAACC,OAAO,GAAG;EACf1B,6BAA6B;EAC7BuB,6BAA6B;EAC7BL;AACF,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/redisUtils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {string} [defaultAppName='undefined-app'] - Fallback app name if METRICS_APP_NAME is not set.
|
|
5
5
|
* @returns {(client: import('redis').RedisClient, name: string) => void}
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
|
|
8
8
|
return (client, name) => {
|
|
9
9
|
const appName = process.env.METRICS_APP_NAME || defaultAppName
|
|
10
10
|
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'
|
|
@@ -27,4 +27,60 @@ const createSetClientName = (defaultAppName = 'undefined-app') => {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Creates a function to set Redis client name for ioredis
|
|
32
|
+
* @param {string} defaultAppName
|
|
33
|
+
* @returns {(client: Redis, name: string) => void}
|
|
34
|
+
*/
|
|
35
|
+
const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
|
|
36
|
+
return (client, name) => {
|
|
37
|
+
const appName = process.env.METRICS_APP_NAME || defaultAppName
|
|
38
|
+
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'
|
|
39
|
+
|
|
40
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
41
|
+
client.once('connect', () => {
|
|
42
|
+
client
|
|
43
|
+
.call('CLIENT', ['SETNAME', `${appName}:${dyno}:${name}`])
|
|
44
|
+
.then(() => {
|
|
45
|
+
console.log(`Connected to Redis for pid:${process.pid} (${name})`)
|
|
46
|
+
})
|
|
47
|
+
.catch(err => {
|
|
48
|
+
console.error(`Failed to set client name for ${name}:`, err)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates a function to set Redis client name for node-redis v4
|
|
57
|
+
* @param {string} defaultAppName
|
|
58
|
+
* @returns {(client: ReturnType<createClient>, name: string) => void}
|
|
59
|
+
*/
|
|
60
|
+
const createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {
|
|
61
|
+
return (client, name) => {
|
|
62
|
+
const appName = process.env.METRICS_APP_NAME || defaultAppName
|
|
63
|
+
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'
|
|
64
|
+
|
|
65
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
66
|
+
client.on('ready', async () => {
|
|
67
|
+
try {
|
|
68
|
+
await client.sendCommand([
|
|
69
|
+
'CLIENT',
|
|
70
|
+
'SETNAME',
|
|
71
|
+
`${appName}:${dyno}:${name}`,
|
|
72
|
+
])
|
|
73
|
+
console.log(`Connected to Redis for pid:${process.pid} (${name})`)
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error(`Failed to set client name for ${name}:`, err)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = {
|
|
83
|
+
createSetClientNameForRedisV3,
|
|
84
|
+
createSetClientNameForRedisV4,
|
|
85
|
+
createSetClientNameForIoredis,
|
|
86
|
+
}
|