Skip to content

Commit

Permalink
OpenTel: ensure that exceptions are recorded on an active span (#54131)
Browse files Browse the repository at this point in the history
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">
  • Loading branch information
dvoytenko authored Aug 21, 2023
1 parent 06e7e76 commit 1f999b6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/next/src/server/app-render/create-error-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1f999b6

Please sign in to comment.