feat(metrics): logMetrics middleware - #338
Conversation
dreamorosi
left a comment
There was a problem hiding this comment.
Great job, really like the rewording & edits on the docs as well.
Left some minor notes/comments.
Co-authored-by: Andrea Amorosi <dreamorosi@gmail.com>
ijemmy
left a comment
There was a problem hiding this comment.
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.
(minor) Can we extract context object out to reuse and avoid duplication?
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
| 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.
Why moving _context to Unknown type ?
There was a problem hiding this comment.
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.
weird that we are getting linting error when (for once :) ) we know which type to expect :/
There was a problem hiding this comment.
I fixed it with a more descriptive type
|
|
||
| const metrics = new Metrics({ namespace: 'test' }); | ||
| const handler = async (event: any, context: Context) => { | ||
| const handler = async (_event: unknown, _context: unknown): Promise<void> => { |
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: Florian Chazal <florianchazal@gmail.com>
Co-authored-by: Florian Chazal <florianchazal@gmail.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
…da-powertools-typescript into feat/metrics-middleware
dreamorosi
left a comment
There was a problem hiding this comment.
LGTM, thanks a lot for taking this one!
fe6bad1
Description of your changes
Business logic, tests, documentation and examples added for the
logMetricsmiddy 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.