File size: 755 Bytes
02f90dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Content-free ingress evidence, before authentication/body parsing. No headers or bodies logged.
export function requestEvidence(logger) {
    return (req, res, next) => {
        const id = req.headers['x-correlation-id'];
        if (typeof id === 'string' && /^[a-f0-9]{32}$/.test(id)) {
            const started = Date.now();
            res.setHeader('X-Proxy-Correlation-ID', id);
            logger.info(JSON.stringify({event: 'inference.proxy.received', correlation_id: id}));
            res.on('finish', () => logger.info(JSON.stringify({
                event: 'inference.proxy.finished', correlation_id: id,
                http_status: res.statusCode, duration_ms: Date.now() - started
            })));
        }
        next();
    };
}