كل حِزم SDK

Fastify

v0.2.1beta

@allstak/fastify

AllStak/allstak-fastify

AllStak SDK for Fastify. Captures inbound requests, errors, server spans, and distributed trace headers with one plugin.

Install

npm install @allstak/fastify fastify

Setup

import Fastify from 'fastify';
import allstakFastify from '@allstak/fastify';

const app = Fastify();

await app.register(allstakFastify, {
  apiKey: process.env.ALLSTAK_API_KEY,
  environment: process.env.NODE_ENV ?? 'production',
  release: process.env.ALLSTAK_RELEASE,
  serviceName: 'checkout-api',
  captureRequestHeaders: true,
});

app.get('/health', async () => ({ ok: true }));
await app.listen({ port: 3000 });

What is captured

Everything below is automatic after register — no per-call code.

  • Request method, path, host, status code, duration, environment, release, and service.
  • Unhandled route errors with stack traces and request correlation.
  • Fatal crashes: process-global uncaughtException and unhandledRejection are captured at fatal level, mark the release-health session crashed, and are flushed before the process exits (Node exit semantics preserved).
  • Database queries: pg, mysql2, and the SQLite family (better-sqlite3 / sqlite3 / node:sqlite) are auto-instrumented when installed — normalized SQL, query type, duration, status, rows affected, and the request's trace/span ids.
  • Logs: Fastify's pino logger is bridged so application and framework logs ship to AllStak (your stdout logs are unchanged). Error/fatal logs are promoted with throwable details; every log carries the request trace/span ids.
  • Breadcrumbs: an http breadcrumb is recorded per inbound request and attached to any error captured during that request.
  • Server spans for each request, plus outbound HTTP client spans.
  • Response propagation headers: traceparent, baggage, allstak-baggage, x-allstak-trace-id, and x-allstak-request-id.

Each feature is default-on and independently toggleable (see Configuration). To record DB queries, install the relevant driver in your app:

npm install pg              # PostgreSQL
npm install mysql2          # MySQL
npm install better-sqlite3  # SQLite

Configuration

OptionDescription
apiKeyProject API key.
dsnAlias for apiKey.
environmentDeployment environment.
releaseApp version or commit SHA.
serviceNameLogical service name.
captureRequestHeadersCapture redacted inbound headers. Default: false.
sampleRateRequest capture sample rate from 0 to 1.
beforeSendOptional hook to modify or drop outbound telemetry.
enableDbInstrumentationAuto-instrument pg / mysql2 / SQLite drivers. Default: true.
enableLogBridgeBridge Fastify's pino logger to AllStak logs. Default: true.
logBridgeMinLevelMinimum log level forwarded. Default: info.
enableAutoBreadcrumbsRecord an http breadcrumb per request. Default: true.
enableCrashHandlersInstall process-global crash handlers. Default: true.
captureOutboundHttpInstrument outbound HTTP egress. Default: true.
enableAutoSessionTrackingOpen a release-health session per process. Default: true.
enableOfflineQueuePersist un-sent telemetry to disk and replay on restart. Default: true on Node.

Privacy

Sensitive header and metadata keys are redacted before telemetry is sent. Add redactKeys for application-specific fields.

Troubleshooting

  • No events: confirm the API key is present and the plugin is registered before routes.
  • Missing request correlation: keep upstream traceparent or x-request-id headers when proxying traffic.
  • Short-lived tests or scripts: wait briefly or call the plugin transport shutdown in your test harness.

Contributing and Support

License

MIT