Node.js SDK
WatchTower15 in Fastify
npm install @watchtower15/sdk @watchtower15/pino fastifyThis recipe is the app in the SDK’s examples/fastify/, which the SDK’s test suite runs on Node 24 against the test fakes.
import Fastify from 'fastify';import { Aggregator, WatchTower15 } from '@watchtower15/sdk';
const metrics = new Aggregator({ client: WatchTower15.fromEnvironment(), allowList: { 'orders.created': 'count' } });
const app = Fastify({ logger: { transport: { targets: [ { target: 'pino/file', options: { destination: 1 } }, { target: '@watchtower15/pino', options: { stream: 'orders-api' } }, ], }, },});
app.addHook('onClose', async () => { await metrics.close();});app.post('/orders', async (_request, reply) => { metrics.increment('orders.created'); return reply.code(201).send({ created: true });});- Logs. Fastify uses pino, so
@watchtower15/pinois a second target beside the one that writes to standard output; it readsWT15_LOGS_TOKENand runs in pino’s worker thread. See Logs. - Metrics. The
onClosehook closes the aggregator, which sends what was counted.