@gasket/plugin-elastic-apm 7.4.9 → 7.5.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.
@@ -0,0 +1,65 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ Object.defineProperty(exports, "getApmTransaction", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return getApmTransaction;
8
+ }
9
+ });
10
+ const _request = require("@gasket/request");
11
+ function _getRequireWildcardCache(nodeInterop) {
12
+ if (typeof WeakMap !== "function") return null;
13
+ var cacheBabelInterop = new WeakMap();
14
+ var cacheNodeInterop = new WeakMap();
15
+ return (_getRequireWildcardCache = function(nodeInterop) {
16
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
17
+ })(nodeInterop);
18
+ }
19
+ function _interop_require_wildcard(obj, nodeInterop) {
20
+ if (!nodeInterop && obj && obj.__esModule) {
21
+ return obj;
22
+ }
23
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
24
+ return {
25
+ default: obj
26
+ };
27
+ }
28
+ var cache = _getRequireWildcardCache(nodeInterop);
29
+ if (cache && cache.has(obj)) {
30
+ return cache.get(obj);
31
+ }
32
+ var newObj = {
33
+ __proto__: null
34
+ };
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for(var key in obj){
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ const getApmTransaction = (0, _request.withGasketRequestCache)(async function getApmTransaction(gasket, req) {
53
+ const apm = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("elastic-apm-node")));
54
+ if (!apm?.default?.isStarted()) {
55
+ return;
56
+ }
57
+ const transaction = apm.default.currentTransaction;
58
+ if (!transaction) {
59
+ return;
60
+ }
61
+ await gasket.exec('apmTransaction', transaction, {
62
+ req
63
+ });
64
+ return transaction;
65
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Determines if the Elastic APM agent has sufficient config to be active
3
+ * @param {import('./index.js').ExtendedAgentConfigOptions} config Apm agent config
4
+ * @param {Record<string, string | undefined>} env Environment variables
5
+ * @returns {boolean} A combined config object
6
+ */ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ Object.defineProperty(exports, /** @type {import('@gasket/core').HookHandler<'configure'>} */ "default", {
10
+ enumerable: true,
11
+ get: function() {
12
+ return configure;
13
+ }
14
+ });
15
+ const isActive = (config, env)=>{
16
+ const { active, serverUrl, secretToken } = config;
17
+ if (active || env.ELASTIC_APM_ACTIVE) {
18
+ return true;
19
+ }
20
+ const combined = {
21
+ serverUrl: serverUrl || env.ELASTIC_APM_SERVER_URL,
22
+ secretToken: secretToken || env.ELASTIC_APM_SECRET_TOKEN
23
+ };
24
+ if (combined.serverUrl && combined.secretToken) {
25
+ return true;
26
+ }
27
+ return false;
28
+ };
29
+ function configure(gasket, config) {
30
+ config.elasticAPM = config.elasticAPM || {};
31
+ // eslint-disable-next-line no-process-env
32
+ config.elasticAPM.active = isActive(config.elasticAPM, process.env);
33
+ return {
34
+ ...config
35
+ };
36
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Returns an array of cookie names which are considered sensitive because they
3
+ * may contain session credential or PII
4
+ * @param {import('@gasket/core').GasketConfig} config the Gasket config
5
+ * @returns {string[]} an array of cookie names
6
+ */ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ function _export(target, all) {
10
+ for(var name in all)Object.defineProperty(target, name, {
11
+ enumerable: true,
12
+ get: all[name]
13
+ });
14
+ }
15
+ _export(exports, {
16
+ filterSensitiveCookies: function() {
17
+ return filterSensitiveCookies;
18
+ },
19
+ sensitiveCookies: function() {
20
+ return sensitiveCookies;
21
+ }
22
+ });
23
+ const sensitiveCookies = (config)=>{
24
+ if (typeof config.elasticAPM === 'undefined' || typeof config.elasticAPM.sensitiveCookies === 'undefined') {
25
+ return [];
26
+ }
27
+ return config.elasticAPM.sensitiveCookies;
28
+ };
29
+ const filterSensitiveCookies = function(config) {
30
+ return function(payload) {
31
+ const cookiesToRedact = sensitiveCookies(config);
32
+ if (payload.context && payload.context.request && payload.context.request.headers && payload.context.request.headers.cookie) {
33
+ let cookie = payload.context.request.headers.cookie;
34
+ cookiesToRedact.forEach((sc)=>{
35
+ cookie = cookie.replace(new RegExp(sc + '=([^;]+)'), sc + '=[REDACTED]');
36
+ });
37
+ payload.context.request.headers.cookie = cookie;
38
+ }
39
+ if (payload.context && payload.context.request && payload.context.request.cookies) {
40
+ cookiesToRedact.forEach((sc)=>{
41
+ if (sc in payload.context.request.cookies) {
42
+ payload.context.request.cookies[sc] = '[REDACTED]';
43
+ }
44
+ });
45
+ }
46
+ return payload;
47
+ };
48
+ };
package/cjs/create.cjs ADDED
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ Object.defineProperty(exports, /** @type {import('@gasket/core').HookHandler<'create'>} */ "default", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return create;
8
+ }
9
+ });
10
+ const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
11
+ function _interop_require_default(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ const { name, version, devDependencies } = _packagejson.default;
17
+ function create(gasket, { pkg, files, gasketConfig }) {
18
+ const generatorDir = new URL('../generator', require("url").pathToFileURL(__filename).toString()).pathname;
19
+ gasketConfig.addPlugin('pluginElasticApm', name);
20
+ pkg.add('dependencies', {
21
+ [name]: `^${version}`,
22
+ 'dotenv': devDependencies.dotenv,
23
+ 'elastic-apm-node': devDependencies['elastic-apm-node']
24
+ });
25
+ pkg.extend((current)=>{
26
+ return {
27
+ scripts: {
28
+ start: `NODE_OPTIONS=--import=./setup.js ${current.scripts.start}`
29
+ }
30
+ };
31
+ });
32
+ files.add(`${generatorDir}/*`);
33
+ }
package/cjs/index.cjs ADDED
@@ -0,0 +1,109 @@
1
+ /// <reference types="create-gasket-app" />
2
+ /// <reference types="@gasket/plugin-metadata" />
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return _default;
10
+ }
11
+ });
12
+ const _actions = /*#__PURE__*/ _interop_require_wildcard(require("./actions.cjs"));
13
+ const _create = /*#__PURE__*/ _interop_require_default(require("./create.cjs"));
14
+ const _configure = /*#__PURE__*/ _interop_require_default(require("./configure.cjs"));
15
+ const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
16
+ function _interop_require_default(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
21
+ function _getRequireWildcardCache(nodeInterop) {
22
+ if (typeof WeakMap !== "function") return null;
23
+ var cacheBabelInterop = new WeakMap();
24
+ var cacheNodeInterop = new WeakMap();
25
+ return (_getRequireWildcardCache = function(nodeInterop) {
26
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
27
+ })(nodeInterop);
28
+ }
29
+ function _interop_require_wildcard(obj, nodeInterop) {
30
+ if (!nodeInterop && obj && obj.__esModule) {
31
+ return obj;
32
+ }
33
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
34
+ return {
35
+ default: obj
36
+ };
37
+ }
38
+ var cache = _getRequireWildcardCache(nodeInterop);
39
+ if (cache && cache.has(obj)) {
40
+ return cache.get(obj);
41
+ }
42
+ var newObj = {
43
+ __proto__: null
44
+ };
45
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
46
+ for(var key in obj){
47
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
48
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
49
+ if (desc && (desc.get || desc.set)) {
50
+ Object.defineProperty(newObj, key, desc);
51
+ } else {
52
+ newObj[key] = obj[key];
53
+ }
54
+ }
55
+ }
56
+ newObj.default = obj;
57
+ if (cache) {
58
+ cache.set(obj, newObj);
59
+ }
60
+ return newObj;
61
+ }
62
+ const { name, version, description } = _packagejson.default;
63
+ /** @type {import('@gasket/core').Plugin} */ const plugin = {
64
+ name,
65
+ version,
66
+ description,
67
+ actions: _actions,
68
+ hooks: {
69
+ configure: _configure.default,
70
+ create: _create.default,
71
+ metadata (gasket, meta) {
72
+ return {
73
+ ...meta,
74
+ actions: [
75
+ {
76
+ name: 'getApmTransaction',
77
+ description: 'Get the APM transaction data',
78
+ link: 'README.md#getApmTransaction'
79
+ }
80
+ ],
81
+ configurations: [
82
+ {
83
+ name: 'elasticAPM',
84
+ link: 'README.md#configuration',
85
+ description: 'Configuration to provide additional setup helpers',
86
+ type: 'object'
87
+ },
88
+ {
89
+ name: 'elasticAPM.sensitiveCookies',
90
+ link: 'README.md#configuration',
91
+ description: 'List of sensitive cookies to filter',
92
+ type: 'string[]',
93
+ default: '[]'
94
+ }
95
+ ],
96
+ lifecycles: [
97
+ {
98
+ name: 'apmTransaction',
99
+ method: 'exec',
100
+ description: 'Modify the APM transaction',
101
+ link: 'README.md#apmtransaction',
102
+ parent: 'middleware'
103
+ }
104
+ ]
105
+ };
106
+ }
107
+ }
108
+ };
109
+ const _default = plugin;
@@ -0,0 +1 @@
1
+ {}
package/lib/actions.js CHANGED
@@ -1,15 +1,15 @@
1
- const { withGasketRequestCache } = require('@gasket/request');
1
+ import { withGasketRequestCache } from '@gasket/request';
2
2
 
3
3
  /** @type {import('@gasket/core').ActionHandler<'getApmTransaction'>} */
4
- const getApmTransaction = withGasketRequestCache(
4
+ export const getApmTransaction = withGasketRequestCache(
5
5
  async function getApmTransaction(gasket, req) {
6
- const apm = require('elastic-apm-node');
6
+ const apm = await import('elastic-apm-node');
7
7
 
8
- if (!apm?.isStarted()) {
8
+ if (!apm?.default?.isStarted()) {
9
9
  return;
10
10
  }
11
11
 
12
- const transaction = apm.currentTransaction;
12
+ const transaction = apm.default.currentTransaction;
13
13
  if (!transaction) {
14
14
  return;
15
15
  }
@@ -19,7 +19,3 @@ const getApmTransaction = withGasketRequestCache(
19
19
  return transaction;
20
20
  }
21
21
  );
22
-
23
- module.exports = {
24
- getApmTransaction
25
- };
package/lib/configure.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Determines if the Elastic APM agent has sufficient config to be active
3
- * @param {import('./index').ExtendedAgentConfigOptions} config Apm agent config
4
- * @param {NodeJS.ProcessEnv} env Environment variables
3
+ * @param {import('./index.js').ExtendedAgentConfigOptions} config Apm agent config
4
+ * @param {Record<string, string | undefined>} env Environment variables
5
5
  * @returns {boolean} A combined config object
6
6
  */
7
7
  const isActive = (config, env) => {
@@ -24,11 +24,11 @@ const isActive = (config, env) => {
24
24
  };
25
25
 
26
26
  /** @type {import('@gasket/core').HookHandler<'configure'>} */
27
- module.exports = function configure(gasket, config) {
27
+ export default function configure(gasket, config) {
28
28
  config.elasticAPM = config.elasticAPM || {};
29
29
 
30
30
  // eslint-disable-next-line no-process-env
31
31
  config.elasticAPM.active = isActive(config.elasticAPM, process.env);
32
32
 
33
33
  return { ...config };
34
- };
34
+ }
package/lib/cookies.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * @param {import('@gasket/core').GasketConfig} config the Gasket config
5
5
  * @returns {string[]} an array of cookie names
6
6
  */
7
- const sensitiveCookies = (config) => {
7
+ export const sensitiveCookies = (config) => {
8
8
  if (
9
9
  typeof config.elasticAPM === 'undefined' ||
10
10
  typeof config.elasticAPM.sensitiveCookies === 'undefined'
@@ -17,9 +17,9 @@ const sensitiveCookies = (config) => {
17
17
 
18
18
  /**
19
19
  * Redacts the contents of user-specified sensitive cookies
20
- * @type {import('.').filterSensitiveCookies}
20
+ * @type {import('./index.js').filterSensitiveCookies}
21
21
  */
22
- const filterSensitiveCookies = function (config) {
22
+ export const filterSensitiveCookies = function (config) {
23
23
  return function (payload) {
24
24
  const cookiesToRedact = sensitiveCookies(config);
25
25
 
@@ -54,8 +54,3 @@ const filterSensitiveCookies = function (config) {
54
54
  return payload;
55
55
  };
56
56
  };
57
-
58
- module.exports = {
59
- filterSensitiveCookies,
60
- sensitiveCookies
61
- };
package/lib/create.js CHANGED
@@ -1,8 +1,9 @@
1
- const { name, version, devDependencies } = require('../package.json');
1
+ import packageJson from '../package.json' with { type: 'json' };
2
+ const { name, version, devDependencies } = packageJson;
2
3
 
3
4
  /** @type {import('@gasket/core').HookHandler<'create'>} */
4
- module.exports = function create(gasket, { pkg, files, gasketConfig }) {
5
- const generatorDir = `${__dirname}/../generator`;
5
+ export default function create(gasket, { pkg, files, gasketConfig }) {
6
+ const generatorDir = new URL('../generator', import.meta.url).pathname;
6
7
 
7
8
  gasketConfig.addPlugin('pluginElasticApm', name);
8
9
 
@@ -21,4 +22,4 @@ module.exports = function create(gasket, { pkg, files, gasketConfig }) {
21
22
  });
22
23
 
23
24
  files.add(`${generatorDir}/*`);
24
- };
25
+ }
package/lib/index.js CHANGED
@@ -1,14 +1,11 @@
1
1
  /// <reference types="create-gasket-app" />
2
2
  /// <reference types="@gasket/plugin-metadata" />
3
3
 
4
- const actions = require('./actions');
5
- const create = require('./create');
6
- const configure = require('./configure');
7
- const {
8
- name,
9
- version,
10
- description
11
- } = require('../package.json');
4
+ import * as actions from './actions.js';
5
+ import create from './create.js';
6
+ import configure from './configure.js';
7
+ import packageJson from '../package.json' with { type: 'json' };
8
+ const { name, version, description } = packageJson;
12
9
 
13
10
  /** @type {import('@gasket/core').Plugin} */
14
11
  const plugin = {
@@ -58,4 +55,4 @@ const plugin = {
58
55
  }
59
56
  };
60
57
 
61
- module.exports = plugin;
58
+ export default plugin;
package/package.json CHANGED
@@ -1,13 +1,23 @@
1
1
  {
2
2
  "name": "@gasket/plugin-elastic-apm",
3
- "version": "7.4.9",
3
+ "version": "7.5.0",
4
4
  "description": "Adds Elastic APM instrumentation to your application",
5
- "main": "lib/index.js",
5
+ "type": "module",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
8
8
  "lib",
9
+ "cjs",
9
10
  "EXAMPLES.md"
10
11
  ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./lib/index.d.ts",
15
+ "import": "./lib/index.js",
16
+ "require": "./cjs/index.cjs",
17
+ "default": "./cjs/index.cjs"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
11
21
  "repository": "godaddy/gasket.git",
12
22
  "publishConfig": {
13
23
  "access": "public"
@@ -28,22 +38,21 @@
28
38
  "devDependencies": {
29
39
  "dotenv": "^16.4.7",
30
40
  "elastic-apm-node": "^4.11.0",
31
- "jest": "^29.7.0",
32
- "nyc": "^15.1.0",
41
+ "vitest": "^3.2.0",
42
+ "@gasket/cjs": "^7.1.0",
33
43
  "@gasket/core": "^7.6.3",
34
- "@gasket/plugin-metadata": "^7.5.4",
35
- "create-gasket-app": "^7.4.13"
36
- },
37
- "jest": {
38
- "testEnvironment": "node"
44
+ "@gasket/plugin-metadata": "^7.5.5",
45
+ "create-gasket-app": "^7.4.15"
39
46
  },
40
47
  "scripts": {
48
+ "build": "gasket-cjs ./lib",
49
+ "build:watch": "pnpm run build --watch",
41
50
  "lint": "eslint .",
42
51
  "lint:fix": "pnpm run lint --fix",
43
52
  "posttest": "pnpm run lint && pnpm run typecheck",
44
- "test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest",
53
+ "test": "vitest run --globals",
45
54
  "test:coverage": "pnpm run test --coverage",
46
- "test:watch": "pnpm run test --watch",
55
+ "test:watch": "vitest --watch --globals",
47
56
  "typecheck": "tsc",
48
57
  "typecheck:watch": "tsc --watch"
49
58
  }