@lokalise/fastify-extras 27.0.3 → 27.2.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.
@@ -1,6 +1,6 @@
1
1
  import type { TransactionObservabilityManager } from '@lokalise/node-core';
2
2
  import type { FastifyPluginCallback } from 'fastify';
3
- import type { getTransaction as GetTransaction, shutdown as Shutdown, startBackgroundTransaction as startBackgroundTransactionType } from 'newrelic';
3
+ import type { getTransaction as GetTransaction, setControllerName as SetControllerName, setUserID as SetUserID, shutdown as Shutdown, startBackgroundTransaction as startBackgroundTransactionType } from 'newrelic';
4
4
  interface Newrelic {
5
5
  startBackgroundTransaction: typeof startBackgroundTransactionType;
6
6
  shutdown: typeof Shutdown;
@@ -9,6 +9,8 @@ interface Newrelic {
9
9
  addCustomAttributes(atts: {
10
10
  [key: string]: string | number | boolean;
11
11
  }): void;
12
+ setUserID: typeof SetUserID;
13
+ setControllerName: typeof SetControllerName;
12
14
  }
13
15
  declare module 'fastify' {
14
16
  interface FastifyInstance {
@@ -28,6 +30,8 @@ export declare class NewRelicTransactionManager implements TransactionObservabil
28
30
  addCustomAttributes(_uniqueTransactionKey: string, atts: {
29
31
  [p: string]: string | number | boolean;
30
32
  }): void;
33
+ setUserID(userId: string): void;
34
+ setControllerName(name: string, action: string): void;
31
35
  /**
32
36
  * @param transactionName - used for grouping similar transactions together
33
37
  * @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions
@@ -12,33 +12,46 @@ export class NewRelicTransactionManager {
12
12
  static async create(isNewRelicEnabled) {
13
13
  let newrelic = undefined;
14
14
  if (isNewRelicEnabled) {
15
+ // newrelic import is returning a wrapper, property `default` is the actual newrelic object
15
16
  // @ts-ignore
16
17
  newrelic = (await import('newrelic')).default;
17
18
  }
18
19
  return new NewRelicTransactionManager(isNewRelicEnabled, newrelic);
19
20
  }
20
21
  addCustomAttribute(attrName, attrValue) {
21
- if (!this.isEnabled) {
22
+ if (!this.isEnabled)
22
23
  return;
23
- }
24
- this.newrelic?.addCustomAttribute(attrName, attrValue);
24
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
25
+ this.newrelic.addCustomAttribute(attrName, attrValue);
25
26
  }
26
27
  addCustomAttributes(_uniqueTransactionKey, atts) {
27
- if (!this.isEnabled) {
28
+ if (!this.isEnabled)
28
29
  return;
29
- }
30
- this.newrelic?.addCustomAttributes(atts);
30
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
31
+ this.newrelic.addCustomAttributes(atts);
32
+ }
33
+ setUserID(userId) {
34
+ if (!this.isEnabled)
35
+ return;
36
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
37
+ this.newrelic.setUserID(userId);
38
+ }
39
+ setControllerName(name, action) {
40
+ if (!this.isEnabled)
41
+ return;
42
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
43
+ this.newrelic.setControllerName(name, action);
31
44
  }
32
45
  /**
33
46
  * @param transactionName - used for grouping similar transactions together
34
47
  * @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions
35
48
  */
36
49
  start(transactionName, uniqueTransactionKey) {
37
- if (!this.isEnabled) {
50
+ if (!this.isEnabled)
38
51
  return;
39
- }
40
- this.newrelic?.startBackgroundTransaction(transactionName, () => {
41
- // biome-ignore lint/style/noNonNullAssertion: At this point it should be defined
52
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
53
+ this.newrelic.startBackgroundTransaction(transactionName, () => {
54
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
42
55
  this.transactionMap.set(uniqueTransactionKey, this.newrelic.getTransaction());
43
56
  });
44
57
  }
@@ -51,19 +64,18 @@ export class NewRelicTransactionManager {
51
64
  if (!this.isEnabled) {
52
65
  return;
53
66
  }
54
- this.newrelic?.startBackgroundTransaction(transactionName, transactionGroup, () => {
55
- // biome-ignore lint/style/noNonNullAssertion: At this point it should be defined
67
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
68
+ this.newrelic.startBackgroundTransaction(transactionName, transactionGroup, () => {
69
+ // biome-ignore lint/style/noNonNullAssertion: It should be defined
56
70
  this.transactionMap.set(uniqueTransactionKey, this.newrelic.getTransaction());
57
71
  });
58
72
  }
59
73
  stop(uniqueTransactionKey) {
60
- if (!this.isEnabled) {
74
+ if (!this.isEnabled)
61
75
  return;
62
- }
63
76
  const transaction = this.transactionMap.get(uniqueTransactionKey) ?? null;
64
- if (!transaction) {
77
+ if (!transaction)
65
78
  return;
66
- }
67
79
  transaction.end();
68
80
  this.transactionMap.delete(uniqueTransactionKey);
69
81
  }
@@ -75,9 +87,8 @@ async function plugin(fastify, opts) {
75
87
  fastify.addHook('onClose', async () => {
76
88
  return new Promise((resolve, reject) => {
77
89
  manager.newrelic?.shutdown((error) => {
78
- if (error) {
90
+ if (error)
79
91
  return reject(error);
80
- }
81
92
  resolve();
82
93
  });
83
94
  });
@@ -1 +1 @@
1
- {"version":3,"file":"newrelicTransactionManagerPlugin.js","sourceRoot":"","sources":["../../lib/plugins/newrelicTransactionManagerPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAO/B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAoBpC,MAAM,OAAO,0BAA0B;IACrB,QAAQ,CAAW;IAElB,SAAS,CAAS;IAClB,cAAc,CAA4B;IAE3D,YAAoB,iBAA0B,EAAE,QAAmB;QACjE,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACzC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,iBAA0B;QACnD,IAAI,QAAQ,GAAyB,SAAS,CAAA;QAC9C,IAAI,iBAAiB,EAAE,CAAC;YACtB,aAAa;YACb,QAAQ,GAAG,CAAC,MAAM,MAAM,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,oBAAoB,CAAC,CAAA;IAClD,CAAC;CACF;AAED,KAAK,UAAU,MAAM,CAAC,OAAwB,EAAE,IAAuC;IACrF,MAAM,OAAO,GAAG,MAAM,0BAA0B,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACvE,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,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;oBACnC,IAAI,KAAK;wBAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;oBAC/B,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,gCAAgC,GAC3C,EAAE,CAAC,MAAM,EAAE;IACT,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,qCAAqC;CAC5C,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/fastify-extras",
3
- "version": "27.0.3",
3
+ "version": "27.2.0",
4
4
  "description": "Opinionated set of fastify plugins, commonly used in Lokalise",
5
5
  "author": {
6
6
  "name": "Lokalise",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@amplitude/analytics-node": "^1.3.6",
39
39
  "@bugsnag/js": "^8.1.2",
40
- "@lokalise/error-utils": "^2.2.0",
40
+ "@lokalise/error-utils": "^3.0.0",
41
41
  "@splitsoftware/splitio": "^11.0.3",
42
42
  "@supercharge/promise-pool": "^3.2.0",
43
43
  "fastify-metrics": "^12.1.0",
@@ -62,7 +62,7 @@
62
62
  "@amplitude/analytics-types": "^2.8.4",
63
63
  "@biomejs/biome": "^1.9.4",
64
64
  "@lokalise/backend-http-client": "^4.1.1",
65
- "@lokalise/background-jobs-common": "^11.0.0",
65
+ "@lokalise/background-jobs-common": "^12.0.1",
66
66
  "@lokalise/biome-config": "^1.5.0",
67
67
  "@lokalise/node-core": "^13.3.0",
68
68
  "@lokalise/tsconfig": "^1.0.2",
@@ -77,7 +77,7 @@
77
77
  "newrelic": "12.15.0",
78
78
  "pino": "^9.5.0",
79
79
  "pino-pretty": "^13.0.0",
80
- "shx": "^0.3.4",
80
+ "shx": "^0.4.0",
81
81
  "typescript": "^5.7.2",
82
82
  "vitest": "^3.0.8",
83
83
  "zod": "^3.24.1"