Unverified Commit 1f999b6f authored by Dima Voytenko's avatar Dima Voytenko Committed by GitHub

OpenTel: ensure that exceptions are recorded on an active span (#54131)

Examples of the output with this change:

<img width="346" alt="image" src="https://github.com/vercel/next.js/assets/726049/6f8b94ea-5890-401a-9760-15af38ea4f0c">
parent 06e7e76c
......@@ -4,6 +4,7 @@ import { formatServerError } from '../../lib/format-server-error'
import { isNotFoundError } from '../../client/components/not-found'
import { isRedirectError } from '../../client/components/redirect'
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../../shared/lib/lazy-dynamic/no-ssr-error'
import { SpanStatusCode, getTracer } from '../lib/trace/tracer'
/**
* Create error handler for renderers.
......@@ -56,6 +57,16 @@ export function createErrorHandler({
)
)
) {
// Record exception in an active span, if available.
const span = getTracer().getActiveScopeSpan()
if (span) {
span.recordException(err)
span.setStatus({
code: SpanStatusCode.ERROR,
message: err.message,
})
}
if (errorLogger) {
errorLogger(err).catch(() => {})
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment