@gasket/plugin-elastic-apm 7.0.0-cli.6 → 7.0.0-next.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.
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'http';
2
2
  import type { AgentConfigOptions, Transaction } from 'elastic-apm-node';
3
+ import type { MaybeAsync } from '@gasket/engine';
3
4
 
4
5
  declare module '@gasket/engine' {
5
6
  export interface GasketConfig {
@@ -7,7 +8,11 @@ declare module '@gasket/engine' {
7
8
  sensitiveCookies?: Array<string>
8
9
  },
9
10
  }
10
-
11
+
12
+ export interface Gasket {
13
+ apm?: Agent;
14
+ }
15
+
11
16
  export interface HookExecTypes {
12
17
  apmTransaction(
13
18
  transaction: Transaction,
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ const isActive = (config, env) => {
25
25
  module.exports = {
26
26
  hooks: {
27
27
  configure: {
28
- handler: async (gasket, config) => {
28
+ handler: (gasket, config) => {
29
29
  config.elasticAPM = config.elasticAPM || {};
30
30
 
31
31
  // eslint-disable-next-line no-process-env
package/lib/middleware.js CHANGED
@@ -10,7 +10,6 @@
10
10
  */
11
11
 
12
12
  const { callbackify } = require('util');
13
- const apm = require('elastic-apm-node');
14
13
 
15
14
  /**
16
15
  * Middleware for customizing transactions
@@ -20,6 +19,12 @@ const apm = require('elastic-apm-node');
20
19
  * @param {Response} res The server response
21
20
  */
22
21
  async function customizeTransaction(gasket, req, res) {
22
+ const apm = gasket.apm;
23
+
24
+ if (!apm?.isStarted()) {
25
+ return;
26
+ }
27
+
23
28
  const transaction = apm.currentTransaction;
24
29
  if (!transaction) {
25
30
  return;
@@ -28,6 +33,9 @@ async function customizeTransaction(gasket, req, res) {
28
33
  await gasket.exec('apmTransaction', transaction, { req, res });
29
34
  }
30
35
 
31
- module.exports = (gasket) => [
32
- callbackify(async (req, res) => customizeTransaction(gasket, req, res))
33
- ];
36
+ module.exports = (gasket) => {
37
+ return (
38
+ gasket.apm
39
+ && [callbackify(async (req, res) => customizeTransaction(gasket, req, res))]
40
+ );
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasket/plugin-elastic-apm",
3
- "version": "7.0.0-cli.6",
3
+ "version": "7.0.0-next.0",
4
4
  "description": "Adds Elastic APM instrumentation to your application",
5
5
  "main": "lib",
6
6
  "types": "lib/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-elastic-apm",
42
42
  "devDependencies": {
43
- "@gasket/engine": "^7.0.0-cli.6",
43
+ "@gasket/engine": "^7.0.0-next.0",
44
44
  "dot-env": "^0.0.1",
45
45
  "elastic-apm-node": "^4.4.1",
46
46
  "eslint": "^8.56.0",
@@ -66,5 +66,5 @@
66
66
  "jest": {
67
67
  "testEnvironment": "node"
68
68
  },
69
- "gitHead": "55e09f4b9d9d059c108f0c4f9ccf442f2ff78ad2"
69
+ "gitHead": "55ab680e659ef5315c1d82f511439f32cca5f2e4"
70
70
  }