@instana/shared-metrics 5.0.0 → 5.0.1

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 (55) hide show
  1. package/CHANGELOG.md +410 -6
  2. package/addons/linux/arm64/glibc/108/event-loop-stats.tar.gz +0 -0
  3. package/addons/linux/arm64/glibc/108/gcstats.js.tar.gz +0 -0
  4. package/addons/linux/arm64/glibc/115/event-loop-stats.tar.gz +0 -0
  5. package/addons/linux/arm64/glibc/115/gcstats.js.tar.gz +0 -0
  6. package/addons/linux/arm64/glibc/127/event-loop-stats.tar.gz +0 -0
  7. package/addons/linux/arm64/glibc/127/gcstats.js.tar.gz +0 -0
  8. package/addons/linux/arm64/glibc/137/event-loop-stats.tar.gz +0 -0
  9. package/addons/linux/arm64/glibc/137/gcstats.js.tar.gz +0 -0
  10. package/addons/linux/arm64/musl/108/event-loop-stats.tar.gz +0 -0
  11. package/addons/linux/arm64/musl/108/gcstats.js.tar.gz +0 -0
  12. package/addons/linux/arm64/musl/115/event-loop-stats.tar.gz +0 -0
  13. package/addons/linux/arm64/musl/115/gcstats.js.tar.gz +0 -0
  14. package/addons/linux/arm64/musl/127/event-loop-stats.tar.gz +0 -0
  15. package/addons/linux/arm64/musl/127/gcstats.js.tar.gz +0 -0
  16. package/addons/linux/arm64/musl/137/event-loop-stats.tar.gz +0 -0
  17. package/addons/linux/arm64/musl/137/gcstats.js.tar.gz +0 -0
  18. package/addons/linux/s390x/glibc/108/event-loop-stats.tar.gz +0 -0
  19. package/addons/linux/s390x/glibc/108/gcstats.js.tar.gz +0 -0
  20. package/addons/linux/s390x/glibc/115/event-loop-stats.tar.gz +0 -0
  21. package/addons/linux/s390x/glibc/115/gcstats.js.tar.gz +0 -0
  22. package/addons/linux/s390x/glibc/127/event-loop-stats.tar.gz +0 -0
  23. package/addons/linux/s390x/glibc/127/gcstats.js.tar.gz +0 -0
  24. package/addons/linux/s390x/glibc/137/event-loop-stats.tar.gz +0 -0
  25. package/addons/linux/s390x/glibc/137/gcstats.js.tar.gz +0 -0
  26. package/addons/linux/x64/glibc/115/event-loop-stats.tar.gz +0 -0
  27. package/addons/linux/x64/glibc/115/gcstats.js.tar.gz +0 -0
  28. package/addons/linux/x64/glibc/137/event-loop-stats.tar.gz +0 -0
  29. package/addons/linux/x64/glibc/137/gcstats.js.tar.gz +0 -0
  30. package/addons/linux/x64/musl/137/event-loop-stats.tar.gz +0 -0
  31. package/addons/linux/x64/musl/137/gcstats.js.tar.gz +0 -0
  32. package/package.json +15 -14
  33. package/src/activeHandles.js +2 -1
  34. package/src/activeRequests.js +4 -0
  35. package/src/dependencies.js +40 -23
  36. package/src/description.js +10 -14
  37. package/src/directDependencies.js +9 -9
  38. package/src/gc.js +60 -46
  39. package/src/healthchecks.js +7 -6
  40. package/src/index.js +51 -22
  41. package/src/keywords.js +11 -13
  42. package/src/libuv.js +24 -20
  43. package/src/name.js +9 -15
  44. package/src/util/DependencyDistanceCalculator.js +17 -22
  45. package/src/util/index.js +12 -8
  46. package/src/util/nativeModuleRetry.js +36 -17
  47. package/src/version.js +11 -13
  48. package/addons/linux/x64/glibc/120/event-loop-stats.tar.gz +0 -0
  49. package/addons/linux/x64/glibc/120/gcstats.js.tar.gz +0 -0
  50. package/addons/linux/x64/glibc/131/event-loop-stats.tar.gz +0 -0
  51. package/addons/linux/x64/glibc/131/gcstats.js.tar.gz +0 -0
  52. package/addons/linux/x64/musl/120/event-loop-stats.tar.gz +0 -0
  53. package/addons/linux/x64/musl/120/gcstats.js.tar.gz +0 -0
  54. package/addons/linux/x64/musl/131/event-loop-stats.tar.gz +0 -0
  55. package/addons/linux/x64/musl/131/gcstats.js.tar.gz +0 -0
package/src/name.js CHANGED
@@ -7,13 +7,14 @@
7
7
 
8
8
  const { applicationUnderMonitoring } = require('@instana/core').util;
9
9
 
10
- let logger = require('@instana/core').logger.getLogger('metrics');
10
+ /** @type {import('@instana/core/src/core').GenericLogger} */
11
+ let logger;
11
12
 
12
13
  /**
13
- * @param {import('@instana/core/src/core').GenericLogger} _logger
14
+ * @param {import('@instana/core/src/config').InstanaConfig} config
14
15
  */
15
- exports.setLogger = function setLogger(_logger) {
16
- logger = _logger;
16
+ exports.init = function init(config) {
17
+ logger = config.logger;
17
18
  };
18
19
 
19
20
  exports.payloadPrefix = 'name';
@@ -24,22 +25,15 @@ exports.MAX_ATTEMPTS = 60;
24
25
  exports.DELAY = 1000;
25
26
  let attempts = 0;
26
27
 
27
- /**
28
- * @param {import('@instana/core/src/util/normalizeConfig').InstanaConfig} config
29
- */
30
- exports.activate = function activate(config) {
28
+ exports.activate = function activate() {
31
29
  attempts++;
32
30
 
33
- applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule(config, (err, packageJson) => {
31
+ applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule((err, packageJson) => {
34
32
  if (err) {
35
- return logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
33
+ return logger.warn(`Failed to determine main package json. Reason: ${err?.message} ${err?.stack}`);
36
34
  } else if (!packageJson && attempts < exports.MAX_ATTEMPTS) {
37
35
  logger.debug('Main package.json could not be found. Will try again later.');
38
-
39
- setTimeout(() => {
40
- exports.activate(config);
41
- }, exports.DELAY).unref();
42
-
36
+ setTimeout(exports.activate, exports.DELAY).unref();
43
37
  return;
44
38
  } else if (!packageJson) {
45
39
  if (require.main) {
@@ -6,18 +6,19 @@
6
6
  'use strict';
7
7
 
8
8
  const assert = require('assert');
9
- const { logger: Logger, uninstrumentedFs: fs } = require('@instana/core');
9
+ const { uninstrumentedFs: fs } = require('@instana/core');
10
10
  const path = require('path');
11
11
 
12
12
  const CountDownLatch = require('./CountDownLatch');
13
13
 
14
- let logger = Logger.getLogger('metrics');
14
+ /** @type {import('@instana/core/src/core').GenericLogger} */
15
+ let logger;
15
16
 
16
17
  /**
17
- * @param {import('@instana/core/src/core').GenericLogger} _logger
18
+ * @param {import('@instana/core/src/config').InstanaConfig} config
18
19
  */
19
- const setLogger = function (_logger) {
20
- logger = _logger;
20
+ const init = config => {
21
+ logger = config.logger;
21
22
  };
22
23
 
23
24
  class DependencyDistanceCalculator {
@@ -73,10 +74,8 @@ class DependencyDistanceCalculator {
73
74
  fs.readFile(packageJsonPath, { encoding: 'utf8' }, (err, contents) => {
74
75
  if (err) {
75
76
  logger.debug(
76
- 'Failed to calculate transitive distances for some dependencies, could not read package.json file at ' +
77
- '%s: %s.',
78
- packageJsonPath,
79
- err.message
77
+ `Failed to calculate transitive distances for some dependencies, could not read package.json file at
78
+ ${packageJsonPath}: ${err?.message}.`
80
79
  );
81
80
 
82
81
  // If we cannot parse the package.json or if it does not exist, we need to decrement by 3 immediately because
@@ -90,10 +89,8 @@ class DependencyDistanceCalculator {
90
89
  parsedPackageJson = JSON.parse(contents);
91
90
  } catch (parseErr) {
92
91
  logger.debug(
93
- 'Failed to calculate transitive distances for some dependencies, could not parse package.json file at ' +
94
- '%s: %s',
95
- packageJsonPath,
96
- parseErr.message
92
+ `Failed to calculate transitive distances for some dependencies, could not parse package.json file at
93
+ ${packageJsonPath}: ${parseErr?.message}.`
97
94
  );
98
95
  this.globalCountDownLatchAllPackages.countDown(3);
99
96
  return;
@@ -109,9 +106,8 @@ class DependencyDistanceCalculator {
109
106
  // This catch-block is for synchronous errors from fs.readFile, which can also happen in addition to the callback
110
107
  // being called with an error.
111
108
  logger.debug(
112
- 'Failed to calculate transitive distances for some dependencies, synchronous error from fs.readFile for %s:',
113
- packageJsonPath,
114
- fsReadFileErr
109
+ `Failed to calculate transitive distances for some dependencies, synchronous error from fs.readFile for
110
+ ${packageJsonPath}: ${fsReadFileErr?.message}`
115
111
  );
116
112
  this.globalCountDownLatchAllPackages.countDown(3);
117
113
  }
@@ -179,7 +175,7 @@ class DependencyDistanceCalculator {
179
175
  mainModulePath = require.resolve(dependency);
180
176
  } catch (requireResolveErr) {
181
177
  // ignore
182
- logger.debug(
178
+ logger.trace(
183
179
  `Ignoring failure to resolve the path to dependency ${dependency} for dependency distance calculation.`
184
180
  );
185
181
  }
@@ -188,7 +184,7 @@ class DependencyDistanceCalculator {
188
184
  // Could not find the package.json for this dependency so we cannot analyze it further, which means we are done
189
185
  // with it.
190
186
  localCountDownLatchForThisNode.countDown();
191
- logger.debug(`No main module path for dependency ${dependency}.`);
187
+ logger.trace(`Ignoring ${dependency} for dependency distance calculation, could not find main module path.`);
192
188
  return;
193
189
  }
194
190
 
@@ -197,8 +193,7 @@ class DependencyDistanceCalculator {
197
193
  localCountDownLatchForThisNode.countDown();
198
194
  logger.debug(
199
195
  `Ignoring failure to find the package.json file for dependency ${dependency} for dependency distance ` +
200
- 'calculation.',
201
- err
196
+ `calculation. ${err?.message} ${err?.stack}`
202
197
  );
203
198
  return;
204
199
  }
@@ -275,8 +270,8 @@ function searchInParentDir(dir, onParentDir, callback) {
275
270
  }
276
271
 
277
272
  module.exports = {
273
+ init,
278
274
  DependencyDistanceCalculator,
279
275
  MAX_DEPTH: 15,
280
- __moduleRefExportedForTest: module,
281
- setLogger
276
+ __moduleRefExportedForTest: module
282
277
  };
package/src/util/index.js CHANGED
@@ -6,14 +6,18 @@
6
6
  'use strict';
7
7
 
8
8
  const nativeModuleRetry = require('./nativeModuleRetry');
9
- const { setLogger: setLoggerForDependencyDistanceCalculator } = require('./DependencyDistanceCalculator');
9
+ const dependencyDistanceCalculator = require('./DependencyDistanceCalculator');
10
+
11
+ /**
12
+ * @param {import('@instana/core/src/config').InstanaConfig} config
13
+ */
14
+ const init = config => {
15
+ nativeModuleRetry.init(config);
16
+ dependencyDistanceCalculator.init(config);
17
+ };
18
+
10
19
  module.exports = {
20
+ init,
11
21
  nativeModuleRetry,
12
- /**
13
- * @param {import('@instana/core/src/core').GenericLogger} logger
14
- */
15
- setLogger: function setLogger(logger) {
16
- nativeModuleRetry.setLogger(logger);
17
- setLoggerForDependencyDistanceCalculator(logger);
18
- }
22
+ dependencyDistanceCalculator
19
23
  };
@@ -5,15 +5,23 @@
5
5
 
6
6
  'use strict';
7
7
 
8
- const { logger: Logger, uninstrumentedFs: fs } = require('@instana/core');
9
- let logger = Logger.getLogger('shared-metrics/native-module-retry');
10
-
8
+ const { uninstrumentedFs: fs } = require('@instana/core');
11
9
  const EventEmitter = require('events');
12
10
  const os = require('os');
13
11
  const tar = require('tar');
14
12
  const path = require('path');
15
13
  const detectLibc = require('detect-libc');
16
14
 
15
+ /** @type {import('@instana/core/src/core').GenericLogger} */
16
+ let logger;
17
+
18
+ /**
19
+ * @param {import('@instana/core/src/config').InstanaConfig} config
20
+ */
21
+ exports.init = function init(config) {
22
+ logger = config.logger;
23
+ };
24
+
17
25
  /**
18
26
  * @typedef {Object} InstanaSharedMetricsOptions
19
27
  * @property {string} [nativeModuleName]
@@ -115,7 +123,9 @@ function attemptRequire(opts, loaderEmitter, mechanism) {
115
123
  logger.debug(`Attempt to load native add-on ${opts.nativeModuleName} ${mechanism} has been successful.`);
116
124
  return true;
117
125
  } catch (e) {
118
- logger.debug(`Attempt to load native add-on ${opts.nativeModuleName} ${mechanism} has failed.`, e);
126
+ logger.debug(
127
+ `Attempt to load native add-on ${opts.nativeModuleName} ${mechanism} has failed. ${e?.message} ${e?.stack}`
128
+ );
119
129
  return false;
120
130
  }
121
131
  }
@@ -167,7 +177,10 @@ function copyPrecompiled(opts, loaderEmitter, callback) {
167
177
  callback(false);
168
178
  return;
169
179
  } else if (statsErr) {
170
- logger.warn(`Looking for a precompiled version for ${opts.nativeModuleName} ${label} failed.`, statsErr);
180
+ logger.warn(
181
+ `Looking for a precompiled version for ${opts.nativeModuleName} ${label} failed.
182
+ ${statsErr?.message} ${statsErr?.stack}`
183
+ );
171
184
  callback(false);
172
185
  return;
173
186
  }
@@ -206,12 +219,24 @@ function copyPrecompiled(opts, loaderEmitter, callback) {
206
219
  callback(true);
207
220
  })
208
221
  .catch(error => {
209
- logger.warn(`Copying the precompiled build for ${opts.nativeModuleName} ${label} failed.`, error);
222
+ // The log triggered when the Instana Node.js collector fails to load a precompiled native module.
223
+ // The collector first attempts to load the module directly; if that fails, it extracts a precompiled
224
+ // version from the instrumentation image, which is currently compiled only for Node.js v21.
225
+ // If the application runs a different Node.js version and the filesystem is read-only, extraction may fail,
226
+ // preventing collection of certain telemetry data (garbage collection and event loop stats).
227
+ // TODO: Fix the issue tracked under INSTA-6673. Ensure prebuilt binaries are available for the
228
+ // corresponding Node.js version.
229
+ logger.debug(
230
+ `Failed to load precompiled build for ${opts.nativeModuleName} ${label}. ` +
231
+ 'Precompiled binary extraction has failed, possibly due to a read-only filesystem or an unknown' +
232
+ `system operation error for the Node.js ${process.version}. ${error?.message} ${error?.stack}`
233
+ );
210
234
  callback(false);
211
235
  });
212
236
  })
213
237
  .catch(tarErr => {
214
- logger.warn(`Unpacking the precompiled build for ${opts.nativeModuleName} ${label} failed.`, tarErr);
238
+ logger.warn(`Unpacking the precompiled build for ${opts.nativeModuleName} ${label} failed.
239
+ ${tarErr?.message} ${tarErr?.stack}`);
215
240
  callback(false);
216
241
  });
217
242
  });
@@ -245,7 +270,9 @@ function findNativeModulePath(opts) {
245
270
  opts.nativeModuleParentPath = path.join(opts.nativeModulePath, '..');
246
271
  return true;
247
272
  } catch (e) {
248
- logger.debug(`Could not find location for ${opts.nativeModuleName}. Will create a path for it.`, e);
273
+ logger.debug(
274
+ `Could not find location for ${opts.nativeModuleName}. Will create a path for it. ${e?.message} ${e?.stack}`
275
+ );
249
276
  return createNativeModulePath(opts);
250
277
  }
251
278
  }
@@ -278,14 +305,6 @@ function createNativeModulePath(opts) {
278
305
  return true;
279
306
  }
280
307
 
281
- loadNativeAddOn.setLogger = setLogger;
282
308
  loadNativeAddOn.selfNodeModulesPath = '';
283
309
 
284
- /**
285
- * @param {import('@instana/core/src/core').GenericLogger} _logger
286
- */
287
- function setLogger(_logger) {
288
- logger = _logger;
289
- }
290
-
291
- module.exports = loadNativeAddOn;
310
+ exports.loadNativeAddOn = loadNativeAddOn;
package/src/version.js CHANGED
@@ -7,12 +7,14 @@
7
7
 
8
8
  const { applicationUnderMonitoring } = require('@instana/core').util;
9
9
 
10
- let logger = require('@instana/core').logger.getLogger('metrics');
10
+ /** @type {import('@instana/core/src/core').GenericLogger} */
11
+ let logger;
12
+
11
13
  /**
12
- * @param {import('@instana/core/src/core').GenericLogger} _logger
14
+ * @param {import('@instana/core/src/config').InstanaConfig} config
13
15
  */
14
- exports.setLogger = function setLogger(_logger) {
15
- logger = _logger;
16
+ exports.init = function init(config) {
17
+ logger = config.logger;
16
18
  };
17
19
 
18
20
  exports.payloadPrefix = 'version';
@@ -23,18 +25,14 @@ const MAX_ATTEMPTS = 20;
23
25
  const DELAY = 1000;
24
26
  let attempts = 0;
25
27
 
26
- /**
27
- * @param {import('@instana/core/src/util/normalizeConfig').InstanaConfig} config
28
- */
29
- exports.activate = function activate(config) {
28
+ exports.activate = function activate() {
30
29
  attempts++;
31
- applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule(config, (err, packageJson) => {
30
+
31
+ applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule((err, packageJson) => {
32
32
  if (err) {
33
- return logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
33
+ return logger.warn(`Failed to determine main package json. Reason: ${err?.message} ${err?.stack}`);
34
34
  } else if (!packageJson && attempts < MAX_ATTEMPTS) {
35
- setTimeout(() => {
36
- exports.activate(config);
37
- }, DELAY).unref();
35
+ setTimeout(exports.activate, DELAY).unref();
38
36
 
39
37
  return;
40
38
  } else if (!packageJson) {