Skip to main content
Use @squasher-ai/node for Express, Fastify, Hono, Bun, workers, and plain scripts.

Install

Initialize early

Call init() before you import code that might throw.
src/index.ts
For long-running services, install process-level handlers and close the client during shutdown:
The SDK batches buffered events and automatically splits multi-event request bodies at 1 MB. The configured event-count and flush-interval thresholds still determine when a flush starts; the byte limit only keeps a single outbound request bounded.

Use a standalone client

init() sets the optional process-wide client used by the package-level helpers. Use SquasherClient directly when you need explicit ownership, isolated tests, or more than one client in the same process:
Methods on SquasherClient do not use the process-wide client. Package-level helpers such as captureError() and close() continue to use the client created by init(). flush() and close() wait for queued events and any active batch request that the batch-size threshold started.

Check local delivery health

Read getDeliveryStats() when a health endpoint, shutdown check, or local debug tool needs to know whether the SDK can deliver events:
The immutable snapshot stays in the current process. Reading it does not send a diagnostic event, so delivery failures cannot create a recursive telemetry loop. Counters start at zero when the client starts and are not stored across process restarts. Attempted counts cover initial batches; retried counts cover later delivery attempts for those batches.

Wrap request handlers

Use withHttpRequest to emit one correlated completion event for successful and failed requests:

Wrap AWS Lambda handlers

Use withAwsLambda to capture handler failures and flush queued events before the invocation ends:
src/handler.ts
The wrapper uses the Lambda context to limit its flush time. By default, it waits for at most one second and keeps 100 ms for the Lambda runtime. It has no AWS SDK, Lambda layer, extension, or collector dependency. It uses the normal Squasher ingestion request and does not provision a separate service. The flush runs inside the invocation and can add up to the configured wait time. Use shorter limits when the function has a strict response budget:

Capture framework errors

Manual capture

Actionable error context

Squasher AI triage works best when errors include a short explanation and a next step. For Node services, send that context as structured attributes on telemetry events: Keep these values safe to store with remote project telemetry. Put private implementation notes in your own development workflow rather than public-facing docs or customer-visible messages. Supported release line: @squasher-ai/node 0.4.x and the companion JavaScript SDKs at 0.3.x. Do not install earlier 0.x artifacts. For reusable application errors, create the context once and let captureError merge it into the event:
internal is hidden from the error’s normal JSON representation, but it is still sent to Squasher as event extra. Only include values that are safe for retained project telemetry.

Local debug artifacts

Enable localEventSink when you want a coding agent or local debug script to inspect the exact events the SDK prepared after beforeSend.
The sink writes redacted NDJSON files named YYYY-MM-DD.jsonl. Treat them as temporary debugging output for agents and humans. They complement Squasher’s remote observability, but they are not the production source of truth and should not be used for alerting, retention, or incident history.

Agent handoff