Skip to content

Commit 6278107

Browse files
authored
feat: Allowed undici error reporting to be disabled with feature flag undici_error_tracking (#2956)
Thanks for your contribution @Voziv 🎉
1 parent 98d29fe commit 6278107

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

documentation/feature-flags.md

+6
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ Any prerelease flags can be enabled or disabled in your agent config by adding a
3939
* Environment Variable: `NEW_RELIC_FEATURE_FLAG_OTEL_INSTRUMENTATION`
4040
* Description: Enables the creation of Transaction Trace segments and time slices metrics from opentelemetry spans. This will help drive New Relic UI experience for opentelemetry spans.
4141
* **WARNING**: This is not feature complete and is not intended to be enabled yet.
42+
43+
#### undici_error_tracking
44+
* Enabled by default: `true`
45+
* Configuration: `{ feature_flag: { undici_error_tracking: true|false }}`
46+
* Environment Variable: `NEW_RELIC_FEATURE_FLAG_UNDICI_ERROR_TRACKING`
47+
* Description: Enables the creation of errors when a request with undici fails. To disable tracking errors with undici, set the value to `false`.

lib/feature_flags.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ exports.prerelease = {
1414
promise_segments: false,
1515
reverse_naming_rules: false,
1616
unresolved_promise_cleanup: true,
17-
kafkajs_instrumentation: false
17+
kafkajs_instrumentation: false,
18+
undici_error_tracking: true
1819
}
1920

2021
// flags that are no longer used for released features

lib/instrumentation/undici.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,15 @@ function requestHeadersHook(shim, { request, response }) {
192192
* @param {Error} params.error error from undici request
193193
*/
194194
function endAndRestoreSegment(shim, { request, error }) {
195+
const { config } = shim.agent
195196
const activeSegment = request[symbols.segment]
196197
const parentSegment = request[symbols.parentSegment]
197198
const tx = request[symbols.transaction]
198199
if (activeSegment) {
199200
activeSegment.end()
200201
}
201202

202-
if (error && tx) {
203+
if (error && tx && config.feature_flag.undici_error_tracking === true) {
203204
handleError(shim, tx, error)
204205
}
205206

test/unit/feature_flag.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const used = [
4141
'undici_async_tracking',
4242
'aws_bedrock_instrumentation',
4343
'langchain_instrumentation',
44-
'kafkajs_instrumentation'
44+
'kafkajs_instrumentation',
45+
'undici_error_tracking'
4546
]
4647

4748
test.beforeEach((ctx) => {

test/versioned/undici/requests.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,26 @@ test('Undici request tests', async (t) => {
312312
})
313313
})
314314

315+
await t.test('should not log error when `feature_flag.undici_error_tracking` is false', async (t) => {
316+
agent.config.feature_flag.undici_error_tracking = false
317+
t.after(() => {
318+
agent.config.feature_flag.undici_error_tracking = true
319+
})
320+
await helper.runInTransaction(agent, async (tx) => {
321+
try {
322+
await undici.request('https://invalidurl', {
323+
path: '/foo',
324+
method: 'GET'
325+
})
326+
} catch (err) {
327+
assert.ok(err)
328+
assertSegments(tx.trace, tx.trace.root, ['External/invalidurl/foo'], { exact: false })
329+
assert.equal(tx.exceptions.length, 0)
330+
tx.end()
331+
}
332+
})
333+
})
334+
315335
await t.test('segments should end on error', async () => {
316336
const socketEndServer = http.createServer(function badHandler(req) {
317337
req.socket.end()

0 commit comments

Comments
 (0)