Repository navigation
feat(shared, server, opentelemetry, cloudflare)!: pass the original error to TracingSpan.recordException
#2494
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ import type { | |
| Promisable, | ||
| Tracer, | ||
| TracingAttributeValue, | ||
| TracingException, | ||
| TracingExceptionLevel, | ||
| TracingSpan, | ||
| } from '@orpc/shared' | ||
|
|
@@ -43,11 +42,22 @@ export class OpenTelemetrySpan implements TracingSpan { | |
| this.span.addEvent(name) | ||
| } | ||
|
|
||
| recordException(level: TracingExceptionLevel, exception: TracingException): void { | ||
| this.span.recordException(exception) | ||
| recordException(level: TracingExceptionLevel, error: unknown): void { | ||
| // OpenTelemetry reads the name, message, stack and code of an error itself | ||
| const exception = error instanceof Error ? error : String(error) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Protect string conversion from replacing the original error. If the handler catches Use a guarded conversion with a fixed fallback here and on Line 53. Keep forwarding ordinary
|
||
|
|
||
| try { | ||
| this.span.recordException(exception) | ||
| } catch { | ||
| // An error can hold values OpenTelemetry fails to read, e.g. a `code` without `toString` | ||
| this.span.recordException(String(error)) | ||
| } | ||
|
|
||
| if (level === 'error') { | ||
| this.span.setStatus({ code: SpanStatusCode.ERROR, message: exception.message }) | ||
| this.span.setStatus({ | ||
| code: SpanStatusCode.ERROR, | ||
| message: typeof exception === 'string' ? exception : exception.message, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard conversion before recording the exception.
If the handler catches
Object.create(null),String(error)throws aTypeErrorbefore thetryblock. The handler then skipsspan.end()and replaces the original thrown value with thatTypeError.Use a guarded string conversion with a fixed fallback. Apply it to the retry path too. Continue to pass ordinary
Errorinstances through unchanged.