@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
.env
Initialize the SDK
Callinit 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
CallcaptureError in the error handler of your framework. The second argument is optional. It
adds your own fields to the event.
- Express
- Fastify
- Hono
src/app.ts
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 inwithAwsLambda. 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
{ 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
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. Callclose()
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 setrelease, 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
initthrows when you call it a second time, and whenapiKeyorprojectIdisundefined. To run without Squasher in local development, pass an empty string.- After an HTTP 401 response, the SDK logs
Invalid API keyand 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.