Skip to content

Commit

Permalink
Use render id header as request id if available
Browse files Browse the repository at this point in the history
  • Loading branch information
paustint committed Nov 16, 2024
1 parent fbba49a commit 8cd8bec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/app/routes/route.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AuthenticationError, NotFoundError, UserFacingError } from '../utils/er
import { getApiAddressFromReq } from '../utils/route.utils';

export function addContextMiddleware(req: express.Request, res: express.Response, next: express.NextFunction) {
res.locals.requestId = res.locals.requestId || uuid();
res.locals.requestId = res.locals.requestId || req.get('rndr-id') || uuid();
const clientReqId = req.header(HTTP.HEADERS.X_CLIENT_REQUEST_ID);
if (clientReqId) {
res.setHeader(HTTP.HEADERS.X_CLIENT_REQUEST_ID, clientReqId);
Expand Down
5 changes: 4 additions & 1 deletion libs/api-config/src/lib/api-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const httpLogger = pinoHttp<express.Request, express.Response>({
genReqId: (req, res) => res.locals.requestId || uuid(),
autoLogging: {
// ignore static files based on file extension
ignore: (req) => ignoreLogsFileExtensions.test(req.url) || req.url === '/healthz' || req.url === '/api/heartbeat',
ignore: (req) =>
ignoreLogsFileExtensions.test(req.url) || req.url === '/healthz' || req.url === '/api/heartbeat' || req.url === '/api/analytics',
},
customLogLevel: function (req, res, error) {
if (res.statusCode > 400) {
Expand All @@ -46,6 +47,8 @@ export const httpLogger = pinoHttp<express.Request, express.Response>({
host: req.raw.headers.host,
'user-agent': req.raw.headers['user-agent'],
referer: req.raw.headers.referer,
'cf-ray': req.raw.headers['cf-ray'],
'rndr-id': req.raw.headers['rndr-id'],
'x-sfdc-id': req.raw.headers['x-sfdc-id'],
'x-client-request-id': req.raw.headers['x-client-request-id'],
'x-retry': req.raw.headers['x-retry'],
Expand Down

0 comments on commit 8cd8bec

Please sign in to comment.