newrelic 12.11.0 → 12.11.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,21 @@
1
+ ### v12.11.1 (2025-01-16)
2
+
3
+ #### Bug fixes
4
+
5
+ * Updated undici instrumentation to fix crash with trying to calculate exclusive duration on a segment that no longer exists ([#2884](https://github.com/newrelic/node-newrelic/pull/2884)) ([3b7e4bf](https://github.com/newrelic/node-newrelic/commit/3b7e4bf0a40b21f16b11e7761809cbaa83c02515))
6
+
7
+ #### Documentation
8
+
9
+ * Updated compatibility report ([#2878](https://github.com/newrelic/node-newrelic/pull/2878)) ([e784f84](https://github.com/newrelic/node-newrelic/commit/e784f8427bd49852f0ed7a15d6025ea8dfc73c72))
10
+
11
+ #### Miscellaneous chores
12
+
13
+ * Fixed dns integration tests ([#2883](https://github.com/newrelic/node-newrelic/pull/2883)) ([dd30ad7](https://github.com/newrelic/node-newrelic/commit/dd30ad71f07233682da39ca41f452a55c6798a15))
14
+
15
+ #### Tests
16
+
17
+ * Restored the branch to test apollo-server-plugin to main ([#2879](https://github.com/newrelic/node-newrelic/pull/2879)) ([978faab](https://github.com/newrelic/node-newrelic/commit/978faab59f5378e26cb8f5e584a3c9e684e7bbb1))
18
+
1
19
  ### v12.11.0 (2025-01-14)
2
20
 
3
21
  #### Features
@@ -13,7 +13,6 @@ exports.prerelease = {
13
13
 
14
14
  promise_segments: false,
15
15
  reverse_naming_rules: false,
16
- undici_async_tracking: true,
17
16
  unresolved_promise_cleanup: true,
18
17
  kafkajs_instrumentation: false
19
18
  }
@@ -36,6 +35,7 @@ exports.released = [
36
35
  'await_support',
37
36
  'certificate_bundle',
38
37
  'async_local_context',
38
+ 'undici_async_tracking',
39
39
  'undici_instrumentation',
40
40
  'aws_bedrock_instrumentation',
41
41
  'langchain_instrumentation'
@@ -11,8 +11,6 @@ const logger = require('../logger').child({ component: 'undici' })
11
11
  const NAMES = require('../metrics/names')
12
12
  const symbols = require('../symbols')
13
13
  // eslint-disable-next-line n/no-unsupported-features/node-builtins
14
- const { executionAsyncResource } = require('async_hooks')
15
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
16
14
  const diagnosticsChannel = require('diagnostics_channel')
17
15
  const synthetics = require('../synthetics')
18
16
  const urltils = require('../util/urltils')
@@ -49,42 +47,6 @@ module.exports.unsubscribe = function unsubscribe() {
49
47
  })
50
48
  }
51
49
 
52
- /**
53
- * Retrieves the current segment(parent in our context) and transaction from executionAsyncResource
54
- * or from context manager then adds to the executionAsyncResource for future
55
- * undici requests within same async context.
56
- *
57
- * It was found that when running concurrent undici requests
58
- * within a transaction that the parent segment would get out of sync
59
- * depending on the async context of the transaction. By using
60
- * `async_hooks.executionResource` it is more reliable.
61
- *
62
- * Note: However, if you have concurrent undici requests in a transaction
63
- * and the request to the transaction is using a keep alive there is a chance the
64
- * executionAsyncResource may be incorrect because of shared connections. To revert to a more
65
- * naive tracking of parent set `config.feature_flag.undici_async_tracking: false` and
66
- * it will just get the segment and transaction from the context manager.
67
- *
68
- * @param {Shim} shim instance of shim
69
- * @returns {TraceSegment} parent segment
70
- */
71
- function getParentContext(shim) {
72
- const { config } = shim.agent
73
- if (config.feature_flag.undici_async_tracking) {
74
- const resource = executionAsyncResource()
75
-
76
- if (!resource[symbols.parentSegment]) {
77
- const parent = shim.getSegment()
78
- resource[symbols.parentSegment] = parent
79
- const tx = shim.tracer.getTransaction()
80
- resource[symbols.transaction] = tx
81
- }
82
- return { segment: resource[symbols.parentSegment], transaction: resource[symbols.transaction] }
83
- }
84
-
85
- return shim.tracer.getContext()
86
- }
87
-
88
50
  /**
89
51
  * Injects relevant DT headers for the external request
90
52
  *
@@ -160,7 +122,7 @@ function createExternalSegment({ shim, request, segment }) {
160
122
  */
161
123
  function requestCreateHook(shim, { request }) {
162
124
  const { config } = shim.agent
163
- const { transaction, segment } = getParentContext(shim)
125
+ const { transaction, segment } = shim.tracer.getContext()
164
126
  request[symbols.parentSegment] = segment
165
127
  request[symbols.transaction] = transaction
166
128
  if (!(segment || transaction) || segment?.opaque) {
@@ -221,9 +183,8 @@ function requestHeadersHook(shim, { request, response }) {
221
183
  }
222
184
 
223
185
  /**
224
- * Gets the active and parent from given ctx(request, client connector)
225
- * and ends active and restores parent to active. If an error exists
226
- * it will add the error to the transaction
186
+ * Gets the active segment, parent segment and transaction from given ctx(request, client connector)
187
+ * and ends segment and sets the previous parent segment as the active segment. If an error exists it will add the error to the transaction
227
188
  *
228
189
  * @param {Shim} shim instance of shim
229
190
  * @param {object} params object from undici hook
@@ -236,14 +197,14 @@ function endAndRestoreSegment(shim, { request, error }) {
236
197
  const tx = request[symbols.transaction]
237
198
  if (activeSegment) {
238
199
  activeSegment.end()
200
+ }
239
201
 
240
- if (error) {
241
- handleError(shim, tx, error)
242
- }
202
+ if (error && tx) {
203
+ handleError(shim, tx, error)
204
+ }
243
205
 
244
- if (parentSegment) {
245
- shim.setActiveSegment(parentSegment)
246
- }
206
+ if (parentSegment) {
207
+ shim.setActiveSegment(parentSegment)
247
208
  }
248
209
  }
249
210
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newrelic",
3
- "version": "12.11.0",
3
+ "version": "12.11.1",
4
4
  "author": "New Relic Node.js agent team <nodejs@newrelic.com>",
5
5
  "license": "Apache-2.0",
6
6
  "contributors": [