@gasket/plugin-elastic-apm 7.0.0-next.68 → 7.0.0-next.69

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/README.md CHANGED
@@ -114,6 +114,35 @@ According to the [Elastic APM docs], the _Elastic APM agent for Node.js is a
114
114
  singleton_. This means that you can require and configure singleton in various
115
115
  hooks of your Gasket app, such as with the [init] or [middleware] lifecycles.
116
116
 
117
+ ## Actions
118
+
119
+ ### getApmTransaction
120
+
121
+ Use the `getApmTransaction` action to access and decorate the current APM
122
+ transaction. This action is available in any lifecycle hook or server-side code.
123
+
124
+ ```js
125
+ // example-plugin.js
126
+
127
+ export default {
128
+ name: 'example-plugin',
129
+ hooks: {
130
+ express(gasket, app) {
131
+ app.use(async (req, res, next) => {
132
+ const transaction = await gasket.actions.getApmTransaction(req);
133
+ const locale = await gasket.actions.getIntlLocale(req);
134
+ transaction.setLabel('locale', locale);
135
+ });
136
+ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ In the above example, we are hooking the express lifecycle to add middleware
142
+ to decorate the transaction.
143
+ Calling `getApmTransaction` will also allow other plugins to decorate the
144
+ transaction by hooking the `apmTransaction` lifecycle discussed next.
145
+
117
146
  ## Lifecycles
118
147
 
119
148
  ### apmTransaction
@@ -142,11 +171,8 @@ export default {
142
171
 
143
172
  ## How it works
144
173
 
145
- This plugin hooks the Gasket [preboot] lifecycle from [@gasket/plugin-start] and
146
- will set up additional filtering, such as for sensitive cookies. If the
147
- `preboot` hook finds that the APM agent has not yet been started using the
148
- recommended `--require elastic-apm-node/start`, it will start it here. However,
149
- you risk not bootstrapping necessary modules with a late start.
174
+ This plugin hooks the Gasket [configure] lifecycle to set additional filtering,
175
+ such as for sensitive cookies.
150
176
 
151
177
  ## License
152
178
 
package/lib/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  const actions = require('./actions');
5
5
  const create = require('./create');
6
- const middleware = require('./middleware');
7
6
  const configure = require('./configure');
8
7
  const {
9
8
  name,
@@ -20,7 +19,6 @@ const plugin = {
20
19
  hooks: {
21
20
  configure,
22
21
  create,
23
- middleware,
24
22
  metadata(gasket, meta) {
25
23
  return {
26
24
  ...meta,
@@ -28,7 +26,7 @@ const plugin = {
28
26
  {
29
27
  name: 'getApmTransaction',
30
28
  description: 'Get the APM transaction data',
31
- link: 'README.md'
29
+ link: 'README.md#getApmTransaction'
32
30
  }
33
31
  ],
34
32
  configurations: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasket/plugin-elastic-apm",
3
- "version": "7.0.0-next.68",
3
+ "version": "7.0.0-next.69",
4
4
  "description": "Adds Elastic APM instrumentation to your application",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -31,16 +31,13 @@
31
31
  "plugin"
32
32
  ],
33
33
  "author": "GoDaddy Operating Company, LLC",
34
- "maintainers": [
35
- "Keith Bartholomew <kbartholomew@godaddy.com>"
36
- ],
37
34
  "license": "MIT",
38
35
  "bugs": {
39
36
  "url": "https://github.com/godaddy/gasket/issues"
40
37
  },
41
38
  "homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-elastic-apm",
42
39
  "devDependencies": {
43
- "@gasket/core": "7.0.0-next.68",
40
+ "@gasket/core": "7.0.0-next.69",
44
41
  "dotenv": "^16.4.5",
45
42
  "elastic-apm-node": "^4.4.1",
46
43
  "eslint": "^8.56.0",
@@ -69,5 +66,5 @@
69
66
  "jest": {
70
67
  "testEnvironment": "node"
71
68
  },
72
- "gitHead": "13b1cf962202f9d7212412d337cbfcd38cd92c2a"
69
+ "gitHead": "b5645f2b3cc18080304c9dbdfeadf6d0005e3893"
73
70
  }
package/lib/middleware.js DELETED
@@ -1,41 +0,0 @@
1
- /// <reference types="@gasket/plugin-express" />
2
-
3
- /**
4
- * Middleware for customizing transactions
5
- * @param {import('@gasket/core').Gasket} gasket - The Gasket engine
6
- * @param {import('http').IncomingMessage} req - The HTTP request being handled
7
- */
8
- async function customizeTransaction(gasket, req) {
9
- const apm = require('elastic-apm-node');
10
- if (!apm?.isStarted()) {
11
- return;
12
- }
13
-
14
- const transaction = apm.currentTransaction;
15
- if (!transaction) {
16
- return;
17
- }
18
-
19
- await gasket.exec('apmTransaction', transaction, { req });
20
- }
21
-
22
- /**
23
- * Add middleware to gather config details
24
- * @type {import('@gasket/core').HookHandler<'middleware'>}
25
- */
26
- module.exports = function middleware(gasket) {
27
- const apm = require('elastic-apm-node');
28
- // eslint-disable-next-line no-undefined
29
- const isStarted = apm.isStarted() || undefined;
30
- return (
31
- isStarted &&
32
- async function apmTransactionMiddleware(req, res, next) {
33
- try {
34
- customizeTransaction(gasket, req);
35
- } catch (error) {
36
- return next(error);
37
- }
38
- next();
39
- }
40
- );
41
- };