Skip to content

Commit

Permalink
Add a special logging tag to uncaught handler exceptions (#266)
Browse files Browse the repository at this point in the history
## Why

We want to pipe uncaught errors in handlers to Sentry, we think it's ok
to do that via the logger as opposed to having a special error callback.

## What changed

- Add tag `uncaught-handler-error`
- Include `originalException` in `extras` (for proper stack traces)
- Change `extras` in logs from `unknown` to an optional `Record<string,
unknown>` (we're using it that way anyway, just makes it easier to
handle)

## Versioning

- [ ] Breaking protocol change
- [ ] Breaking ts/js API change

<!-- Kind reminder to add tests and updated documentation if needed -->
  • Loading branch information
masad-frost authored Sep 3, 2024
1 parent 998bc75 commit 4f610d4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions logging/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export type Tags =
| 'invariant-violation'
| 'state-transition'
| 'invalid-request'
| 'unhealthy-session';
| 'unhealthy-session'
| 'uncaught-handler-error';

const cleanedLogFn = (log: LogFn) => {
return (msg: string, metadata?: MessageMetadata) => {
Expand Down Expand Up @@ -53,7 +54,7 @@ export type MessageMetadata = Partial<{
traceId: string;
spanId: string;
};
extras: unknown;
extras?: Record<string, unknown>;
}>;

export class BaseLogger implements Logger {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@replit/river",
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
"version": "0.200.3",
"version": "0.200.4",
"type": "module",
"exports": {
".": {
Expand Down
2 changes: 2 additions & 0 deletions router/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ class RiverServer<Services extends AnyServiceSchemaMap>
},
extras: {
error: errorMsg,
originalException: err,
},
tags: ['uncaught-handler-error'],
},
);

Expand Down
2 changes: 1 addition & 1 deletion transport/impls/ws/connection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from '../../connection';
import { WsLike } from './wslike';

interface ConnectionInfoExtras {
interface ConnectionInfoExtras extends Record<string, unknown> {
headers: Record<string, string>;
}

Expand Down

0 comments on commit 4f610d4

Please sign in to comment.