@squasher-ai/edge in Cloudflare Workers. It wraps your fetch, queue, and scheduled
handlers, and it sends the events of each invocation after the response. This page is tested with
version 0.4.0.
What the SDK captures
Install the SDK
nodejs_compat compatibility flag, for AsyncLocalStorage:
wrangler.jsonc
wrangler dev, put the same two values in .dev.vars.
Wrap the Worker
PasswithSquasher a function that reads the configuration from env, and your handlers.
src/index.ts
edge GET /checkout or edge queue orders, and keeps the error message and the stack trace on the
event. Numbers and UUIDs in the path become :id.
Set environment to production in production: automatic AI triage runs
only on issues from that environment. When you do not set service.name, the SDK uses
edge-worker.
Capture errors that you catch
Inside a wrapped handler, callcaptureError. It uses the client of the current invocation.
src/index.ts
setUser, setTag, and captureMessage also work
inside a wrapped handler.
Add spans, logs, and metrics
src/index.ts
log.error accepts an Error, and then it also sends the stack trace.
When a fetch request has a valid W3C traceparent header, the invocation joins that trace: it
uses the caller’s trace ID and becomes a child of the caller’s span. A missing, malformed, or
all-zero header starts a new trace. To continue the trace in a Worker you call, set the header from
the active span:
Use the SDK in Durable Objects
withSquasher covers only the Worker handlers. In a Durable Object method or alarm, run the code
inside runWithSquasher, and put the work in a span. When the function throws, span sends an
error event with the error message and throws the error again. runWithSquasher sends the events
when the function ends.
src/counter.ts
Send a test error
Add a route that throws, runnpx wrangler dev, and open /squasher-test once:
src/index.ts
edge GET /squasher-test.
If it does not appear, see Troubleshooting.
Options
Each invocation sends at least one event. To store fewer events for successful invocations, set
sampling: { successRate: 0.1 }. Errors are kept at the default errorRate of 1.
Limits
- The SDK keeps at most 30 events for each invocation. It drops the events after the 30th.
- The SDK retries a failed send at most 2 times.
- Cloudflare Workers advance the clock only after I/O, so a span of CPU-only work shows 0 ms.
- The SDK sends breadcrumbs, but Squasher does not store them.
- If you bundle your Worker, stack traces point at the bundle. Upload source maps for the release so the issue page shows the original files.
Give the setup to a coding agent
Copy this prompt into your coding agent to install the SDK the same way:Next steps
Cloudflare Logpush
Send Worker logs to the same project without code.
Pino transport
Use the same spans, logs, and metrics in Node.js.
Read AI triage
Learn what the triage summary tells you.
Troubleshooting
Find out why an event does not appear.