newrelic 11.10.0 → 11.10.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.
package/NEWS.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### v11.10.1 (2024-01-25)
2
+
3
+ #### Bug fixes
4
+
5
+ * Updated instrumentation registration to allow for instrumenting of a local file that does not exist within node_modules.
6
+ * To properly instrument a local file, you must pass in `absolutePath` with the absolute path to the file that is being instrumented along with the `moduleName` which in this case is just the file name without the extension. ([#1974](https://github.com/newrelic/node-newrelic/pull/1974)) ([f545b4e](https://github.com/newrelic/node-newrelic/commit/f545b4ebc3394f0a7179a51e156c6df28896edf0))
7
+
1
8
  ### v11.10.0 (2024-01-22)
2
9
 
3
10
  #### Features
package/api.js CHANGED
@@ -1312,7 +1312,7 @@ API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attribut
1312
1312
  *
1313
1313
  * @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
1314
1314
  * @param {string} moduleName.moduleName The module name given to require to load the module
1315
- * @param {Function} moduleName.onResolved The function to call prior to module load after the filepath has been resolved
1315
+ * @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
1316
1316
  * @param {Function} moduleName.onRequire The function to call when the module has been loaded
1317
1317
  * @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
1318
1318
  * @param {Function} onRequire The function to call when the module has been loaded
@@ -1343,7 +1343,7 @@ API.prototype.instrument = function instrument(moduleName, onRequire, onError) {
1343
1343
  *
1344
1344
  * @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
1345
1345
  * @param {string} moduleName.moduleName The module name given to require to load the module
1346
- * @param {Function} moduleName.onResolved The function to call prior to module load after the filepath has been resolved
1346
+ * @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
1347
1347
  * @param {Function} moduleName.onRequire The function to call when the module has been loaded
1348
1348
  * @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
1349
1349
  * @param {Function} onRequire The function to call when the module has been loaded
@@ -1375,7 +1375,7 @@ API.prototype.instrumentConglomerate = function instrumentConglomerate(
1375
1375
  *
1376
1376
  * @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
1377
1377
  * @param {string} moduleName.moduleName The module name given to require to load the module
1378
- * @param {Function} moduleName.onResolved The function to call prior to module load after the filepath has been resolved
1378
+ * @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
1379
1379
  * @param {Function} moduleName.onRequire The function to call when the module has been loaded
1380
1380
  * @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
1381
1381
  * @param {Function} onRequire The function to call when the module has been loaded
@@ -1408,7 +1408,7 @@ API.prototype.instrumentDatastore = function instrumentDatastore(moduleName, onR
1408
1408
  *
1409
1409
  * @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
1410
1410
  * @param {string} moduleName.moduleName The module name given to require to load the module
1411
- * @param {Function} moduleName.onResolved The function to call prior to module load after the filepath has been resolved
1411
+ * @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
1412
1412
  * @param {Function} moduleName.onRequire The function to call when the module has been loaded
1413
1413
  * @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
1414
1414
  * @param {Function} onRequire The function to call when the module has been loaded
@@ -1445,7 +1445,7 @@ API.prototype.instrumentWebframework = function instrumentWebframework(
1445
1445
  *
1446
1446
  * @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
1447
1447
  * @param {string} moduleName.moduleName The module name given to require to load the module
1448
- * @param {Function} moduleName.onResolved The function to call prior to module load after the filepath has been resolved
1448
+ * @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
1449
1449
  * @param {Function} moduleName.onRequire The function to call when the module has been loaded
1450
1450
  * @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
1451
1451
  * @param {Function} onRequire The function to call when the module has been loaded
package/lib/shimmer.js CHANGED
@@ -398,11 +398,17 @@ const shimmer = (module.exports = {
398
398
 
399
399
  if (!registeredInstrumentation) {
400
400
  shimmer.registeredInstrumentations[opts.moduleName] = []
401
+ // In cases where a customer is trying to instrument a file
402
+ // that is not within node_modules, they must provide the absolutePath
403
+ // so require-in-the-middle can call our callback. the moduleName
404
+ // still needs to be the resolved name so we can look up our instrumentation correctly
405
+ const pkgHook = opts.absolutePath || opts.moduleName
406
+
401
407
  // not using a set because this is shared by reference
402
408
  // to allow custom instrumentation to be loaded after the
403
409
  // agent is bootstrapped
404
- if (!pkgsToHook.includes(opts.moduleName)) {
405
- pkgsToHook.push(opts.moduleName)
410
+ if (!pkgsToHook.includes(pkgHook)) {
411
+ pkgsToHook.push(pkgHook)
406
412
  }
407
413
  }
408
414
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newrelic",
3
- "version": "11.10.0",
3
+ "version": "11.10.1",
4
4
  "author": "New Relic Node.js agent team <nodejs@newrelic.com>",
5
5
  "license": "Apache-2.0",
6
6
  "contributors": [