newrelic 11.2.1 → 11.4.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,43 @@
1
+ ### v11.4.0 (2023-10-25)
2
+
3
+ #### Features
4
+
5
+ * Added support for parsing container ids from docker versions using cgroups v2. ([#1830](https://github.com/newrelic/node-newrelic/pull/1830)) ([9892901](https://github.com/newrelic/node-newrelic/commit/98929013da3e62e2223f94531b8d6f59eecfc35b))
6
+
7
+ #### Miscellaneous chores
8
+
9
+ * [Snyk] Upgraded @grpc/grpc-js from 1.9.2 to 1.9.4. ([#1823](https://github.com/newrelic/node-newrelic/pull/1823)) ([81f9450](https://github.com/newrelic/node-newrelic/commit/81f945033376e4d33651d1e42afc30aea19dbdeb))
10
+ * **deps:** Updated aws-sdk, koa, superagent ([#1831](https://github.com/newrelic/node-newrelic/pull/1831)) ([8b4e963](https://github.com/newrelic/node-newrelic/commit/8b4e963e84d34e4727b9fda3aa630ef119aa3905))
11
+
12
+ #### Tests
13
+
14
+ * Increased timeout for integration tests to avoid random failures. ([#1827](https://github.com/newrelic/node-newrelic/pull/1827)) ([5202048](https://github.com/newrelic/node-newrelic/commit/52020485191868f479092ae4860019acf105b3eb))
15
+
16
+ ### v11.3.0 (2023-10-23)
17
+
18
+ #### Features
19
+
20
+ * 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))
21
+
22
+ #### Bug fixes
23
+
24
+ * 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))
25
+
26
+ #### Miscellaneous chores
27
+
28
+ * **dev-deps:** Bumped @babel/traverse ([#1818](https://github.com/newrelic/node-newrelic/pull/1818)) ([d3c8d04](https://github.com/newrelic/node-newrelic/commit/d3c8d04b74b7a84846609b744e3b4922136dbdd6))
29
+ * 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))
30
+
31
+ #### Tests
32
+
33
+ * 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))
34
+
35
+ #### Continuous integration
36
+
37
+ * 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))
38
+ * 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))
39
+ * 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))
40
+
1
41
  ### v11.2.1 (2023-10-12)
2
42
 
3
43
  #### Bug fixes
@@ -59,6 +99,7 @@
59
99
  * 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
100
  * Updated the default context manager to be AsyncLocalContextManager.
61
101
  * Renamed `shim.handleCATHeaders` to `shim.handleMqTracingHeaders`.
102
+ * 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
103
 
63
104
  #### Features
64
105
 
@@ -92,7 +92,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
92
92
 
93
93
  ### @grpc/grpc-js
94
94
 
95
- This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.9.2](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.9.2)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.9.2/LICENSE):
95
+ This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.9.4](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.9.4)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.9.4/LICENSE):
96
96
 
97
97
  ```
98
98
  Apache License
@@ -510,7 +510,7 @@ This product includes source derived from [@grpc/proto-loader](https://github.co
510
510
 
511
511
  ### @newrelic/aws-sdk
512
512
 
513
- This product includes source derived from [@newrelic/aws-sdk](https://github.com/newrelic/node-newrelic-aws-sdk) ([v7.0.0](https://github.com/newrelic/node-newrelic-aws-sdk/tree/v7.0.0)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-newrelic-aws-sdk/blob/v7.0.0/LICENSE):
513
+ This product includes source derived from [@newrelic/aws-sdk](https://github.com/newrelic/node-newrelic-aws-sdk) ([v7.0.2](https://github.com/newrelic/node-newrelic-aws-sdk/tree/v7.0.2)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-newrelic-aws-sdk/blob/v7.0.2/LICENSE):
514
514
 
515
515
  ```
516
516
  Apache License
@@ -718,7 +718,7 @@ This product includes source derived from [@newrelic/aws-sdk](https://github.com
718
718
 
719
719
  ### @newrelic/koa
720
720
 
721
- This product includes source derived from [@newrelic/koa](https://github.com/newrelic/node-newrelic-koa) ([v8.0.0](https://github.com/newrelic/node-newrelic-koa/tree/v8.0.0)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-newrelic-koa/blob/v8.0.0/LICENSE):
721
+ This product includes source derived from [@newrelic/koa](https://github.com/newrelic/node-newrelic-koa) ([v8.0.1](https://github.com/newrelic/node-newrelic-koa/tree/v8.0.1)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-newrelic-koa/blob/v8.0.1/LICENSE):
722
722
 
723
723
  ```
724
724
  Apache License
@@ -978,7 +978,7 @@ This license terminates when the Pre-Release Software stops being provided by Ne
978
978
 
979
979
  ### @newrelic/superagent
980
980
 
981
- This product includes source derived from [@newrelic/superagent](https://github.com/newrelic/node-newrelic-superagent) ([v7.0.0](https://github.com/newrelic/node-newrelic-superagent/tree/v7.0.0)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-newrelic-superagent/blob/v7.0.0/LICENSE):
981
+ This product includes source derived from [@newrelic/superagent](https://github.com/newrelic/node-newrelic-superagent) ([v7.0.1](https://github.com/newrelic/node-newrelic-superagent/tree/v7.0.1)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-newrelic-superagent/blob/v7.0.1/LICENSE):
982
982
 
983
983
  ```
984
984
  Apache License
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
+ }
@@ -10,6 +10,8 @@ const common = require('./common')
10
10
  const NAMES = require('../metrics/names')
11
11
  const os = require('os')
12
12
  let vendorInfo = null
13
+ const CGROUPS_V1_PATH = '/proc/self/cgroup'
14
+ const CGROUPS_V2_PATH = '/proc/self/mountinfo'
13
15
 
14
16
  module.exports.getVendorInfo = fetchDockerVendorInfo
15
17
  module.exports.clearVendorCache = function clearDockerVendorCache() {
@@ -51,6 +53,12 @@ module.exports.getBootId = function getBootId(agent, callback) {
51
53
  }
52
54
  }
53
55
 
56
+ /**
57
+ * Attempt to extract container id from either cgroups v1 or v2 file
58
+ *
59
+ * @param {object} agent NR instance
60
+ * @param {Function} callback function to call when done
61
+ */
54
62
  function fetchDockerVendorInfo(agent, callback) {
55
63
  if (!agent.config.utilization || !agent.config.utilization.detect_docker) {
56
64
  return callback(null, null)
@@ -62,16 +70,56 @@ function fetchDockerVendorInfo(agent, callback) {
62
70
 
63
71
  if (!os.platform().match(/linux/i)) {
64
72
  logger.debug('Platform is not a flavor of linux, omitting docker info')
65
- return callback(null)
73
+ return callback(null, null)
66
74
  }
67
75
 
68
- common.readProc('/proc/self/cgroup', function getCGroup(err, data) {
76
+ // try v2 path first and if null try parsing v1 path
77
+ common.readProc(CGROUPS_V2_PATH, function getV2CGroup(err, data) {
78
+ if (data === null) {
79
+ logger.debug(
80
+ `${CGROUPS_V2_PATH} not found, trying to parse container id from ${CGROUPS_V1_PATH}`
81
+ )
82
+ findCGroupsV1(callback)
83
+ return
84
+ }
85
+
86
+ parseCGroupsV2(data, callback)
87
+ })
88
+ }
89
+
90
+ /**
91
+ * Try extracting container id from a /proc/self/mountinfo
92
+ * e.g. - `528 519 254:1 /docker/containers/84cf3472a20d1bfb4b50e48b6ff50d96dfcd812652d76dd907951e6f98997bce/resolv.conf`
93
+ *
94
+ * @param {string} data file contents
95
+ * @param {Function} callback function to call when done
96
+ */
97
+ function parseCGroupsV2(data, callback) {
98
+ const containerLine = new RegExp('/docker/containers/([0-9a-f]{64})/')
99
+ const line = containerLine.exec(data)
100
+ if (line) {
101
+ callback(null, { id: line[1] })
102
+ } else {
103
+ logger.debug(`Found ${CGROUPS_V2_PATH} but failed to parse Docker container id.`)
104
+ callback(null, null)
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Read /proc/self/cgroup and try to extract the container id from a cpu line
110
+ * e.g. - `4:cpu:/docker/f37a7e4d17017e7bf774656b19ca4360c6cdc4951c86700a464101d0d9ce97ee`
111
+ *
112
+ * @param {Function} callback function to call when done
113
+ */
114
+ function findCGroupsV1(callback) {
115
+ common.readProc(CGROUPS_V1_PATH, function getCGroup(err, data) {
69
116
  if (!data) {
117
+ logger.debug(`${CGROUPS_V1_PATH} not found, exiting parsing containerId.`)
70
118
  return callback(null)
71
119
  }
72
120
 
73
121
  let id = null
74
- findCGroups(data, 'cpu', function forEachCpuGroup(cpuGroup) {
122
+ parseCGroupsV1(data, 'cpu', function forEachCpuGroup(cpuGroup) {
75
123
  const match = /(?:^|[^0-9a-f])([0-9a-f]{64})(?:[^0-9a-f]|$)/.exec(cpuGroup)
76
124
  if (match) {
77
125
  id = match[1]
@@ -91,7 +139,14 @@ function fetchDockerVendorInfo(agent, callback) {
91
139
  })
92
140
  }
93
141
 
94
- function findCGroups(info, cgroup, eachCb) {
142
+ /**
143
+ * Iterate line by line to extract the container id from the cpu stanza
144
+ *
145
+ * @param {string} info contents of file
146
+ * @param {string} cgroup value is cpu
147
+ * @param {Function} eachCb funtion to test if the container id exists
148
+ */
149
+ function parseCGroupsV1(info, cgroup, eachCb) {
95
150
  const target = new RegExp('^\\d+:[^:]*?\\b' + cgroup + '\\b[^:]*:')
96
151
  const lines = info.split('\n')
97
152
  for (let i = 0; i < lines.length; ++i) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newrelic",
3
- "version": "11.2.1",
3
+ "version": "11.4.0",
4
4
  "author": "New Relic Node.js agent team <nodejs@newrelic.com>",
5
5
  "license": "Apache-2.0",
6
6
  "contributors": [
@@ -146,7 +146,7 @@
146
146
  "bench": "node ./bin/run-bench.js",
147
147
  "docker-env": "./bin/docker-env-vars.sh",
148
148
  "docs": "npm ci && jsdoc -c ./jsdoc-conf.json --private -r .",
149
- "integration": "npm run prepare-test && npm run sub-install && time c8 -o ./coverage/integration tap --test-regex='(\\/|^test\\/integration\\/.*\\.tap\\.js)$' --timeout=300 --no-coverage --reporter classic",
149
+ "integration": "npm run prepare-test && npm run sub-install && time c8 -o ./coverage/integration tap --test-regex='(\\/|^test\\/integration\\/.*\\.tap\\.js)$' --timeout=600 --no-coverage --reporter classic",
150
150
  "prepare-test": "npm run ssl && npm run docker-env",
151
151
  "lint": "eslint ./*.{js,mjs} lib test bin examples",
152
152
  "lint:fix": "eslint --fix, ./*.{js,mjs} lib test bin examples",
@@ -181,12 +181,12 @@
181
181
  "newrelic-naming-rules": "./bin/test-naming-rules.js"
182
182
  },
183
183
  "dependencies": {
184
- "@grpc/grpc-js": "^1.8.10",
184
+ "@grpc/grpc-js": "^1.9.4",
185
185
  "@grpc/proto-loader": "^0.7.5",
186
- "@newrelic/aws-sdk": "^7.0.0",
187
- "@newrelic/koa": "^8.0.0",
186
+ "@newrelic/aws-sdk": "^7.0.2",
187
+ "@newrelic/koa": "^8.0.1",
188
188
  "@newrelic/security-agent": "0.3.0",
189
- "@newrelic/superagent": "^7.0.0",
189
+ "@newrelic/superagent": "^7.0.1",
190
190
  "@tyriar/fibonacci-heap": "^2.0.7",
191
191
  "concat-stream": "^2.0.0",
192
192
  "https-proxy-agent": "^7.0.1",