Skip to content

Commit

Permalink
OpenTel: ensure that exceptions are recorded on an active span
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoytenko committed Aug 21, 2023
1 parent 5d758c7 commit 990f6c8
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 990f6c8

Please sign in to comment.