@contrast/agent 5.39.0 → 5.40.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/start-agent.js +50 -40
- package/package.json +10 -10
package/lib/start-agent.js
CHANGED
|
@@ -19,7 +19,6 @@ const process = require('process');
|
|
|
19
19
|
const { isMainThread, threadId } = require('worker_threads');
|
|
20
20
|
const { safeConsoleError, safeConsoleWarn } = require('@contrast/common');
|
|
21
21
|
const { Core } = require('@contrast/core/lib/ioc/core');
|
|
22
|
-
const _agentify = require('@contrast/agentify');
|
|
23
22
|
|
|
24
23
|
const {
|
|
25
24
|
name: agentName,
|
|
@@ -30,6 +29,8 @@ const {
|
|
|
30
29
|
}
|
|
31
30
|
} = require('../package.json');
|
|
32
31
|
|
|
32
|
+
const kContrastInitialized = Symbol(`${agentName}:initialized`);
|
|
33
|
+
|
|
33
34
|
function initCore() {
|
|
34
35
|
const core = new Core({
|
|
35
36
|
agentName,
|
|
@@ -70,46 +71,55 @@ function loadFeatures(core) {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function startAgent({ type = 'cjs' } = {}) {
|
|
73
|
-
if (isMainThread) {
|
|
74
|
-
try {
|
|
75
|
-
const core = initCore();
|
|
76
|
-
const agentify = _agentify(core);
|
|
77
|
-
|
|
78
|
-
return agentify(loadFeatures, {
|
|
79
|
-
installOrder: [
|
|
80
|
-
'reporter',
|
|
81
|
-
'startupValidation',
|
|
82
|
-
'telemetry',
|
|
83
|
-
'contrastMethods',
|
|
84
|
-
'deadzones',
|
|
85
|
-
'scopes',
|
|
86
|
-
'secObs',
|
|
87
|
-
'sources',
|
|
88
|
-
'architectureComponents',
|
|
89
|
-
'routeCoverage',
|
|
90
|
-
'assess',
|
|
91
|
-
'protect',
|
|
92
|
-
'depHooks',
|
|
93
|
-
'libraryAnalysis',
|
|
94
|
-
'heapSnapshots',
|
|
95
|
-
'metrics',
|
|
96
|
-
'rewriteHooks',
|
|
97
|
-
'functionHooks',
|
|
98
|
-
'esmHooks',
|
|
99
|
-
'diagnostics',
|
|
100
|
-
],
|
|
101
|
-
type
|
|
102
|
-
});
|
|
103
|
-
} catch (cause) {
|
|
104
|
-
// agentify should catch any startup errors and handle necessary logging,
|
|
105
|
-
// but this is just in case a fatal error occurs during composition.
|
|
106
|
-
safeConsoleError(new Error(
|
|
107
|
-
'Startup error was not handled by agentify. Application Will be run without instrumentation.',
|
|
108
|
-
{ cause }
|
|
109
|
-
));
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
74
|
+
if (!isMainThread) {
|
|
112
75
|
safeConsoleWarn('Not in main thread. Thread (tid: %d) continuing without instrumentation.', threadId);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (global[kContrastInitialized]) {
|
|
80
|
+
safeConsoleWarn('%s has already been initialized. Continuing without reinstrumentation.', agentName);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
global[kContrastInitialized] = true;
|
|
86
|
+
|
|
87
|
+
const core = initCore();
|
|
88
|
+
const agentify = require('@contrast/agentify')(core);
|
|
89
|
+
|
|
90
|
+
return agentify(loadFeatures, {
|
|
91
|
+
installOrder: [
|
|
92
|
+
'reporter',
|
|
93
|
+
'startupValidation',
|
|
94
|
+
'telemetry',
|
|
95
|
+
'contrastMethods',
|
|
96
|
+
'deadzones',
|
|
97
|
+
'scopes',
|
|
98
|
+
'secObs',
|
|
99
|
+
'sources',
|
|
100
|
+
'architectureComponents',
|
|
101
|
+
'routeCoverage',
|
|
102
|
+
'assess',
|
|
103
|
+
'protect',
|
|
104
|
+
'depHooks',
|
|
105
|
+
'libraryAnalysis',
|
|
106
|
+
'heapSnapshots',
|
|
107
|
+
'metrics',
|
|
108
|
+
'rewriteHooks',
|
|
109
|
+
'functionHooks',
|
|
110
|
+
'esmHooks',
|
|
111
|
+
'diagnostics',
|
|
112
|
+
],
|
|
113
|
+
type
|
|
114
|
+
});
|
|
115
|
+
} catch (cause) {
|
|
116
|
+
delete global[kContrastInitialized];
|
|
117
|
+
// agentify should catch any startup errors and handle necessary logging,
|
|
118
|
+
// but this is just in case a fatal error occurs during composition.
|
|
119
|
+
safeConsoleError(new Error(
|
|
120
|
+
'Startup error was not handled by agentify. Application Will be run without instrumentation.',
|
|
121
|
+
{ cause }
|
|
122
|
+
));
|
|
113
123
|
}
|
|
114
124
|
}
|
|
115
125
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/agent",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.40.0",
|
|
4
4
|
"description": "Assess and Protect agents for Node.js",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"test": "bash ../scripts/test.sh"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@contrast/agentify": "1.52.
|
|
31
|
-
"@contrast/architecture-components": "1.42.
|
|
32
|
-
"@contrast/assess": "1.58.
|
|
33
|
-
"@contrast/common": "1.34.
|
|
34
|
-
"@contrast/core": "1.54.
|
|
35
|
-
"@contrast/library-analysis": "1.44.
|
|
36
|
-
"@contrast/protect": "1.64.
|
|
37
|
-
"@contrast/route-coverage": "1.45.
|
|
30
|
+
"@contrast/agentify": "1.52.2",
|
|
31
|
+
"@contrast/architecture-components": "1.42.2",
|
|
32
|
+
"@contrast/assess": "1.58.2",
|
|
33
|
+
"@contrast/common": "1.34.2",
|
|
34
|
+
"@contrast/core": "1.54.2",
|
|
35
|
+
"@contrast/library-analysis": "1.44.2",
|
|
36
|
+
"@contrast/protect": "1.64.2",
|
|
37
|
+
"@contrast/route-coverage": "1.45.2",
|
|
38
38
|
"@contrast/sec-obs": "1.0.0-alpha.8",
|
|
39
|
-
"@contrast/telemetry": "1.29.
|
|
39
|
+
"@contrast/telemetry": "1.29.2"
|
|
40
40
|
}
|
|
41
41
|
}
|