Skip to main content
Use @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

The SDK needs the nodejs_compat compatibility flag, for AsyncLocalStorage:
wrangler.jsonc
Save your ingest key and project ID as Worker secrets. To get both values, see Create an ingest key.
For wrangler dev, put the same two values in .dev.vars.

Wrap the Worker

Pass withSquasher a function that reads the configuration from env, and your handlers.
src/index.ts
For each invocation, the wrapper makes a new client. When the handler throws, it sends an error event and throws the error again. Squasher names the issue after the handler, for example 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, call captureError. It uses the client of the current invocation.
src/index.ts
The issue gets the error message as its title. setUser, setTag, and captureMessage also work inside a wrapped handler.

Add spans, logs, and metrics

src/index.ts
Spans that start inside another span become its children. Logs and metrics get the trace ID of the active span. 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, run npx wrangler dev, and open /squasher-test once:
src/index.ts
Then select Issues in the sidebar of your project. The issue is named 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.