Trasys
Node.js SDKFrameworks

Fastify

Register the Trasys SDK's Fastify plugin before your routes to automatically capture every inbound request as a span using sdk.fastifyplugin() at startup.

Fastify

// index.js
require('dotenv').config();
const { sdk } = require('./trasys'); // SDK must be required first

const Fastify = require('fastify');
const app = Fastify({ logger: false });

// Register as a Fastify plugin — before your routes
await app.register(sdk.fastifyplugin());

app.get('/users/:id', async (request, reply) => {
  return db.findUser(request.params.id);
});

await app.listen({ port: 3000, host: '0.0.0.0' });

TypeScript

// index.ts
import 'dotenv/config';
import { sdk } from './trasys';

import Fastify from 'fastify';

const app = Fastify({ logger: false });

await app.register(sdk.fastifyplugin());

app.get<{ Params: { id: string } }>('/users/:id', async (request, reply) => {
  return db.findUser(request.params.id);
});

await app.listen({ port: 3000, host: '0.0.0.0' });

If you use a custom type provider (e.g. TypeBoxTypeProvider), cast the return value: sdk.fastifyplugin() as FastifyPluginAsync

Plugin scope

The plugin uses fastify-plugin internally, which means it decorates the root Fastify instance rather than a scoped child. Every route — regardless of prefix or plugin scope — is automatically instrumented.

Fastify v4 and v5

Both Fastify v4 and v5 are supported. No configuration changes are needed between versions.

Next steps

On this page