@adalo/metrics 0.1.106 → 0.1.108
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/README.md +1 -1
- package/lib/redisUtils.d.ts +11 -5
- package/lib/redisUtils.d.ts.map +1 -1
- package/lib/redisUtils.js +16 -11
- package/lib/redisUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/redisUtils.js +12 -11
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ import { MetricsClient } from '@adalo/metrics-js'
|
|
|
22
22
|
const metrics = new MetricsClient({ appName: 'my-app', enabled: true })
|
|
23
23
|
|
|
24
24
|
// Express middleware
|
|
25
|
-
app.use(metrics.
|
|
25
|
+
app.use(metrics.trackHttpRequestMiddleware)
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
// Start metrics push
|
package/lib/redisUtils.d.ts
CHANGED
|
@@ -37,11 +37,17 @@ export const REDIS_V4: "REDIS_V4";
|
|
|
37
37
|
export const REDIS_V3: "REDIS_V3";
|
|
38
38
|
export const IOREDIS: "IOREDIS";
|
|
39
39
|
/**
|
|
40
|
-
* Get default
|
|
40
|
+
* Get the default Redis client name.
|
|
41
41
|
*
|
|
42
|
-
* @param {
|
|
43
|
-
* @param {string} [
|
|
44
|
-
* @
|
|
42
|
+
* @param {Object} options - Options for generating Redis name.
|
|
43
|
+
* @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
|
|
44
|
+
* @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
|
|
45
|
+
* @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
|
|
46
|
+
* @returns {string} The generated Redis client name.
|
|
45
47
|
*/
|
|
46
|
-
export function
|
|
48
|
+
export function getRedisName({ name, appName, processName }: {
|
|
49
|
+
name?: string | undefined;
|
|
50
|
+
appName?: string | undefined;
|
|
51
|
+
processName?: string | undefined;
|
|
52
|
+
}): string;
|
|
47
53
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA4BD;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAmB/C;AAjDD;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA2BD;;;;;GAKG;AACH,kCAHW,GAAG,GACD,OAAO,CASnB;AAED;;;;;GAKG;AACH,2CAHW,GAAG,GACD,MAAM,CAiBlB;AArID,kCAA2B;AAC3B,kCAA2B;AAC3B,gCAAyB;AAKzB;;;;;;;;GAQG;AACH;IAL4B,IAAI;IACJ,OAAO;IACP,WAAW;IAC1B,MAAM,CAIlB"}
|
package/lib/redisUtils.js
CHANGED
|
@@ -7,15 +7,20 @@ const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno';
|
|
|
7
7
|
const defaultAppName = process.env.BUILD_APP_NAME || 'undefined-app';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Get default
|
|
10
|
+
* Get the default Redis client name.
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {string} [
|
|
14
|
-
* @
|
|
12
|
+
* @param {Object} options - Options for generating Redis name.
|
|
13
|
+
* @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
|
|
14
|
+
* @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
|
|
15
|
+
* @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
|
|
16
|
+
* @returns {string} The generated Redis client name.
|
|
15
17
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const getRedisName = ({
|
|
19
|
+
name = 'undefined-name',
|
|
20
|
+
appName,
|
|
21
|
+
processName
|
|
22
|
+
}) => {
|
|
23
|
+
return `${appName || defaultAppName}:${processName || dyno}:${name}`;
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
/**
|
|
@@ -28,7 +33,7 @@ const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
|
|
|
28
33
|
return (client, name) => {
|
|
29
34
|
if (process.env.NODE_ENV !== 'test') {
|
|
30
35
|
client.on('connect', () => {
|
|
31
|
-
client.send_command('CLIENT', ['SETNAME',
|
|
36
|
+
client.send_command('CLIENT', ['SETNAME', getRedisName(name, defaultAppName)], err => {
|
|
32
37
|
if (err) {
|
|
33
38
|
console.error(`Failed to set client name for ${name}:`, err);
|
|
34
39
|
} else {
|
|
@@ -50,7 +55,7 @@ const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
|
|
|
50
55
|
return (client, name) => {
|
|
51
56
|
if (process.env.NODE_ENV !== 'test') {
|
|
52
57
|
client.once('connect', () => {
|
|
53
|
-
client.call('CLIENT', ['SETNAME',
|
|
58
|
+
client.call('CLIENT', ['SETNAME', getRedisName(name, defaultAppName)]).then(() => {
|
|
54
59
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`);
|
|
55
60
|
}).catch(err => {
|
|
56
61
|
console.error(`Failed to set client name for ${name}:`, err);
|
|
@@ -71,7 +76,7 @@ const createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {
|
|
|
71
76
|
if (process.env.NODE_ENV !== 'test') {
|
|
72
77
|
client.on('ready', async () => {
|
|
73
78
|
try {
|
|
74
|
-
await client.sendCommand(['CLIENT', 'SETNAME',
|
|
79
|
+
await client.sendCommand(['CLIENT', 'SETNAME', getRedisName(name, defaultAppName)]);
|
|
75
80
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`);
|
|
76
81
|
} catch (err) {
|
|
77
82
|
console.error(`Failed to set client name for ${name}:`, err);
|
|
@@ -121,6 +126,6 @@ module.exports = {
|
|
|
121
126
|
REDIS_V4,
|
|
122
127
|
REDIS_V3,
|
|
123
128
|
IOREDIS,
|
|
124
|
-
|
|
129
|
+
getRedisName
|
|
125
130
|
};
|
|
126
131
|
//# sourceMappingURL=redisUtils.js.map
|
package/lib/redisUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redisUtils.js","names":["REDIS_V4","REDIS_V3","IOREDIS","dyno","process","env","BUILD_DYNO_PROCESS_TYPE","defaultAppName","BUILD_APP_NAME","
|
|
1
|
+
{"version":3,"file":"redisUtils.js","names":["REDIS_V4","REDIS_V3","IOREDIS","dyno","process","env","BUILD_DYNO_PROCESS_TYPE","defaultAppName","BUILD_APP_NAME","getRedisName","name","appName","processName","createSetClientNameForRedisV3","client","NODE_ENV","on","send_command","err","console","error","log","pid","createSetClientNameForIoredis","once","call","then","catch","createSetClientNameForRedisV4","sendCommand","isIORedis","disconnect","options","undefined","getRedisClientType","info","Error","module","exports"],"sources":["../src/redisUtils.js"],"sourcesContent":["const REDIS_V4 = 'REDIS_V4'\nconst REDIS_V3 = 'REDIS_V3'\nconst IOREDIS = 'IOREDIS'\n\nconst dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\nconst defaultAppName = process.env.BUILD_APP_NAME || 'undefined-app'\n\n/**\n * Get the default Redis client name.\n *\n * @param {Object} options - Options for generating Redis name.\n * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.\n * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.\n * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.\n * @returns {string} The generated Redis client name.\n */\nconst getRedisName = ({ name = 'undefined-name', appName, processName }) => {\n return `${appName || defaultAppName}:${processName || dyno}:${name}`\n}\n\n/**\n * Creates a configured setClientName function for node-redis v3.\n *\n * @param {string} [defaultAppName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('connect', () => {\n client.send_command(\n 'CLIENT',\n ['SETNAME', getRedisName(name, defaultAppName)],\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 *\n * @param {string} [defaultAppName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.once('connect', () => {\n client\n .call('CLIENT', [\n 'SETNAME',\n getRedisName(name, defaultAppName),\n ])\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 *\n * @param {string} [defaultAppName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('ready', async () => {\n try {\n await client.sendCommand([\n 'CLIENT',\n 'SETNAME',\n getRedisName(name, defaultAppName),\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\n/**\n * Check if a Redis client is an ioredis instance\n *\n * @param {any} client - Redis client instance\n * @returns {boolean} True if the client is ioredis\n */\nconst isIORedis = client => {\n return (\n client &&\n typeof client.sendCommand === 'function' &&\n typeof client.disconnect === 'function' &&\n client.options !== undefined\n )\n}\n\n/**\n * Get Redis client type\n *\n * @param {any} client - Redis client instance\n * @returns {string} One of IOREDIS, REDIS_V3, REDIS_V4\n */\nconst getRedisClientType = client => {\n if (isIORedis(client)) {\n console.log('Detected node-redis ioredis')\n return IOREDIS\n }\n if (typeof client?.send_command === 'function') {\n console.log('Detected node-redis redis_v3')\n return REDIS_V3\n }\n if (typeof client.info === 'function') {\n console.log('Detected node-redis redis_v4')\n return REDIS_V4\n }\n\n throw new Error(`Failed to get Redis client type`)\n}\n\nmodule.exports = {\n createSetClientNameForRedisV3,\n createSetClientNameForRedisV4,\n createSetClientNameForIoredis,\n isIORedis,\n getRedisClientType,\n REDIS_V4,\n REDIS_V3,\n IOREDIS,\n getRedisName,\n}\n"],"mappings":";;AAAA,MAAMA,QAAQ,GAAG,UAAU;AAC3B,MAAMC,QAAQ,GAAG,UAAU;AAC3B,MAAMC,OAAO,GAAG,SAAS;AAEzB,MAAMC,IAAI,GAAGC,OAAO,CAACC,GAAG,CAACC,uBAAuB,IAAI,gBAAgB;AACpE,MAAMC,cAAc,GAAGH,OAAO,CAACC,GAAG,CAACG,cAAc,IAAI,eAAe;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAGA,CAAC;EAAEC,IAAI,GAAG,gBAAgB;EAAEC,OAAO;EAAEC;AAAY,CAAC,KAAK;EAC1E,OAAO,GAAGD,OAAO,IAAIJ,cAAc,IAAIK,WAAW,IAAIT,IAAI,IAAIO,IAAI,EAAE;AACtE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,6BAA6B,GAAGA,CAACN,cAAc,GAAG,eAAe,KAAK;EAC1E,OAAO,CAACO,MAAM,EAAEJ,IAAI,KAAK;IACvB,IAAIN,OAAO,CAACC,GAAG,CAACU,QAAQ,KAAK,MAAM,EAAE;MACnCD,MAAM,CAACE,EAAE,CAAC,SAAS,EAAE,MAAM;QACzBF,MAAM,CAACG,YAAY,CACjB,QAAQ,EACR,CAAC,SAAS,EAAER,YAAY,CAACC,IAAI,EAAEH,cAAc,CAAC,CAAC,EAC/CW,GAAG,IAAI;UACL,IAAIA,GAAG,EAAE;YAC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isUtils.js
CHANGED
|
@@ -6,15 +6,16 @@ const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'
|
|
|
6
6
|
const defaultAppName = process.env.BUILD_APP_NAME || 'undefined-app'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Get default
|
|
9
|
+
* Get the default Redis client name.
|
|
10
10
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {string} [
|
|
13
|
-
* @
|
|
11
|
+
* @param {Object} options - Options for generating Redis name.
|
|
12
|
+
* @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
|
|
13
|
+
* @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
|
|
14
|
+
* @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
|
|
15
|
+
* @returns {string} The generated Redis client name.
|
|
14
16
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return `${appName || defaultAppName}:${dyno}:${name}`
|
|
17
|
+
const getRedisName = ({ name = 'undefined-name', appName, processName }) => {
|
|
18
|
+
return `${appName || defaultAppName}:${processName || dyno}:${name}`
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -29,7 +30,7 @@ const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
|
|
|
29
30
|
client.on('connect', () => {
|
|
30
31
|
client.send_command(
|
|
31
32
|
'CLIENT',
|
|
32
|
-
['SETNAME',
|
|
33
|
+
['SETNAME', getRedisName(name, defaultAppName)],
|
|
33
34
|
err => {
|
|
34
35
|
if (err) {
|
|
35
36
|
console.error(`Failed to set client name for ${name}:`, err)
|
|
@@ -56,7 +57,7 @@ const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
|
|
|
56
57
|
client
|
|
57
58
|
.call('CLIENT', [
|
|
58
59
|
'SETNAME',
|
|
59
|
-
|
|
60
|
+
getRedisName(name, defaultAppName),
|
|
60
61
|
])
|
|
61
62
|
.then(() => {
|
|
62
63
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`)
|
|
@@ -83,7 +84,7 @@ const createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {
|
|
|
83
84
|
await client.sendCommand([
|
|
84
85
|
'CLIENT',
|
|
85
86
|
'SETNAME',
|
|
86
|
-
|
|
87
|
+
getRedisName(name, defaultAppName),
|
|
87
88
|
])
|
|
88
89
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`)
|
|
89
90
|
} catch (err) {
|
|
@@ -141,5 +142,5 @@ module.exports = {
|
|
|
141
142
|
REDIS_V4,
|
|
142
143
|
REDIS_V3,
|
|
143
144
|
IOREDIS,
|
|
144
|
-
|
|
145
|
+
getRedisName,
|
|
145
146
|
}
|