Skip to content

Commit 3da643a

Browse files
authored
OpenTelemetry: ignore bubble errors to avoid spamming traces (#56625)
The "bubble" errors are created here: https://github.com/vercel/next.js/blob/3f25a2e747fc27da6c2166e45d54fc95e96d7895/packages/next/src/server/next-server.ts#L1636-L1639 These errors do not appear to be true errors, but they tend to spam tracing. E.g. <img width="1412" alt="image" src="https://github.com/vercel/next.js/assets/726049/d62f3116-5f94-45ac-947c-e59ac4bfa533">
1 parent 8013ef7 commit 3da643a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/next/src/server/lib/trace/tracer.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ const isPromise = <T>(p: any): p is Promise<T> => {
3434
return p !== null && typeof p === 'object' && typeof p.then === 'function'
3535
}
3636

37+
type BubbledError = Error & { bubble?: boolean }
38+
3739
const closeSpanWithError = (span: Span, error?: Error) => {
38-
if (error) {
39-
span.recordException(error)
40+
if ((error as BubbledError | undefined)?.bubble === true) {
41+
span.setAttribute('next.bubble', true)
42+
} else {
43+
if (error) {
44+
span.recordException(error)
45+
}
46+
span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message })
4047
}
41-
span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message })
4248
span.end()
4349
}
4450

0 commit comments

Comments
 (0)