Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/do 1563 prerender logging improvement #1171

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/prerender-fargate/lib/prerender/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ const server = prerender({

server.use({
requestReceived: (req, res, next) => {
console.log(`${new Date().toISOString()} User-Agent: "${req.get('user-agent')}" ${req.prerender.reqId} ${req.prerender.url}`);
// Log "x-prerender-user-agent" value forwarded from CloudFront/Lambda@edge that contains the original User-Agent value. If not present, e.g. requests from ELB, default to "user-agent" value.
const userAgent = req.get('x-prerender-user-agent') || req.get('user-agent');

console.log(`${new Date().toISOString()} User-Agent: "${userAgent}" ${req.prerender.reqId} ${req.prerender.url}`);
let auth = req.headers['x-prerender-token'];
if (!auth) {
console.log(`${new Date().toISOString()} "${req.get('user-agent')}" ${req.prerender.reqId} Authentication header not found.`);
console.log(`${new Date().toISOString()} "${userAgent}" ${req.prerender.reqId} Authentication header not found.`);
return res.send(401);
}

Expand All @@ -40,7 +43,7 @@ server.use({
if (authenticated) break;
}
if (!authenticated) {
console.log(`${new Date().toISOString()} "${req.get('user-agent')}" ${req.prerender.reqId} Authentication Failed.`);
console.log(`${new Date().toISOString()} "${userAgent}" ${req.prerender.reqId} Authentication Failed.`);
return res.send(401);
}

Expand Down
8 changes: 8 additions & 0 deletions packages/prerender-proxy/lib/handlers/prerender-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export const handler = async (
request.headers["x-prerender-host"] = [
{ key: "X-Prerender-Host", value: request.headers.host[0].value },
];

// Custom header to be forwarded to Prerender service for better logging
request.headers["x-prerender-user-agent"] = [
{
key: "x-prerender-user-agent",
value: request.headers["user-agent"][0].value,
},
];
}
}

Expand Down
Loading