Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/next/src/server/app-render/create-error-handler.tsx
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