Skip to content

Commit

Permalink
feat: add user-agent to logs (aws-solutions#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzzimmer authored Jun 13, 2022
1 parent d5166ac commit 5e35a26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion source/image-handler/logger/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function getMdc({ event }) {
}

return {
accept: event.headers && (event.headers.accept || event.headers.Accept)
accept: event.headers && (event.headers.accept || event.headers.Accept),
user_agent: event.headers && (event.headers["User-Agent"] || event.headers["user-agent"])
};
}

Expand Down
8 changes: 5 additions & 3 deletions source/image-handler/logger/send.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const TEST_DATA = {
const TEST_API_GATEWAY_EVENT = {
path: "/path/to/image.png",
headers: {
accept: 'imgage/webp'
accept: 'image/webp',
'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
},
eventId: 12345,
};
Expand Down Expand Up @@ -109,12 +110,13 @@ describe("sendMessage", () => {
});
});

it("should log the Cloudwatch event path to the image to be processed", () => {
it("should log headers", () => {
sendMessage({level: "log", args: [], event: TEST_API_GATEWAY_EVENT});

expect(getLastMessage().path).toStrictEqual(TEST_API_GATEWAY_EVENT.path)
expect(getLastMessage().mdc).toStrictEqual({
accept: 'imgage/webp'
accept: 'image/webp',
user_agent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
});
});
});
Expand Down

0 comments on commit 5e35a26

Please sign in to comment.