feat: add more api logs (#1870)

Adds more detailed API logging using Pino
This commit is contained in:
David Nguyen
2025-06-30 19:46:32 +10:00
committed by GitHub
parent 0cc729e9bd
commit 7487399123
74 changed files with 1395 additions and 544 deletions

View File

@ -1,5 +1,7 @@
import { z } from 'zod';
import { getIpAddress } from './get-ip-address';
const ZIpSchema = z.string().ip();
export const ZRequestMetadataSchema = z.object({
@ -40,11 +42,13 @@ export type ApiRequestMetadata = {
};
export const extractRequestMetadata = (req: Request): RequestMetadata => {
const forwardedFor = req.headers.get('x-forwarded-for');
const ip = forwardedFor
?.split(',')
.map((ip) => ip.trim())
.at(0);
let ip: string | undefined = undefined;
try {
ip = getIpAddress(req);
} catch {
// Do nothing.
}
const parsedIp = ZIpSchema.safeParse(ip);