newrelic 11.2.1 → 11.3.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/NEWS.md CHANGED
@@ -1,3 +1,28 @@
1
+ ### v11.3.0 (2023-10-23)
2
+
3
+ #### Features
4
+
5
+ * Updated agent initialization to allow running in worker threads when config.worker_threads.enabled is true ([#1817](https://github.com/newrelic/node-newrelic/pull/1817)) ([a39f0ef](https://github.com/newrelic/node-newrelic/commit/a39f0ef5ac670d03ab407b24e5aeccd8d5e8c680))
6
+
7
+ #### Bug fixes
8
+
9
+ * Updated Elasticsearch instrumentation to register on v7.13.0+ only ([#1816](https://github.com/newrelic/node-newrelic/pull/1816)) ([6437671](https://github.com/newrelic/node-newrelic/commit/6437671b921cd6bd73ed31180b0d62f62cc229a2))
10
+
11
+ #### Miscellaneous chores
12
+
13
+ * **dev-deps:** Bumped @babel/traverse ([#1818](https://github.com/newrelic/node-newrelic/pull/1818)) ([d3c8d04](https://github.com/newrelic/node-newrelic/commit/d3c8d04b74b7a84846609b744e3b4922136dbdd6))
14
+ * Updated release note headers to follow standard sentence caps ([#1806](https://github.com/newrelic/node-newrelic/pull/1806)) ([91d3600](https://github.com/newrelic/node-newrelic/commit/91d36009e0496af823cfbc3a4bdb2b32a97ba8c5))
15
+
16
+ #### Tests
17
+
18
+ * Updated the grpc versioned tests utils to dynamically bind ports to avoid conflicts between cjs and esm tests ([#1820](https://github.com/newrelic/node-newrelic/pull/1820)) ([95ac917](https://github.com/newrelic/node-newrelic/commit/95ac917da92575e178d8026bdc0badb08ba6fb83))
19
+
20
+ #### Continuous integration
21
+
22
+ * Disabled fail-fast on testing jobs to make sure all versions are run before getting canceled because of a flappy test ([#1819](https://github.com/newrelic/node-newrelic/pull/1819)) ([0928ee3](https://github.com/newrelic/node-newrelic/commit/0928ee3db82533e2386ad2bf4b87074b4f15f33b))
23
+ * Updated CI workflow to use larger runners on versioned tests but only when running against the main branch ([#1812](https://github.com/newrelic/node-newrelic/pull/1812)) ([01eaa14](https://github.com/newrelic/node-newrelic/commit/01eaa14c76a32966f6af8475e6ba6d4e00b03513))
24
+ * Updated post release script to update the nodejs_agent_version only on staging and us prod, eu will get it via replication now ([#1811](https://github.com/newrelic/node-newrelic/pull/1811)) ([317a00a](https://github.com/newrelic/node-newrelic/commit/317a00a9c160b52b053cb1f9f55292551c4c3428))
25
+
1
26
  ### v11.2.1 (2023-10-12)
2
27
 
3
28
  #### Bug fixes
@@ -59,6 +84,7 @@
59
84
  * Updated agent to use require-in-the-middle to register CommonJS instrumentation. You can no longer use an onResolved hook to register custom instrumentation.
60
85
  * Updated the default context manager to be AsyncLocalContextManager.
61
86
  * Renamed `shim.handleCATHeaders` to `shim.handleMqTracingHeaders`.
87
+ * Updated agent to only run in the main thread. This is because running in a worker thread does not completely function out of the box. This will reduce the overhead for customers that are naively trying to load this into worker threads.
62
88
 
63
89
  #### Features
64
90
 
package/index.js CHANGED
@@ -20,28 +20,23 @@ const NAMES = require('./lib/metrics/names')
20
20
  const isESMSupported = psemver.satisfies('>=16.2.0')
21
21
 
22
22
  const pkgJSON = require('./package.json')
23
- if (isMainThread) {
24
- logger.info(
25
- 'Using New Relic for Node.js. Agent version: %s; Node version: %s.',
26
- pkgJSON.version,
27
- process.version
23
+ logger.info(
24
+ 'Using New Relic for Node.js. Agent version: %s; Node version: %s.',
25
+ pkgJSON.version,
26
+ process.version
27
+ )
28
+
29
+ if (require.cache.__NR_cache) {
30
+ logger.warn(
31
+ 'Attempting to load a second copy of newrelic from %s, using cache instead',
32
+ __dirname
28
33
  )
29
-
30
- if (require.cache.__NR_cache) {
31
- logger.warn(
32
- 'Attempting to load a second copy of newrelic from %s, using cache instead',
33
- __dirname
34
- )
35
- if (require.cache.__NR_cache.agent) {
36
- require.cache.__NR_cache.agent.recordSupportability('Agent/DoubleLoad')
37
- }
38
- module.exports = require.cache.__NR_cache
39
- } else {
40
- initialize()
34
+ if (require.cache.__NR_cache.agent) {
35
+ require.cache.__NR_cache.agent.recordSupportability('Agent/DoubleLoad')
41
36
  }
37
+ module.exports = require.cache.__NR_cache
42
38
  } else {
43
- logger.warn('Using New Relic for Node.js in worker_threads is not supported. Not starting!')
44
- initApi({ apiPath: './stub_api' })
39
+ initialize()
45
40
  }
46
41
 
47
42
  function initApi({ agent, apiPath }) {
@@ -97,7 +92,16 @@ function initialize() {
97
92
  logger.info('No configuration detected. Not starting.')
98
93
  } else if (!config.agent_enabled) {
99
94
  logger.info('Module disabled in configuration. Not starting.')
95
+ } else if (!config.worker_threads.enabled && !isMainThread) {
96
+ logger.warn(
97
+ 'New Relic for Node.js in worker_threads is not officially supported. Not starting! To bypass this, set `config.worker_threads.enabled` to true in configuration.'
98
+ )
100
99
  } else {
100
+ if (!isMainThread && config.worker_threads.enabled) {
101
+ logger.warn(
102
+ 'Attempting to load agent in worker thread. This is not officially supported. Use at your own risk.'
103
+ )
104
+ }
101
105
  agent = createAgent(config)
102
106
  addStartupSupportabilities(agent)
103
107
  }
@@ -1320,11 +1320,31 @@ defaultConfig.definition = () => ({
1320
1320
  }
1321
1321
  },
1322
1322
 
1323
+ /**
1324
+ * When enabled, it will use `process.env.DYNO`
1325
+ * to set the hostname of the running application
1326
+ */
1323
1327
  heroku: {
1324
1328
  use_dyno_names: {
1325
1329
  default: true,
1326
1330
  formatter: boolean
1327
1331
  }
1332
+ },
1333
+
1334
+ /**
1335
+ * When enabled, it will allow loading of the agent
1336
+ * in worker threads.
1337
+ *
1338
+ * In 11.0.0 we added code to prevent loading in worker threads
1339
+ * to cut down on unnecessary overhead of the agent. We have found
1340
+ * in testing that traces and spans were useless unless work was
1341
+ * completely self contained in the worker thread.
1342
+ */
1343
+ worker_threads: {
1344
+ enabled: {
1345
+ formatter: boolean,
1346
+ default: false
1347
+ }
1328
1348
  }
1329
1349
  })
1330
1350
 
@@ -5,6 +5,8 @@
5
5
 
6
6
  'use strict'
7
7
 
8
+ const { isSimpleObject } = require('../util/objects')
9
+
8
10
  class MergeServerConfig {
9
11
  // eslint-disable-next-line max-params
10
12
  updateNestedIfChanged(config, remote, local, remoteKey, localKey, logger) {
@@ -21,7 +23,7 @@ class MergeServerConfig {
21
23
  // value is an array, a simple object, or anything else
22
24
  if (Array.isArray(value) && Array.isArray(local[localKey])) {
23
25
  this.updateArray(value, local, localKey)
24
- } else if (this.isSimpleObject(value) && this.isSimpleObject(local[localKey])) {
26
+ } else if (isSimpleObject(value) && isSimpleObject(local[localKey])) {
25
27
  this.updateObject(value, local, localKey)
26
28
  } else {
27
29
  local[localKey] = value
@@ -54,10 +56,6 @@ class MergeServerConfig {
54
56
  }
55
57
  })
56
58
  }
57
-
58
- isSimpleObject(thing) {
59
- return 'object' === typeof thing && thing !== null
60
- }
61
59
  }
62
60
 
63
61
  module.exports = MergeServerConfig
@@ -4,7 +4,9 @@
4
4
  */
5
5
 
6
6
  'use strict'
7
+ const semver = require('semver')
7
8
  const logger = require('../../logger').child({ component: 'ElasticSearch' })
9
+ const { isNotEmpty } = require('../../util/objects')
8
10
 
9
11
  /**
10
12
  * Instruments the `@elastic/elasticsearch` module. This function is
@@ -17,6 +19,15 @@ const logger = require('../../logger').child({ component: 'ElasticSearch' })
17
19
  * @returns {void}
18
20
  */
19
21
  module.exports = function initialize(_agent, elastic, _moduleName, shim) {
22
+ const pkgVersion = shim.require('./package.json').version
23
+ if (semver.lt(pkgVersion, '7.13.0')) {
24
+ shim &&
25
+ shim.logger.debug(
26
+ `ElasticSearch support is for versions 7.13.0 and above. Not instrumenting ${pkgVersion}.`
27
+ )
28
+ return
29
+ }
30
+
20
31
  shim.setDatastore(shim.ELASTICSEARCH)
21
32
  shim.setParser(queryParser)
22
33
 
@@ -46,18 +57,17 @@ module.exports = function initialize(_agent, elastic, _moduleName, shim) {
46
57
  */
47
58
  function queryParser(params) {
48
59
  params = JSON.parse(params)
49
-
50
60
  const { collection, operation } = parsePath(params.path, params.method)
51
61
 
52
62
  // the substance of the query may be in querystring or in body.
53
63
  let queryParam = {}
54
- if (typeof params.querystring === 'object' && Object.keys(params.querystring).length > 0) {
64
+ if (isNotEmpty(params.querystring)) {
55
65
  queryParam = params.querystring
56
66
  }
57
67
  // let body or bulkBody override querystring, as some requests have both
58
- if (typeof params.body === 'object' && Object.keys(params.body).length > 0) {
68
+ if (isNotEmpty(params.body)) {
59
69
  queryParam = params.body
60
- } else if (typeof params.bulkBody === 'object' && Object.keys(params.bulkBody).length > 0) {
70
+ } else if (isNotEmpty(params.bulkBody)) {
61
71
  queryParam = params.bulkBody
62
72
  }
63
73
 
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ 'use strict'
7
+ exports = module.exports = { isSimpleObject, isNotEmpty }
8
+
9
+ /**
10
+ * Convenience function to test if a value is a non-null object
11
+ *
12
+ * @param {object} thing Value to be tested
13
+ * @returns {boolean} whether or not the value is an object and not null
14
+ */
15
+ function isSimpleObject(thing) {
16
+ return 'object' === typeof thing && thing !== null
17
+ }
18
+
19
+ /**
20
+ * Convenience function to test if an object is not empty
21
+ *
22
+ * @param {object} thing Value to be tested
23
+ * @returns {boolean} true if the value is an object, not null, and has keys
24
+ */
25
+ function isNotEmpty(thing) {
26
+ return isSimpleObject(thing) && Object.keys(thing).length > 0
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newrelic",
3
- "version": "11.2.1",
3
+ "version": "11.3.0",
4
4
  "author": "New Relic Node.js agent team <nodejs@newrelic.com>",
5
5
  "license": "Apache-2.0",
6
6
  "contributors": [