Fastify
One plugin registration. An onRequest hook attaches method, url, request
ID, route, and scrubbed headers to the active context; an onError hook
captures every error Fastify emits. Works with Fastify 4 and 5 on
Node ≥ 20.
AI-assisted setup
Paste the prompt below into Claude Code, Cursor, Copilot, or Codex — your agent will detect your package manager, install both packages, create the observability module, and register the plugin in the right spot.
You are adding the @nreactive/core + @nreactive/fastify SDKs to this Fastify project. nreactive is a production error-monitoring service that opens AI-generated pull requests to fix the errors it catches.
Do the following with the project's existing package manager (detect it from the lockfile: package-lock.json → npm, pnpm-lock.yaml → pnpm, yarn.lock → yarn, bun.lockb → bun):
1. Install the packages @nreactive/core and @nreactive/fastify.
2. Create "src/observability/nreactive.ts" (or ".js" if the project is plain JavaScript) that imports init from @nreactive/core and calls it with { appId: process.env.NREACTIVE_APP_ID, environment: process.env.NODE_ENV, release: process.env.APP_VERSION }. Export nothing — the module is used for its import side effect.
3. In the server entry file, add import "./observability/nreactive"; as the VERY FIRST import — before any other import including "fastify".
4. Register the plugin as early as possible in the Fastify app setup, before any route is registered:
import nreactivePlugin from "@nreactive/fastify";
await app.register(nreactivePlugin);
5. Add NREACTIVE_APP_ID= to .env.example (create it if missing) and document it in the README's environment-variables section. The user obtains their App ID from https://nreactive.com/dashboard/apps.
6. Restart the server and throw a test error from a route (e.g. app.get("/boom", async () => { throw new Error("nreactive test"); })) to confirm events appear in the dashboard.
Do not invent additional configuration. Stop and ask if the project structure doesn't match these assumptions (for example, if the project is not using Fastify).Manual setup
Get your App ID
Sign in and grab your App ID from the Apps page. It looks
like app_ab12cd34ef. Export it as NREACTIVE_APP_ID so the SDK can read
it from process.env.
Install
pnpm add @nreactive/core @nreactive/fastifyOr npm install @nreactive/core @nreactive/fastify / yarn add … / bun add ….
Wire it up
Create src/observability/nreactive.ts:
import { init } from "@nreactive/core";
init({
appId: process.env.NREACTIVE_APP_ID!,
environment: process.env.NODE_ENV,
release: process.env.APP_VERSION,
});Then in your server entry file, import the observability module first and register the plugin before any route:
import "./observability/nreactive";
import Fastify from "fastify";
import nreactivePlugin from "@nreactive/fastify";
const app = Fastify({ logger: true });
await app.register(nreactivePlugin); // register BEFORE routes
app.get("/", async () => ({ hello: "world" }));
await app.listen({ port: 3000 });Attach user info from a preHandler hook so every downstream error is tagged:
import { addContext } from "@nreactive/core";
app.addHook("preHandler", async (req) => {
const user = await resolveUser(req);
if (user) addContext({ user: { id: user.id, email: user.email } });
});Verify
Restart the server and hit a route that throws:
app.get("/boom", async () => {
throw new Error("nreactive test");
});curl http://localhost:3000/boomWithin a few seconds the event shows up on the Errors page of your dashboard with method, URL, route, and request ID attached.