feat: migrate backend logging from Winston to Pino with correlation IDs (refs #82)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 4m3s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 32s
Deploy to Staging / Verify Staging (pull_request) Successful in 2m29s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 4m3s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 32s
Deploy to Staging / Verify Staging (pull_request) Successful in 2m29s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
- Replace Winston with Pino using API-compatible wrapper - Add LOG_LEVEL env var support with validation and fallback - Add correlation ID middleware (X-Request-Id from Traefik or UUID) - Configure PostgreSQL logging env vars (POSTGRES_LOG_STATEMENT, POSTGRES_LOG_MIN_DURATION) - Configure Redis loglevel via command args Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
/**
|
||||
* @ai-summary Fastify request logging plugin
|
||||
* @ai-context Logs request/response details with timing
|
||||
* @ai-summary Fastify request logging plugin with correlation IDs
|
||||
* @ai-context Logs request/response details with timing and requestId
|
||||
*/
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
import fp from 'fastify-plugin';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { logger } from '../logging/logger';
|
||||
|
||||
const loggingPlugin: FastifyPluginAsync = async (fastify) => {
|
||||
fastify.addHook('onRequest', async (request) => {
|
||||
request.startTime = Date.now();
|
||||
// Extract X-Request-Id from Traefik or generate new UUID
|
||||
request.requestId = (request.headers['x-request-id'] as string) || randomUUID();
|
||||
});
|
||||
|
||||
fastify.addHook('onResponse', async (request, reply) => {
|
||||
const duration = Date.now() - (request.startTime || Date.now());
|
||||
|
||||
|
||||
logger.info('Request processed', {
|
||||
requestId: request.requestId,
|
||||
method: request.method,
|
||||
path: request.url,
|
||||
status: reply.statusCode,
|
||||
@@ -24,13 +28,13 @@ const loggingPlugin: FastifyPluginAsync = async (fastify) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Augment FastifyRequest to include startTime
|
||||
declare module 'fastify' {
|
||||
interface FastifyRequest {
|
||||
startTime?: number;
|
||||
requestId?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export default fp(loggingPlugin, {
|
||||
name: 'logging-plugin'
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user