@contrast/agentify 1.44.0 → 1.46.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.
Files changed (2) hide show
  1. package/lib/index.js +24 -8
  2. package/package.json +14 -14
package/lib/index.js CHANGED
@@ -16,12 +16,14 @@
16
16
  'use strict';
17
17
 
18
18
  const Module = require('module');
19
-
19
+ const path = require('path');
20
+ const { IntentionalError, safeConsoleError } = require('@contrast/common');
21
+ const { Core } = require('@contrast/core/lib/ioc/core');
20
22
  const {
21
23
  assertValidOpts,
22
24
  preStartupValidation,
23
25
  } = require('./utils');
24
- const { IntentionalError, safeConsoleError } = require('@contrast/common');
26
+
25
27
 
26
28
  const ERROR_MESSAGE = 'An error prevented the Contrast agent from installing. The application will be run without instrumentation.';
27
29
  /**
@@ -63,6 +65,10 @@ const DEFAULT_INSTALL_ORDER = [
63
65
  * @returns {import('.').Agentify}
64
66
  */
65
67
  module.exports = function init(core = {}) {
68
+ if (!(core instanceof Core)) core = new Core(core);
69
+
70
+ core.agentPath = path.resolve(__dirname, '..', '..');
71
+
66
72
  // used for data that needs to be transferred to threads. originally added
67
73
  // for the file descriptor so the main and esm thread logger instances can
68
74
  // share the same FD. over time, other module-specific data that needs to
@@ -75,6 +81,7 @@ module.exports = function init(core = {}) {
75
81
  if (!core.threadTransferData) {
76
82
  core.threadTransferData = Object.create(null);
77
83
  }
84
+
78
85
  core.startTime = process.hrtime.bigint();
79
86
  if (!core.Perf) {
80
87
  core.Perf = require('@contrast/perf');
@@ -84,7 +91,6 @@ module.exports = function init(core = {}) {
84
91
 
85
92
  let _callback;
86
93
  let _opts;
87
- const _perfAgentify = new core.Perf('agentify');
88
94
 
89
95
  core.agentify = async function agentify(callback, opts = {}) {
90
96
  // options are hardcoded, so if this throws it's going to be in testing/dev situation
@@ -134,6 +140,8 @@ module.exports = function init(core = {}) {
134
140
 
135
141
  const plugin = await _callback?.(core);
136
142
 
143
+ core.messages.emit('ext:core.pre-install');
144
+
137
145
  for (const svcName of _opts.installOrder ?? []) {
138
146
  const svc = core[svcName];
139
147
  if (svc?.install) {
@@ -145,6 +153,8 @@ module.exports = function init(core = {}) {
145
153
  if (plugin?.install) {
146
154
  await plugin.install();
147
155
  }
156
+
157
+ core.messages.emit('ext:core.post-install');
148
158
  } catch (err) {
149
159
  // TODO: Consider proper UNINSTALLATION and normal startup w/o agent
150
160
  if (logger) {
@@ -160,7 +170,6 @@ module.exports = function init(core = {}) {
160
170
  preStartupValidation(core);
161
171
 
162
172
  const modules = [
163
- { name: 'messages', spec: '@contrast/core/lib/messages' },
164
173
  { name: 'config', spec: '@contrast/config' },
165
174
  { name: 'logger', spec: '@contrast/logger', default: true },
166
175
  // call all configValidation functions here
@@ -182,7 +191,6 @@ module.exports = function init(core = {}) {
182
191
  { name: 'reporter', spec: '@contrast/reporter', default: true },
183
192
  { name: 'instrumentation', spec: '@contrast/instrumentation' },
184
193
  { name: 'metrics', spec: '@contrast/metrics' },
185
-
186
194
  // compose additional local services
187
195
  { name: 'heap-snapshots', spec: './heap-snapshots' },
188
196
  { name: 'sources', spec: './sources' },
@@ -215,12 +223,20 @@ module.exports = function init(core = {}) {
215
223
  // now load each module and, if a validator is available, run it.
216
224
  for (const { name, spec, default: isDefault } of modules) {
217
225
  // typescript inserts a default export for esm modules.
218
- let mod = require(spec);
226
+ let component = require(spec);
219
227
  if (isDefault) {
220
- mod = mod.default;
228
+ component = component.default;
221
229
  }
222
230
 
223
- _perfAgentify.wrapInit(mod, spec)(core);
231
+ if (Core.isComponent(component)) {
232
+ core.initComponentSync(component);
233
+ } else {
234
+ core.initComponentFactory(component, spec);
235
+ }
236
+
237
+ if (spec === '@contrast/config' && !core.config.enable) {
238
+ throw new IntentionalError('Contrast is disabled in configuration and will not instrument this application');
239
+ }
224
240
 
225
241
  // perform any validations that can take place now that this module is loaded.
226
242
  if (name === 'logger') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agentify",
3
- "version": "1.44.0",
3
+ "version": "1.46.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)",
@@ -20,21 +20,21 @@
20
20
  "test": "../scripts/test.sh"
21
21
  },
22
22
  "dependencies": {
23
- "@contrast/common": "1.31.0",
24
- "@contrast/config": "1.42.0",
25
- "@contrast/core": "1.47.0",
26
- "@contrast/deadzones": "1.19.0",
27
- "@contrast/dep-hooks": "1.16.0",
28
- "@contrast/esm-hooks": "2.21.0",
23
+ "@contrast/common": "1.32.0",
24
+ "@contrast/config": "1.44.0",
25
+ "@contrast/core": "1.49.0",
26
+ "@contrast/deadzones": "1.21.0",
27
+ "@contrast/dep-hooks": "1.18.0",
28
+ "@contrast/esm-hooks": "2.23.0",
29
29
  "@contrast/find-package-json": "^1.1.0",
30
- "@contrast/instrumentation": "1.26.0",
31
- "@contrast/logger": "1.20.0",
32
- "@contrast/metrics": "1.24.0",
33
- "@contrast/patcher": "1.19.0",
30
+ "@contrast/instrumentation": "1.28.0",
31
+ "@contrast/logger": "1.22.0",
32
+ "@contrast/metrics": "1.26.0",
33
+ "@contrast/patcher": "1.21.0",
34
34
  "@contrast/perf": "1.3.1",
35
- "@contrast/reporter": "1.43.0",
36
- "@contrast/rewriter": "1.23.0",
37
- "@contrast/scopes": "1.17.0",
35
+ "@contrast/reporter": "1.45.0",
36
+ "@contrast/rewriter": "1.25.0",
37
+ "@contrast/scopes": "1.19.0",
38
38
  "on-finished": "^2.4.1",
39
39
  "semver": "^7.6.0"
40
40
  }