-
Notifications
You must be signed in to change notification settings - Fork 1
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
logger function #19
logger function #19
Conversation
Hey @osahyoun, thanks for starting this! About the approach, IMO since logging is something we need to figure out, ideally papertrail since we're already using that for our other apps. I think it's easier to use something like Papertrail alerts instead of implementing our own alerts system. I did some research starting on the docs that @eyko shared, and I think a good approach is to have a separate logging lambda triggered by the logs of the core app lambdas and API Gateway. From that logging lambda we can push the logs to whatever system we want. |
members-service/updateMember.js
Outdated
@@ -15,7 +16,7 @@ const logger = new OperationsLogger({ | |||
client: new DocumentClient(), | |||
}); | |||
|
|||
export function handler(event: any, context: any, callback: any) { | |||
const handlerFunc = (event: any, context: any, callback: 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.
I'd also export this for unit testing without the wrapper.
@rodrei where we stream/store our logs is a separate problem. This code is trying to address the problem of what do we actually want to log. Does that make sense? |
What we want to avoid is littering our lambdas with |
@osahyoun You're suggesting to trigger alarms by manually creating an event on an SNS topic. What I'm suggesting is that we solve the logging issue first, and then use Papertrail alarms to trigger alerts from the logs. |
@osahyoun I also thought of going down a similar route: a wrapper function that logged every request (I guess in a format we're familiar with, or even using bunyan). For the wrapper function, however, I'd have written something a bit clearer. function wrapper(handler) {
return function (event, context, callback) {
// log request
console.log(...);
// wrap the callback as well
const cb = (...args) => {
// perhaps log the response, in some cases (APIGWProxy)
console.log(...args);
// call the real callback
callback(...args)
}
return handler(event, context, cb);
}
}; |
Thanks, @eyko. That does look clearer. |
fe7d13c
to
996fa73
Compare
lib/logger.js
Outdated
@@ -0,0 +1,13 @@ | |||
const wrapper = (handler, name) => { | |||
return function(event, context, callback, ...args) { | |||
console.log(`++++++ ${name}: EVENT ++++++`); |
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.
We can get name
from context.functionName
so it might be unnecessary to pass it a name?
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.
@eyko 👍 thanks
@eyko ready for another review |
👍 let's go for it! |
Here's a possible solution to logging the important stuff when functions are invoked. Thoughts?
I'm publishing errors to an SNS topic that'll in turn update us via email and slack.