-
Notifications
You must be signed in to change notification settings - Fork 153
feat(metrics): logMetrics middleware #338
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, really like the rewording & edits on the docs as well.
Left some minor notes/comments.
Co-authored-by: Andrea Amorosi <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning out the inconsistent case style!
const getRandomInt = (): number => Math.floor(Math.random() * 1000000000); | ||
|
||
const awsRequestId = getRandomInt().toString(); | ||
const context = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) Can we extract context object out to reuse and avoid duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored-by: ijemmy <[email protected]>
Co-authored-by: ijemmy <[email protected]>
Co-authored-by: ijemmy <[email protected]>
Co-authored-by: ijemmy <[email protected]>
@@ -227,7 +229,7 @@ describe('Class: Metrics', () => { | |||
test('Cold start metric should only be written out once and flushed automatically', async () => { | |||
const metrics = new Metrics({ namespace: 'test' }); | |||
|
|||
const handler = async (event: any, context: Context) => { | |||
const handler = async (_event: unknown, _context: unknown): Promise<void> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why moving _context
to Unknown type ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting a linting error, and because we should use unknown
instead of any
, whenever needed: https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird that we are getting linting error when (for once :) ) we know which type to expect :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it with a more descriptive type
@@ -361,7 +363,7 @@ describe('Class: Metrics', () => { | |||
expect.assertions(1); | |||
|
|||
const metrics = new Metrics({ namespace: 'test' }); | |||
const handler = async (event: any, context: Context) => { | |||
const handler = async (_event: unknown, _context: unknown): Promise<void> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here: #338 (comment)
Co-authored-by: ijemmy <[email protected]>
Co-authored-by: ijemmy <[email protected]>
Co-authored-by: Florian Chazal <[email protected]>
Co-authored-by: Florian Chazal <[email protected]>
Co-authored-by: ijemmy <[email protected]>
…da-powertools-typescript into feat/metrics-middleware
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks a lot for taking this one!
fe6bad1
Description of your changes
Business logic, tests, documentation and examples added for the
logMetrics
middy middleware.How to verify this change
Docs:
Examples:
See added NPM scripts for examples in the package.json file.
Related issues, RFCs
#25
PR status
Is this ready for review?: YES
Is it a breaking change?: NO
Checklist
Breaking change checklist
N/A
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.