@gasket/plugin-elastic-apm 6.21.0 → 6.25.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/README.md +59 -24
- package/lib/index.js +41 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ gasket create <app-name> --plugins @gasket/plugin-elastic-apm
|
|
|
13
13
|
#### Existing apps
|
|
14
14
|
|
|
15
15
|
```
|
|
16
|
-
npm
|
|
16
|
+
npm install @gasket/plugin-elastic-apm elastic-apm-node
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Modify `plugins` section of your `gasket.config.js`:
|
|
@@ -28,35 +28,35 @@ module.exports = {
|
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Configurations for the plugin can be added under `elasticAPM` in the config.
|
|
34
|
-
This object accepts the same properties as the Elastic APM Node.js agent. (See
|
|
35
|
-
the [configuration options documentation])
|
|
31
|
+
Add a `--require` flag to a `package.json` start script:
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
elasticAPM: {
|
|
45
|
-
secretToken: '****',
|
|
46
|
-
serverUrl: 'http://localhost:9200'
|
|
33
|
+
```diff
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "gasket build",
|
|
36
|
+
- "start": "gasket start",
|
|
37
|
+
+ "start": "gasket start --require elastic-apm-node/start",
|
|
38
|
+
"local": "gasket local"
|
|
47
39
|
}
|
|
48
|
-
}
|
|
49
40
|
```
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
The [start recommendations] for the APM agent are to require it as early as
|
|
45
|
+
possible in your app. For Gasket apps, using `--require elastic-apm-node/start`
|
|
46
|
+
will accomplish this. To configure the APM agent, set the environment variables
|
|
47
|
+
described in the [configuration options documentation].
|
|
54
48
|
|
|
55
|
-
|
|
56
|
-
`
|
|
57
|
-
or `ELASTIC_APM_SECRET_TOKEN`) are both required configuration fields. If either
|
|
49
|
+
In particular, the APM server URL (`ELASTIC_APM_SERVER_URL`) and secret token
|
|
50
|
+
(`ELASTIC_APM_SECRET_TOKEN`) are both required configuration. If either
|
|
58
51
|
of these are not present, the APM agent will be disabled.
|
|
59
52
|
|
|
53
|
+
### Plugin Configurations
|
|
54
|
+
|
|
55
|
+
The Gasket plugin provides some additional setup helpers. These can be
|
|
56
|
+
configured under `elasticAPM` in the `gasket.config.js`.
|
|
57
|
+
|
|
58
|
+
- **`sensitiveCookies`** - (string[]) A list of sensitive cookies to filter
|
|
59
|
+
|
|
60
60
|
#### Filtering Sensitive Cookies
|
|
61
61
|
|
|
62
62
|
If your application’s users send session credentials or any other sensitive
|
|
@@ -72,9 +72,40 @@ module.exports = {
|
|
|
72
72
|
};
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
### Custom Start Configurations
|
|
76
|
+
|
|
77
|
+
For scenarios where you need to configure the start options for the APM agent,
|
|
78
|
+
you can do so in a custom setup script and require it instead.
|
|
79
|
+
|
|
80
|
+
For example, add a `setup.js` script to the root of your app:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
// setup.js
|
|
84
|
+
require('elastic-apm-node').start({
|
|
85
|
+
// any configuration options
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Then adjust your start script to require it instead:
|
|
90
|
+
|
|
91
|
+
```diff
|
|
92
|
+
- "start": "gasket start --require elastic-apm-node/start",
|
|
93
|
+
+ "start": "gasket start --require ./setup.js",
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Custom Filters
|
|
97
|
+
|
|
98
|
+
According to the [Elastic APM docs], the _Elastic APM agent for Node.js is a
|
|
99
|
+
singleton_. This means that you can require and configure singleton in various
|
|
100
|
+
hooks of your Gasket app, such as with the [init] or [middleware] lifecycles.
|
|
101
|
+
|
|
75
102
|
## How it works
|
|
76
103
|
|
|
77
|
-
This
|
|
104
|
+
This plugin hooks the Gasket [preboot] lifecycle from [@gasket/plugin-start]
|
|
105
|
+
and will set up additional filtering, such as for sensitive cookies. If the
|
|
106
|
+
`preboot` hook finds that the APM agent has not yet been started using the
|
|
107
|
+
recommended `--require elastic-apm-node/start`, it will start it here.
|
|
108
|
+
However, you risk not bootstrapping necessary modules with a late start.
|
|
78
109
|
|
|
79
110
|
## License
|
|
80
111
|
|
|
@@ -83,4 +114,8 @@ This plugins hooks the [preboot] lifecycle from [@gasket/plugin-start].
|
|
|
83
114
|
<!-- LINKS -->
|
|
84
115
|
|
|
85
116
|
[preboot]:/packages/gasket-plugin-start/README.md#preboot
|
|
117
|
+
[init]:packages/gasket-plugin-command/README.md#init
|
|
118
|
+
[middleware]:/packages/gasket-plugin-express/README.md#middleware
|
|
86
119
|
[configuration options documentation]:https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html
|
|
120
|
+
[start recommendations]:https://www.elastic.co/guide/en/apm/agent/nodejs/master/agent-api.html#apm-start
|
|
121
|
+
[Elastic APM docs]:https://www.elastic.co/guide/en/apm/agent/nodejs/master/agent-api.html
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
const { filterSensitiveCookies } = require('./cookies');
|
|
2
|
+
const { dependencies } = require('../package.json');
|
|
3
|
+
|
|
4
|
+
const isDefined = o => typeof o !== 'undefined';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Determines if the Elastic APM agent has sufficient config to be active
|
|
@@ -29,7 +32,17 @@ module.exports = {
|
|
|
29
32
|
hooks: {
|
|
30
33
|
configure: {
|
|
31
34
|
handler: async (gasket, config) => {
|
|
35
|
+
const { logger } = gasket;
|
|
32
36
|
config.elasticAPM = config.elasticAPM || {};
|
|
37
|
+
|
|
38
|
+
const { serverUrl, secretToken } = config.elasticAPM;
|
|
39
|
+
if (isDefined(serverUrl)) {
|
|
40
|
+
logger.notice('DEPRECATED config `elasticAPM.serverUrl`. Use env var: ELASTIC_APM_SERVER_URL');
|
|
41
|
+
}
|
|
42
|
+
if (isDefined(secretToken)) {
|
|
43
|
+
logger.notice('DEPRECATED config `elasticAPM.secretToken`. Use env var: ELASTIC_APM_SECRET_TOKEN');
|
|
44
|
+
}
|
|
45
|
+
|
|
33
46
|
// eslint-disable-next-line no-process-env
|
|
34
47
|
config.elasticAPM.active = isActive(config.elasticAPM, process.env);
|
|
35
48
|
|
|
@@ -37,12 +50,35 @@ module.exports = {
|
|
|
37
50
|
}
|
|
38
51
|
},
|
|
39
52
|
preboot: {
|
|
40
|
-
handler: async (
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
handler: async (gasket) => {
|
|
54
|
+
const { config, logger } = gasket;
|
|
55
|
+
|
|
56
|
+
// prefer app-level dependency in case of duplicates
|
|
57
|
+
const apm = require(
|
|
58
|
+
require.resolve('elastic-apm-node', { paths: [config.root, __dirname] })
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (!apm.isStarted()) {
|
|
62
|
+
apm.start({
|
|
43
63
|
...config.elasticAPM
|
|
44
|
-
})
|
|
45
|
-
.
|
|
64
|
+
});
|
|
65
|
+
logger.notice('DEPRECATED started Elastic APM agent late. Use `--require elastic-apm-node/start`');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
apm.addFilter(filterSensitiveCookies(config));
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
create: {
|
|
72
|
+
timing: {
|
|
73
|
+
after: ['@gasket/plugin-start']
|
|
74
|
+
},
|
|
75
|
+
handler(gasket, { pkg }) {
|
|
76
|
+
pkg.add('dependencies', {
|
|
77
|
+
'elastic-apm-node': dependencies['elastic-apm-node']
|
|
78
|
+
});
|
|
79
|
+
pkg.add('scripts', {
|
|
80
|
+
start: 'gasket start --require elastic-apm-node/start'
|
|
81
|
+
});
|
|
46
82
|
}
|
|
47
83
|
}
|
|
48
84
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-elastic-apm",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.25.0",
|
|
4
4
|
"description": "Adds Elastic APM instrumentation to your application",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"elastic-apm-node": "^3.26.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@gasket/engine": "^6.
|
|
46
|
+
"@gasket/engine": "^6.24.2",
|
|
47
47
|
"eslint": "^8.7.0",
|
|
48
48
|
"eslint-config-godaddy": "^6.0.0",
|
|
49
49
|
"eslint-plugin-jest": "^25.7.0",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"jest": {
|
|
69
69
|
"testEnvironment": "node"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "9a1bfff9d20b3b7fd32b27024c5e51dfb67104f7"
|
|
72
72
|
}
|