@instana/shared-metrics 1.116.0 → 1.117.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instana/shared-metrics",
3
- "version": "1.116.0",
3
+ "version": "1.117.3",
4
4
  "description": "Internal metrics plug-in package for Node.js monitoring with Instana",
5
5
  "author": {
6
6
  "name": "Bastian Krol",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "license": "MIT",
57
57
  "dependencies": {
58
- "@instana/core": "1.116.0",
58
+ "@instana/core": "1.117.3",
59
59
  "detect-libc": "^1.0.3",
60
60
  "event-loop-lag": "^1.4.0",
61
61
  "recursive-copy": "^2.0.11",
@@ -74,5 +74,5 @@
74
74
  "gcstats.js": "1.0.0",
75
75
  "node-gyp": "^7.1.0"
76
76
  },
77
- "gitHead": "d47a972ab41d4066e854a728dc97b545fdd12ac7"
77
+ "gitHead": "fe7898c0944605c3b428f143b36cb05d65c888a7"
78
78
  }
package/src/gc.js CHANGED
@@ -16,6 +16,10 @@ const incrementalMarkingsWindow = slidingWindow.create(windowOpts);
16
16
  const processWeakCallbacksWindow = slidingWindow.create(windowOpts);
17
17
  const gcPauseWindow = slidingWindow.create(windowOpts);
18
18
 
19
+ let gcStats;
20
+ let activateHasBeenCalled = false;
21
+ let hasBeenActivated = false;
22
+
19
23
  exports.payloadPrefix = 'gc';
20
24
  exports.currentPayload = {
21
25
  minorGcs: 0,
@@ -25,6 +29,13 @@ exports.currentPayload = {
25
29
  gcPause: 0
26
30
  };
27
31
 
32
+ exports.activate = function activate() {
33
+ activateHasBeenCalled = true;
34
+ if (gcStats) {
35
+ actuallyActivate();
36
+ }
37
+ };
38
+
28
39
  const nativeModuleLoader = require('./util/nativeModuleRetry')({
29
40
  nativeModuleName: 'gcstats.js',
30
41
  moduleRoot: path.join(__dirname, '..'),
@@ -37,37 +48,46 @@ const nativeModuleLoader = require('./util/nativeModuleRetry')({
37
48
 
38
49
  let senseIntervalHandle;
39
50
 
40
- exports.activate = function activate() {
41
- nativeModuleLoader.on('loaded', gcStats => {
42
- exports.currentPayload.statsSupported = true;
43
- gcStats.on('stats', stats => {
44
- // gcstats exposes start and end in nanoseconds
45
- const pause = (stats.end - stats.start) / 1000000;
46
- gcPauseWindow.addPoint(pause);
47
- const type = stats.gctype;
48
- if (type === 1) {
49
- minorGcWindow.addPoint(1);
50
- } else if (type === 2) {
51
- majorGcWindow.addPoint(1);
52
- } else if (type === 4) {
53
- incrementalMarkingsWindow.addPoint(1);
54
- } else if (type === 8) {
55
- processWeakCallbacksWindow.addPoint(1);
56
- } else if (type === 15) {
57
- minorGcWindow.addPoint(1);
58
- majorGcWindow.addPoint(1);
59
- incrementalMarkingsWindow.addPoint(1);
60
- processWeakCallbacksWindow.addPoint(1);
61
- }
62
- exports.currentPayload.usedHeapSizeAfterGc = stats.after.usedHeapSize;
63
- });
64
- startSensing();
65
- });
51
+ nativeModuleLoader.once('loaded', gcStats_ => {
52
+ gcStats = gcStats_;
53
+ exports.currentPayload.statsSupported = true;
54
+ if (activateHasBeenCalled) {
55
+ actuallyActivate();
56
+ }
57
+ });
58
+
59
+ nativeModuleLoader.once('failed', () => {
60
+ exports.currentPayload.statsSupported = false;
61
+ });
66
62
 
67
- nativeModuleLoader.on('failed', () => {
68
- exports.currentPayload.statsSupported = false;
63
+ function actuallyActivate() {
64
+ if (hasBeenActivated) {
65
+ return;
66
+ }
67
+ hasBeenActivated = true;
68
+ gcStats.on('stats', stats => {
69
+ // gcstats exposes start and end in nanoseconds
70
+ const pause = (stats.end - stats.start) / 1000000;
71
+ gcPauseWindow.addPoint(pause);
72
+ const type = stats.gctype;
73
+ if (type === 1) {
74
+ minorGcWindow.addPoint(1);
75
+ } else if (type === 2) {
76
+ majorGcWindow.addPoint(1);
77
+ } else if (type === 4) {
78
+ incrementalMarkingsWindow.addPoint(1);
79
+ } else if (type === 8) {
80
+ processWeakCallbacksWindow.addPoint(1);
81
+ } else if (type === 15) {
82
+ minorGcWindow.addPoint(1);
83
+ majorGcWindow.addPoint(1);
84
+ incrementalMarkingsWindow.addPoint(1);
85
+ processWeakCallbacksWindow.addPoint(1);
86
+ }
87
+ exports.currentPayload.usedHeapSizeAfterGc = stats.after.usedHeapSize;
69
88
  });
70
- };
89
+ startSensing();
90
+ }
71
91
 
72
92
  function startSensing() {
73
93
  senseIntervalHandle = setInterval(() => {
@@ -84,4 +104,6 @@ exports.deactivate = function deactivate() {
84
104
  if (senseIntervalHandle) {
85
105
  clearInterval(senseIntervalHandle);
86
106
  }
107
+ activateHasBeenCalled = false;
108
+ hasBeenActivated = false;
87
109
  };
package/src/libuv.js CHANGED
@@ -25,11 +25,11 @@ const nativeModuleLoader = require('./util/nativeModuleRetry')({
25
25
  'https://www.instana.com/docs/ecosystem/node-js/installation/#native-addons'
26
26
  });
27
27
 
28
- nativeModuleLoader.on('loaded', eventLoopStats_ => {
28
+ nativeModuleLoader.once('loaded', eventLoopStats_ => {
29
29
  eventLoopStats = eventLoopStats_;
30
30
  });
31
31
 
32
- nativeModuleLoader.on('failed', () => {
32
+ nativeModuleLoader.once('failed', () => {
33
33
  exports.currentPayload.statsSupported = false;
34
34
  });
35
35
 
@@ -50,6 +50,17 @@ function loadNativeAddOn(opts) {
50
50
  }
51
51
 
52
52
  function loadNativeAddOnInternal(opts, loaderEmitter, retryIndex, skipAttempt) {
53
+ try {
54
+ const { isMainThread } = require('worker_threads');
55
+ if (!isMainThread) {
56
+ logger.warn(opts.message + ' (Native addons are currently not loaded in worker threads)');
57
+ loaderEmitter.emit('failed');
58
+ return;
59
+ }
60
+ } catch (err) {
61
+ // worker threads are not available, so we know that this is the main thread
62
+ }
63
+
53
64
  if (skipAttempt) {
54
65
  // The logic of the previous retry mechanism figured out that it cannot complete successfully, so there is no reason
55
66
  // to try to require the module again. Skip directly to the next retry.