Now that we're on Workers (#186), we can enable source maps and capture error stacks for readable production debugging.
What
-
Source maps: Add upload_source_maps = true to wrangler.toml and --sourcemap to the build:worker script. Cloudflare auto-translates bundled line numbers to original TypeScript files in Workers Logs.
-
Error stacks: Capture error.stack in two places:
- Middleware catch-all (
_middleware.ts) for unhandled errors
- Route handler catch blocks via
route.fail() properties
- Store in
properties.stack so it's queryable without bloating top-level log fields
Why
Currently errors only log error.message (e.g. "D1 health check failed: SQLITE_ERROR"). With stacks + source maps, you get the full call chain with original file/line numbers, making production debugging much faster.
Scope
- wrangler.toml: add
upload_source_maps = true
- package.json: add
--sourcemap to build:worker
_middleware.ts: add stack to error properties in catch-all
- Route handlers: add
stack to route.fail() properties in catch blocks
- OBSERVABILITY.md: update template to include stack capture pattern
Now that we're on Workers (#186), we can enable source maps and capture error stacks for readable production debugging.
What
Source maps: Add
upload_source_maps = trueto wrangler.toml and--sourcemapto thebuild:workerscript. Cloudflare auto-translates bundled line numbers to original TypeScript files in Workers Logs.Error stacks: Capture
error.stackin two places:_middleware.ts) for unhandled errorsroute.fail()propertiesproperties.stackso it's queryable without bloating top-level log fieldsWhy
Currently errors only log
error.message(e.g. "D1 health check failed: SQLITE_ERROR"). With stacks + source maps, you get the full call chain with original file/line numbers, making production debugging much faster.Scope
upload_source_maps = true--sourcemaptobuild:worker_middleware.ts: addstackto error properties in catch-allstacktoroute.fail()properties in catch blocks