@lokalise/fastify-extras 3.1.0 → 4.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.
|
@@ -8,4 +8,8 @@ export interface ErrorReport {
|
|
|
8
8
|
context?: Record<string, unknown>;
|
|
9
9
|
}
|
|
10
10
|
export declare const reportErrorToBugsnag: ({ error, severity, unhandled, context, }: ErrorReport) => false | void;
|
|
11
|
-
export
|
|
11
|
+
export interface BugsnagPluginConfig {
|
|
12
|
+
bugsnag: NodeConfig;
|
|
13
|
+
isEnabled: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const bugsnagPlugin: import("fastify").FastifyPluginCallback<BugsnagPluginConfig, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
@@ -14,7 +14,9 @@ const reportErrorToBugsnag = ({ error, severity = 'error', unhandled = true, con
|
|
|
14
14
|
});
|
|
15
15
|
exports.reportErrorToBugsnag = reportErrorToBugsnag;
|
|
16
16
|
function plugin(app, opts, done) {
|
|
17
|
-
|
|
17
|
+
if (opts.isEnabled) {
|
|
18
|
+
js_1.default.start(opts.bugsnag);
|
|
19
|
+
}
|
|
18
20
|
done();
|
|
19
21
|
}
|
|
20
22
|
exports.bugsnagPlugin = (0, fastify_plugin_1.default)(plugin, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bugsnagPlugin.js","sourceRoot":"","sources":["../../lib/plugins/bugsnagPlugin.ts"],"names":[],"mappings":";;;;AACA,6DAAiC;AAGjC,4EAA+B;AAWxB,MAAM,oBAAoB,GAAG,CAAC,EACnC,KAAK,EACL,QAAQ,GAAG,OAAO,EAClB,SAAS,GAAG,IAAI,EAChB,OAAO,GACK,EAAE,EAAE,CAChB,YAAO,CAAC,SAAS,EAAE;IACnB,YAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC9B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACzB,KAAK,CAAC,SAAS,GAAG,SAAS,CAAA;QAC3B,IAAI,OAAO,EAAE;YACX,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;SACtC;IACH,CAAC,CAAC,CAAA;AAbS,QAAA,oBAAoB,wBAa7B;
|
|
1
|
+
{"version":3,"file":"bugsnagPlugin.js","sourceRoot":"","sources":["../../lib/plugins/bugsnagPlugin.ts"],"names":[],"mappings":";;;;AACA,6DAAiC;AAGjC,4EAA+B;AAWxB,MAAM,oBAAoB,GAAG,CAAC,EACnC,KAAK,EACL,QAAQ,GAAG,OAAO,EAClB,SAAS,GAAG,IAAI,EAChB,OAAO,GACK,EAAE,EAAE,CAChB,YAAO,CAAC,SAAS,EAAE;IACnB,YAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC9B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACzB,KAAK,CAAC,SAAS,GAAG,SAAS,CAAA;QAC3B,IAAI,OAAO,EAAE;YACX,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;SACtC;IACH,CAAC,CAAC,CAAA;AAbS,QAAA,oBAAoB,wBAa7B;AAOJ,SAAS,MAAM,CAAC,GAAoB,EAAE,IAAyB,EAAE,IAAgB;IAC/E,IAAI,IAAI,CAAC,SAAS,EAAE;QAClB,YAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;KAC5B;IAED,IAAI,EAAE,CAAA;AACR,CAAC;AAEY,QAAA,aAAa,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IACtC,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,gBAAgB;CACvB,CAAC,CAAA"}
|
|
@@ -3,11 +3,15 @@ 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
|
-
|
|
6
|
+
let newrelic;
|
|
7
7
|
class NewRelicTransactionManager {
|
|
8
8
|
isEnabled;
|
|
9
9
|
transactionMap;
|
|
10
10
|
constructor(isNewRelicEnabled) {
|
|
11
|
+
if (isNewRelicEnabled) {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
13
|
+
newrelic = require('newrelic');
|
|
14
|
+
}
|
|
11
15
|
this.isEnabled = isNewRelicEnabled;
|
|
12
16
|
this.transactionMap = new Map();
|
|
13
17
|
}
|
|
@@ -15,8 +19,8 @@ class NewRelicTransactionManager {
|
|
|
15
19
|
if (!this.isEnabled) {
|
|
16
20
|
return;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
this.transactionMap.set(jobName,
|
|
22
|
+
newrelic.startBackgroundTransaction(jobName, () => {
|
|
23
|
+
this.transactionMap.set(jobName, newrelic.getTransaction());
|
|
20
24
|
});
|
|
21
25
|
}
|
|
22
26
|
stop(jobId) {
|
|
@@ -35,16 +39,18 @@ exports.NewRelicTransactionManager = NewRelicTransactionManager;
|
|
|
35
39
|
function plugin(fastify, opts, done) {
|
|
36
40
|
const manager = new NewRelicTransactionManager(opts.isEnabled);
|
|
37
41
|
fastify.decorate('newrelicTransactionManager', manager);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (opts.isEnabled) {
|
|
43
|
+
fastify.addHook('onClose', async () => {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
newrelic.shutdown((error) => {
|
|
46
|
+
if (error) {
|
|
47
|
+
return reject(error);
|
|
48
|
+
}
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
45
51
|
});
|
|
46
52
|
});
|
|
47
|
-
}
|
|
53
|
+
}
|
|
48
54
|
done();
|
|
49
55
|
}
|
|
50
56
|
exports.newrelicTransactionManagerPlugin = (0, fastify_plugin_1.default)(plugin, {
|
|
@@ -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,4EAA+B;AAc/B,IAAI,QAAkB,CAAA;AAYtB,MAAa,0BAA0B;IACpB,SAAS,CAAS;IAClB,cAAc,CAAgC;IAE/D,YAAY,iBAA0B;QACpC,IAAI,iBAAiB,EAAE;YACrB,mEAAmE;YACnE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;SAC/B;QAED,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAA;IACjC,CAAC;IAEM,KAAK,CAAC,OAAe;QAC1B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAM;SACP;QAED,QAAQ,CAAC,0BAA0B,CAAC,OAAO,EAAE,GAAG,EAAE;YAChD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,IAAI,CAAC,KAAa;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAM;SACP;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAA;QAC1D,IAAI,IAAI,KAAK,WAAW,EAAE;YACxB,OAAM;SACP;QACD,WAAW,CAAC,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,K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