Skip to content

Commit

Permalink
add request id to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
marjisound committed Jan 27, 2025
1 parent e5645bd commit 994d85f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dotcom-rendering/src/server/lib/logging-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ const hasPageId = (body: unknown): body is { pageId: string } => {
* completed.
*/
export const requestLoggerMiddleware: RequestHandler = (req, res, next) => {
const headerValue = req.headers['x-gu-xid'];
const requestId = Array.isArray(headerValue) ? headerValue[0] : headerValue;

const loggerState = {
request: {
pageId: hasPageId(req.body) ? req.body.pageId : 'no-page-id-found',
path: req.path,
method: req.method,
fastlyRequestId: requestId ?? 'fastly-id-not-provided',
},
timing: {},
};
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/server/lib/logging-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DCRLoggingStore = {
method: string;
type?: string;
platform?: string;
fastlyRequestId?: string;
};
error?: {
message?: string;
Expand Down

0 comments on commit 994d85f

Please sign in to comment.