bun run devOpen http://localhost:3000 to test routes from the UI.
The example wires withEvlog() around an OpenAPIHandler so each procedure call becomes a single wide event, and uses os.use(evlog()) on the procedure base to expose context.log and tag every event with operation (the procedure path joined with .).
| Endpoint | RPC feature shown |
|---|---|
GET /health |
Minimal procedure, context.log.set() |
GET /users |
Nested router (users.list) → operation: 'users.list' on the wide event |
GET /users/{id} |
Zod input schema, context accumulation in a service via useLogger(), email masking before logging |
GET /users/unknown |
Typed errors.USER_NOT_FOUND({ data: { userId } }) from os.errors({...}) — clean defined: true response |
POST /payments/charge |
Typed errors.PAYMENT_DECLINED with structured data (reason + retryable flag) |
DELETE /admin/danger/{id} |
Auth middleware injecting context.user, role check, typed FORBIDDEN |
Each request emits one pretty-printed wide event with:
operation— the full procedure path (e.g.payments.charge,users.get).auth— set by the auth middleware, only on procedures that go throughauthed.error— only onerrorevents:code,status, anddataare captured from theORPCErrorthrown byerrors.<NAME>(...).runtime: 'bun'andpid— added by theenrichcallback configured onwithEvlog().
Events are also drained to PostHog when POSTHOG_API_KEY is set in the root .env.