request.id

A unique identifier assigned to each request, used for log correlation.

Since Fastify 5 Spec ↗

Syntax

request.id

Returns

string — The request id (incremental or from genReqId).

Examples

import Fastify from 'fastify';
import { randomUUID } from 'node:crypto';

const app = Fastify({
  genReqId: (req) =>
    (req.headers['x-request-id'] as string) ?? randomUUID(),
});

app.get('/', async (req) => ({ requestId: req.id }));

Notes

Every log line from request.log automatically includes reqId. Provide `genReqId` to derive ids from an incoming correlation header for distributed tracing.