Skip to content

feat(Observability): enable source maps and error stack capture #254

Description

@jlian

Now that we're on Workers (#186), we can enable source maps and capture error stacks for readable production debugging.

What

  1. 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.

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions