Skip to main content
Use @squasher-ai/node in Node.js services, queue workers, scripts, and AWS Lambda functions. This page is tested with version 0.5.0 on Node.js 26.

What the SDK captures

Install the SDK

The package is ESM only. Add your ingest key and project ID to the environment of your service:
.env
To get both values, see Create an ingest key.

Initialize the SDK

Call init once, when the process starts, before the rest of your app code runs.
src/index.ts
installGlobalHandlers() captures uncaught exceptions and unhandled promise rejections. After an uncaught exception, it sends the error, waits up to 5 seconds, and ends the process with exit code 1. resourceAttributes is optional. Set service.name when one project gets data from more than one service. Set environment to production in production: automatic AI triage runs only on issues from that environment.

Capture framework errors

Call captureError in the error handler of your framework. The second argument is optional. It adds your own fields to the event.
src/app.ts
To add context to every later event, call setUser({ id: "user_42" }) or setTag("region", "us-east-1"). The SDK sends the user ID and the tags with each event.

Wrap AWS Lambda handlers

Wrap the handler in withAwsLambda. When the handler throws, the wrapper sends the error with the request ID and function name, then throws it again. After each invocation, it waits for the SDK to send queued events.
src/handler.ts
The wrapper waits at most 1 second, and it stops 100 ms before the Lambda time limit. To change these limits, pass a third argument: { flushTimeoutMs: 500, remainingTimeReserveMs: 150 }. The wrapper needs no Lambda layer or extension.

Send a test error

Run this script once with the same environment variables:
scripts/squasher-test.ts
The SDK sends events in batches, every 5 seconds or when 25 events are queued. flush() sends them now, so a short script does not exit first. Then select Issues in the sidebar of your project. The test error is at the top of the list. If it does not appear, see Troubleshooting.

Send queued events at shutdown

A long-running service can lose the events that are still in the queue when it stops. Call close() when the process gets a stop signal. It sends the queued events, waiting up to 5 seconds.
src/index.ts

Options

sampling treats events at warning level and above as errors, so errorRate applies to them. Events are never sampled out when their user ID is in alwaysSampleUserIds or their release is in alwaysSampleReleases.

Releases

When you do not set release, the SDK reads the first valid value from these environment variables: SQUASHER_RELEASE, VERCEL_GIT_COMMIT_SHA, RAILWAY_GIT_COMMIT_SHA, RENDER_GIT_COMMIT, FLY_MACHINE_VERSION, GITHUB_SHA, then npm_package_name and npm_package_version.

Limits

  • init throws when you call it a second time, and when apiKey or projectId is undefined. To run without Squasher in local development, pass an empty string.
  • After an HTTP 401 response, the SDK logs Invalid API key and stops sending events until the process restarts.
  • After an HTTP 429 response, the SDK waits once, up to 8 seconds, and then drops the batch.
  • The SDK sends breadcrumbs, but Squasher does not store them.
  • Stack traces point at the files that Node.js runs. If you bundle your code, 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

Pino transport

Send Pino logs to the same project.

Winston transport

Send Winston logs to the same project.

Upload source maps

Store source maps for each release.

Read AI triage

Learn what the triage summary tells you.