errorcoredocsbeta
Framework guides

Fastify

npm install errorcore

Initialize Errorcore before registering routes and plugins where possible.

import Fastify from "fastify";
import { captureError, fastifyPlugin, flush, init } from "errorcore";

init({
  service: process.env.ERRORCORE_SERVICE_NAME,
  deploymentEnv: process.env.ERRORCORE_ENVIRONMENT,
  transport: {
    type: "http",
    url: process.env.ERRORCORE_INGEST_URL ?? "https://api-production-7ecf.up.railway.app/v1/ingest",
    apiKey: process.env.ERRORCORE_API_KEY,
  },
  encryptionKey: process.env.ERRORCORE_DEK,
});

const fastify = Fastify();
await fastify.register(fastifyPlugin);

fastify.get("/errorcore-test", async (_request, reply) => {
  captureError(new Error("errorcore test error"));
  await flush();
  return reply.code(202).send({ sent: true });
});

fastifyPlugin attaches request context. Call captureError(error) from the service's existing setErrorHandler callback for handled application failures.

On this page