Repository navigation
Reporting errors from a Worker without delaying the response (ctx.waitUntil) #16669
virajrakholiya
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
A pattern that took me a while to get right in Workers: sending telemetry for a request without making the user wait for it.
The naive version awaits a
fetchto your logging endpoint before returning, which adds a full round trip to every response.ctx.waitUntilkeeps the isolate alive for a promise after the response has gone out:Two gotchas I hit:
envargument, so passenvdown instead of reading globals.I'm building Relia, and its edge wrapper follows this pattern.
export default { fetch: withRelia(handler) }records each request (path, status, duration, and an uncaught error with its stack), each outgoingfetchas a child call, and model calls (OpenAI, Anthropic, Gemini and others) as one AI run. It readsRELIA_PROJECT_IDandRELIA_KEYfromenvand sends after the response throughctx.waitUntil. Relia then explains in plain words what broke and suggests a fix; it never touches your code. Free plan; demo: https://app.tryrelia.com/demo?utm_source=github&utm_campaign=lead-agentHow do you handle error reporting in Workers today: Tail Workers, Logpush, or something inside the handler?
All reactions