@instana/shared-metrics 1.131.1 → 1.133.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instana/shared-metrics",
3
- "version": "1.131.1",
3
+ "version": "1.133.0",
4
4
  "description": "Internal metrics plug-in package for Node.js monitoring with Instana",
5
5
  "author": {
6
6
  "name": "Bastian Krol",
@@ -59,11 +59,11 @@
59
59
  },
60
60
  "license": "MIT",
61
61
  "dependencies": {
62
- "@instana/core": "1.131.1",
62
+ "@instana/core": "1.133.0",
63
63
  "detect-libc": "^1.0.3",
64
64
  "event-loop-lag": "^1.4.0",
65
65
  "recursive-copy": "^2.0.13",
66
- "tar": "^5.0.9"
66
+ "tar": "^5.0.11"
67
67
  },
68
68
  "devDependencies": {
69
69
  "eslint": "^7.30.0",
@@ -78,5 +78,5 @@
78
78
  "gcstats.js": "1.0.0",
79
79
  "node-gyp": "^7.1.2"
80
80
  },
81
- "gitHead": "d08894ed069a3c0f6f22e36f21ab522459fae3b8"
81
+ "gitHead": "ac10cf0745557cdb803544c71cbbccc1ce60e5fa"
82
82
  }
@@ -57,6 +57,9 @@ class DependencyDistanceCalculator {
57
57
  // Do not descend deeper than maxDepth nesting levels.
58
58
  return;
59
59
  }
60
+ if (typeof packageJsonPath !== 'string') {
61
+ return;
62
+ }
60
63
 
61
64
  // For each package.json that we find in the dependency tree, we initially increase the global count down latch
62
65
  // by 3, that is, one for each type of dependencies (normal, optional, peer). Once we have in turn queued all
@@ -66,39 +69,52 @@ class DependencyDistanceCalculator {
66
69
  this.globalCountDownLatchAllPackages.countUp(3);
67
70
 
68
71
  // Read the associated package.json and parse it.
69
- fs.readFile(packageJsonPath, { encoding: 'utf8' }, (err, contents) => {
70
- if (err) {
71
- logger.debug(
72
- 'Failed to calculate transitive distances for some dependencies, could not read package.json file at %s: %s.',
73
- packageJsonPath,
74
- err.message
75
- );
72
+ try {
73
+ fs.readFile(packageJsonPath, { encoding: 'utf8' }, (err, contents) => {
74
+ if (err) {
75
+ 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
80
+ );
76
81
 
77
- // If we cannot parse the package.json or if it does not exist, we need to decrement by 3 immediately because we
78
- // increment the latch by 3 for each node (see above).
79
- this.globalCountDownLatchAllPackages.countDown(3);
80
- return;
81
- }
82
+ // If we cannot parse the package.json or if it does not exist, we need to decrement by 3 immediately because
83
+ // we increment the latch by 3 for each node (see above).
84
+ this.globalCountDownLatchAllPackages.countDown(3);
85
+ return;
86
+ }
82
87
 
83
- let parsedPackageJson;
84
- try {
85
- parsedPackageJson = JSON.parse(contents);
86
- } catch (parseErr) {
87
- logger.debug(
88
- 'Failed to calculate transitive distances for some dependencies, could not parse package.json file at %s: %s',
89
- packageJsonPath,
90
- parseErr.message
91
- );
92
- this.globalCountDownLatchAllPackages.countDown(3);
93
- return;
94
- }
88
+ let parsedPackageJson;
89
+ try {
90
+ parsedPackageJson = JSON.parse(contents);
91
+ } catch (parseErr) {
92
+ 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
97
+ );
98
+ this.globalCountDownLatchAllPackages.countDown(3);
99
+ return;
100
+ }
95
101
 
96
- // Each call to _calculateDistancesForOneType is guaranteed to decrease the global count down latch by exactly
97
- // one, to offset the increment of 3 that we did for this node in the dependency tree initially.
98
- this._calculateDistancesForOneType(parsedPackageJson.dependencies, distance);
99
- this._calculateDistancesForOneType(parsedPackageJson.peerDependencies, distance);
100
- this._calculateDistancesForOneType(parsedPackageJson.optionalDependencies, distance);
101
- });
102
+ // Each call to _calculateDistancesForOneType is guaranteed to decrease the global count down latch by exactly
103
+ // one, to offset the increment of 3 that we did for this node in the dependency tree initially.
104
+ this._calculateDistancesForOneType(parsedPackageJson.dependencies, distance);
105
+ this._calculateDistancesForOneType(parsedPackageJson.peerDependencies, distance);
106
+ this._calculateDistancesForOneType(parsedPackageJson.optionalDependencies, distance);
107
+ });
108
+ } catch (fsReadFileErr) {
109
+ // This catch-block is for synchronous errors from fs.readFile, which can also happen in addition to the callback
110
+ // being called with an error.
111
+ logger.debug(
112
+ 'Failed to calculate transitive distances for some dependencies, synchronous error from fs.readFile for %s:',
113
+ packageJsonPath,
114
+ fsReadFileErr
115
+ );
116
+ this.globalCountDownLatchAllPackages.countDown(3);
117
+ }
102
118
  }
103
119
 
104
120
  /**
@@ -186,6 +202,14 @@ class DependencyDistanceCalculator {
186
202
  );
187
203
  return;
188
204
  }
205
+ if (typeof packageJsonPath !== 'string') {
206
+ localCountDownLatchForThisNode.countDown();
207
+ logger.debug(
208
+ `Ignoring failure to find the package.json file for dependency ${dependency} for dependency distance ` +
209
+ `calculation (package.json path is ${packageJsonPath}/${typeof packageJsonPath}).`
210
+ );
211
+ return;
212
+ }
189
213
 
190
214
  // Recurse one level deeper and queue the next package.json path for analysis.
191
215
  this._calculateDistances(packageJsonPath, distance + 1);
@@ -205,23 +229,30 @@ class DependencyDistanceCalculator {
205
229
  * @param {string} dir
206
230
  * @param {(err: Error, packageJsonPath: string) => void} callback
207
231
  */
232
+
208
233
  function findPackageJsonFor(dir, callback) {
209
234
  const pathToCheck = path.join(dir, 'package.json');
210
- fs.stat(pathToCheck, (err, stats) => {
211
- if (err) {
212
- if (err.code === 'ENOENT') {
213
- return searchInParentDir(dir, findPackageJsonFor, callback);
214
- } else {
215
- return process.nextTick(callback, err, null);
235
+ try {
236
+ fs.stat(pathToCheck, (err, stats) => {
237
+ if (err) {
238
+ if (err.code === 'ENOENT') {
239
+ return searchInParentDir(dir, findPackageJsonFor, callback);
240
+ } else {
241
+ return process.nextTick(callback, err, null);
242
+ }
216
243
  }
217
- }
218
244
 
219
- if (stats.isFile()) {
220
- return process.nextTick(callback, null, pathToCheck);
221
- } else {
222
- return searchInParentDir(dir, findPackageJsonFor, callback);
223
- }
224
- });
245
+ if (stats.isFile()) {
246
+ return process.nextTick(callback, null, pathToCheck);
247
+ } else {
248
+ return searchInParentDir(dir, findPackageJsonFor, callback);
249
+ }
250
+ });
251
+ } catch (fsStatErr) {
252
+ // This catch-block is for synchronous errors from fs.stat, which can also happen in addition to the callback being
253
+ // called with an error. The error will be logged in _handleTransitiveDependency.
254
+ return process.nextTick(callback, fsStatErr, null);
255
+ }
225
256
  }
226
257
 
227
258
  /**