@contrast/agentify 1.19.2 → 1.20.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.js +18 -7
- package/lib/initialize.mjs +12 -3
- package/package.json +9 -9
package/lib/index.js
CHANGED
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const Module = require('module');
|
|
19
|
+
const { IntentionalError } = require('@contrast/common');
|
|
19
20
|
|
|
20
|
-
const ERROR_MESSAGE = '
|
|
21
|
+
const ERROR_MESSAGE = 'An error prevented the Contrast agent from installing. The application will be run without instrumentation.';
|
|
21
22
|
const DEFAULT_INSTALL_ORDER = [
|
|
22
23
|
'reporter',
|
|
23
24
|
'contrastMethods',
|
|
@@ -44,12 +45,18 @@ module.exports = function init(core = {}) {
|
|
|
44
45
|
try {
|
|
45
46
|
require('@contrast/core/lib/messages')(core);
|
|
46
47
|
require('@contrast/config')(core);
|
|
48
|
+
if (core.config._errors?.length) {
|
|
49
|
+
throw core.config._errors[0];
|
|
50
|
+
}
|
|
47
51
|
require('@contrast/logger').default(core);
|
|
48
52
|
|
|
49
53
|
// @contrast/info ?
|
|
50
54
|
require('@contrast/core/lib/agent-info')(core);
|
|
51
55
|
require('@contrast/core/lib/system-info')(core);
|
|
52
56
|
require('@contrast/core/lib/app-info')(core);
|
|
57
|
+
if (core.appInfo._errors?.length) {
|
|
58
|
+
throw core.appInfo._errors[0];
|
|
59
|
+
}
|
|
53
60
|
require('@contrast/core/lib/sensitive-data-masking')(core);
|
|
54
61
|
require('@contrast/core/lib/is-agent-path')(core);
|
|
55
62
|
require('@contrast/dep-hooks')(core);
|
|
@@ -98,6 +105,7 @@ module.exports = function init(core = {}) {
|
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
logger.info('Starting %s v%s', core.agentName, core.agentVersion);
|
|
108
|
+
// pino serializers know how to log redacted values and omit certain props
|
|
101
109
|
logger.info({ config }, 'Agent configuration');
|
|
102
110
|
|
|
103
111
|
const plugin = await preRunMain(core);
|
|
@@ -127,15 +135,18 @@ module.exports = function init(core = {}) {
|
|
|
127
135
|
};
|
|
128
136
|
} catch (err) {
|
|
129
137
|
// TODO: Consider proper UNINSTALLATION and normal startup w/o agent
|
|
130
|
-
if (core.logger) {
|
|
131
|
-
core.logger.error({ err }, ERROR_MESSAGE);
|
|
132
|
-
} else {
|
|
133
|
-
console.error(new Error(ERROR_MESSAGE, { cause: err }));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
138
|
core.agentify = function agentify() {
|
|
137
139
|
return core;
|
|
138
140
|
};
|
|
141
|
+
|
|
142
|
+
// ignore intentional errors
|
|
143
|
+
if (!(err instanceof IntentionalError)) {
|
|
144
|
+
if (core.logger) {
|
|
145
|
+
core.logger.error({ err }, ERROR_MESSAGE);
|
|
146
|
+
} else {
|
|
147
|
+
console.error(new Error(ERROR_MESSAGE, { cause: err }));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
139
150
|
}
|
|
140
151
|
|
|
141
152
|
return core.agentify;
|
package/lib/initialize.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import Module from 'node:module';
|
|
|
24
24
|
//
|
|
25
25
|
import { isMainThread, threadId } from 'node:worker_threads';
|
|
26
26
|
|
|
27
|
-
const ERROR_MESSAGE = '
|
|
27
|
+
const ERROR_MESSAGE = 'An error prevented the Contrast agent from installing. The application will be run without instrumentation.';
|
|
28
28
|
const DEFAULT_INSTALL_ORDER = [
|
|
29
29
|
'reporter',
|
|
30
30
|
'contrastMethods',
|
|
@@ -45,6 +45,7 @@ const DEFAULT_INSTALL_ORDER = [
|
|
|
45
45
|
];
|
|
46
46
|
|
|
47
47
|
const require = Module.createRequire(import.meta.url);
|
|
48
|
+
let startupError;
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* @param {object} { core = {}, options = {} }
|
|
@@ -53,7 +54,11 @@ async function loadModules({ core = {}, options = {} }) {
|
|
|
53
54
|
try {
|
|
54
55
|
require('@contrast/core/lib/messages')(core);
|
|
55
56
|
require('@contrast/config')(core);
|
|
57
|
+
if (core.config._errors?.length) {
|
|
58
|
+
throw core.config._errors[0];
|
|
59
|
+
}
|
|
56
60
|
require('@contrast/logger').default(core);
|
|
61
|
+
|
|
57
62
|
const thread = isMainThread ? 'main' : 'loader';
|
|
58
63
|
core.logger.trace({ tid: threadId }, 'initializing core modules in %s thread', thread);
|
|
59
64
|
|
|
@@ -62,6 +67,9 @@ async function loadModules({ core = {}, options = {} }) {
|
|
|
62
67
|
require('@contrast/core/lib/agent-info')(core);
|
|
63
68
|
require('@contrast/core/lib/system-info')(core);
|
|
64
69
|
require('@contrast/core/lib/app-info')(core);
|
|
70
|
+
if (core.appInfo._errors?.length) {
|
|
71
|
+
throw core.appInfo._errors[0];
|
|
72
|
+
}
|
|
65
73
|
require('@contrast/core/lib/sensitive-data-masking')(core);
|
|
66
74
|
require('@contrast/core/lib/is-agent-path')(core);
|
|
67
75
|
require('@contrast/dep-hooks')(core);
|
|
@@ -101,13 +109,14 @@ async function loadModules({ core = {}, options = {} }) {
|
|
|
101
109
|
} else {
|
|
102
110
|
console.error(new Error(ERROR_MESSAGE, { cause: err }));
|
|
103
111
|
}
|
|
104
|
-
|
|
112
|
+
startupError = err;
|
|
105
113
|
}
|
|
106
|
-
|
|
107
114
|
return core;
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
async function startAgent({ core, options = {} }) {
|
|
118
|
+
if (startupError) return;
|
|
119
|
+
|
|
111
120
|
const { executor, installOrder = DEFAULT_INSTALL_ORDER } = options;
|
|
112
121
|
const { config, logger } = core;
|
|
113
122
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/agentify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Configures Contrast agent services and instrumentation within an application",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"test": "../scripts/test.sh"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@contrast/common": "1.
|
|
21
|
-
"@contrast/config": "1.
|
|
22
|
-
"@contrast/core": "1.
|
|
20
|
+
"@contrast/common": "1.18.0",
|
|
21
|
+
"@contrast/config": "1.25.0",
|
|
22
|
+
"@contrast/core": "1.29.0",
|
|
23
23
|
"@contrast/deadzones": "1.1.2",
|
|
24
24
|
"@contrast/dep-hooks": "1.3.1",
|
|
25
|
-
"@contrast/esm-hooks": "2.
|
|
26
|
-
"@contrast/instrumentation": "1.
|
|
27
|
-
"@contrast/logger": "1.7.
|
|
28
|
-
"@contrast/metrics": "1.
|
|
25
|
+
"@contrast/esm-hooks": "2.2.0",
|
|
26
|
+
"@contrast/instrumentation": "1.5.0",
|
|
27
|
+
"@contrast/logger": "1.7.2",
|
|
28
|
+
"@contrast/metrics": "1.4.0",
|
|
29
29
|
"@contrast/patcher": "1.7.1",
|
|
30
|
-
"@contrast/reporter": "1.
|
|
30
|
+
"@contrast/reporter": "1.24.0",
|
|
31
31
|
"@contrast/rewriter": "1.4.2",
|
|
32
32
|
"@contrast/scopes": "1.4.0"
|
|
33
33
|
}
|