@lokalise/fastify-extras 18.0.0 → 19.0.0
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.
|
@@ -12,8 +12,13 @@ export declare class NewRelicTransactionManager {
|
|
|
12
12
|
private readonly transactionMap;
|
|
13
13
|
constructor(isNewRelicEnabled: boolean);
|
|
14
14
|
addCustomAttribute(attrName: string, attrValue: string | number | boolean): void;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param transactionName - used for grouping similar transactions together
|
|
18
|
+
* @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions
|
|
19
|
+
*/
|
|
20
|
+
start(transactionName: string, uniqueTransactionKey: string): void;
|
|
21
|
+
stop(uniqueTransactionKey: string): void;
|
|
17
22
|
}
|
|
18
23
|
declare function plugin(fastify: FastifyInstance, opts: NewRelicTransactionManagerOptions, done: () => void): void;
|
|
19
24
|
export declare const newrelicTransactionManagerPlugin: typeof plugin;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.newrelicTransactionManagerPlugin = exports.NewRelicTransactionManager = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fastify_plugin_1 = tslib_1.__importDefault(require("fastify-plugin"));
|
|
6
|
+
const toad_cache_1 = require("toad-cache");
|
|
6
7
|
let newrelic;
|
|
7
8
|
class NewRelicTransactionManager {
|
|
8
9
|
isEnabled;
|
|
@@ -13,7 +14,7 @@ class NewRelicTransactionManager {
|
|
|
13
14
|
newrelic = require('newrelic');
|
|
14
15
|
}
|
|
15
16
|
this.isEnabled = isNewRelicEnabled;
|
|
16
|
-
this.transactionMap = new
|
|
17
|
+
this.transactionMap = new toad_cache_1.FifoMap(2000);
|
|
17
18
|
}
|
|
18
19
|
addCustomAttribute(attrName, attrValue) {
|
|
19
20
|
if (!this.isEnabled) {
|
|
@@ -21,24 +22,29 @@ class NewRelicTransactionManager {
|
|
|
21
22
|
}
|
|
22
23
|
newrelic.addCustomAttribute(attrName, attrValue);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param transactionName - used for grouping similar transactions together
|
|
28
|
+
* @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions
|
|
29
|
+
*/
|
|
30
|
+
start(transactionName, uniqueTransactionKey) {
|
|
25
31
|
if (!this.isEnabled) {
|
|
26
32
|
return;
|
|
27
33
|
}
|
|
28
|
-
newrelic.startBackgroundTransaction(
|
|
29
|
-
this.transactionMap.set(
|
|
34
|
+
newrelic.startBackgroundTransaction(transactionName, () => {
|
|
35
|
+
this.transactionMap.set(uniqueTransactionKey, newrelic.getTransaction());
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
|
-
stop(
|
|
38
|
+
stop(uniqueTransactionKey) {
|
|
33
39
|
if (!this.isEnabled) {
|
|
34
40
|
return;
|
|
35
41
|
}
|
|
36
|
-
const transaction = this.transactionMap.get(
|
|
37
|
-
if (
|
|
42
|
+
const transaction = this.transactionMap.get(uniqueTransactionKey) ?? null;
|
|
43
|
+
if (!transaction) {
|
|
38
44
|
return;
|
|
39
45
|
}
|
|
40
46
|
transaction.end();
|
|
41
|
-
this.transactionMap.delete(
|
|
47
|
+
this.transactionMap.delete(uniqueTransactionKey);
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
exports.NewRelicTransactionManager = NewRelicTransactionManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"newrelicTransactionManagerPlugin.js","sourceRoot":"","sources":["../../lib/plugins/newrelicTransactionManagerPlugin.ts"],"names":[],"mappings":";;;;AACA,4EAA+B;
|
|
1
|
+
{"version":3,"file":"newrelicTransactionManagerPlugin.js","sourceRoot":"","sources":["../../lib/plugins/newrelicTransactionManagerPlugin.ts"],"names":[],"mappings":";;;;AACA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gEAiDC;AAED,SAAS,MAAM,CACb,OAAwB,EACxB,IAAuC,EACvC,IAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAE9D,OAAO,CAAC,QAAQ,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAA;IAEvD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;YACpC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACrC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC1B,IAAI,KAAK,EAAE,CAAC;wBACV,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;oBACtB,CAAC;oBACD,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,EAAE,CAAA;AACR,CAAC;AAEY,QAAA,gCAAgC,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IACzD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,qCAAqC;CAC5C,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestContextProviderPlugin.js","sourceRoot":"","sources":["../../lib/plugins/requestContextProviderPlugin.ts"],"names":[],"mappings":";;;;AAAA,6CAAwC;AAExC,8DAAyD;AASzD,4EAA+B;AAElB,QAAA,oBAAoB,GAAG,YAAY,CAAA;AAyBhD,SAAgB,4BAA4B;IAI1C,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAA,wBAAU,GAAE;QAC5B,eAAe,EAAE,cAAc;KAChC,CAAA;AACH,CAAC;AARD,oEAQC;AAED,SAAS,MAAM,CAAC,OAAwB,EAAE,IAAa,EAAE,IAAgB;IACvE,OAAO,CAAC,OAAO,CACb,WAAW,EACX,SAAS,wBAAwB,CAC/B,GAAmB,EACnB,GAAiB,EACjB,IAA6B;QAE7B,GAAG,CAAC,UAAU,GAAG;YACf,MAAM,
|
|
1
|
+
{"version":3,"file":"requestContextProviderPlugin.js","sourceRoot":"","sources":["../../lib/plugins/requestContextProviderPlugin.ts"],"names":[],"mappings":";;;;AAAA,6CAAwC;AAExC,8DAAyD;AASzD,4EAA+B;AAElB,QAAA,oBAAoB,GAAG,YAAY,CAAA;AAyBhD,SAAgB,4BAA4B;IAI1C,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAA,wBAAU,GAAE;QAC5B,eAAe,EAAE,cAAc;KAChC,CAAA;AACH,CAAC;AARD,oEAQC;AAED,SAAS,MAAM,CAAC,OAAwB,EAAE,IAAa,EAAE,IAAgB;IACvE,OAAO,CAAC,OAAO,CACb,WAAW,EACX,SAAS,wBAAwB,CAC/B,GAAmB,EACnB,GAAiB,EACjB,IAA6B;QAE7B,GAAG,CAAC,UAAU,GAAG;YACf,MAAM,EAAG,GAAG,CAAC,GAAoB,CAAC,KAAK,CAAC;gBACtC,cAAc,EAAE,GAAG,CAAC,EAAE;aACvB,CAAC;YACF,KAAK,EAAE,GAAG,CAAC,EAAE;SACd,CAAA;QAED,0GAA0G;QAC1G,gCAAc,CAAC,GAAG,CAAC,4BAAoB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAA;QAEhD,IAAI,EAAE,CAAA;IACR,CAAC,CACF,CAAA;IAED,OAAO,CAAC,OAAO,CACb,QAAQ,EACR,CAAC,GAAmB,EAAE,GAAiB,EAAE,OAAO,EAAE,IAA6B,EAAE,EAAE;QACjF,KAAK,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,GAAG,CAAC,EAAE,CAAC,CAAA;QACvC,IAAI,EAAE,CAAA;IACR,CAAC,CACF,CAAA;IAED,IAAI,EAAE,CAAA;AACR,CAAC;AAEY,QAAA,4BAA4B,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IACrD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,iCAAiC;CACxC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokalise/fastify-extras",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.0.0",
|
|
4
4
|
"description": "Opinionated set of fastify plugins, commonly used in Lokalise",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Lokalise",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@amplitude/analytics-node": "^1.3.5",
|
|
57
57
|
"fastify-metrics": "^11.0.0",
|
|
58
58
|
"fastify-plugin": "^4.5.1",
|
|
59
|
+
"toad-cache": "^3.7.0",
|
|
59
60
|
"tslib": "^2.6.2"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"@fastify/request-context": "^5.1.0",
|
|
71
|
-
"@lokalise/node-core": "^9.
|
|
72
|
+
"@lokalise/node-core": "^9.16.1",
|
|
72
73
|
"@types/newrelic": "^9.14.3",
|
|
73
74
|
"@types/node": "^20.12.7",
|
|
74
75
|
"@amplitude/analytics-types": "^2.5.0",
|