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

logger function #19

Merged
merged 5 commits into from
Jan 17, 2018
Merged

logger function #19

merged 5 commits into from
Jan 17, 2018

Conversation

osahyoun
Copy link
Member

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.

@osahyoun osahyoun added the wip label Jan 15, 2018
@rodrei
Copy link
Contributor

rodrei commented Jan 15, 2018

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.

@@ -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) => {
Copy link
Contributor

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.

@osahyoun
Copy link
Member Author

@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?

@osahyoun
Copy link
Member Author

osahyoun commented Jan 15, 2018

What we want to avoid is littering our lambdas with console.log statements.

@rodrei
Copy link
Contributor

rodrei commented Jan 15, 2018

@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.

@vincemtnz
Copy link
Contributor

vincemtnz commented Jan 16, 2018

@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);
  }
};

@osahyoun
Copy link
Member Author

Thanks, @eyko. That does look clearer.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 81.34% when pulling 996fa73 on feature.logging into 22d6872 on development.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 81.34% when pulling 996fa73 on feature.logging into 22d6872 on development.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 81.384% when pulling 9bc4c29 on feature.logging into 22d6872 on development.

lib/logger.js Outdated
@@ -0,0 +1,13 @@
const wrapper = (handler, name) => {
return function(event, context, callback, ...args) {
console.log(`++++++ ${name}: EVENT ++++++`);
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eyko 👍 thanks

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 81.585% when pulling c0c1968 on feature.logging into 22d6872 on development.

@osahyoun osahyoun removed the wip label Jan 17, 2018
@osahyoun osahyoun changed the title SKETCH: logger function logger function Jan 17, 2018
@osahyoun
Copy link
Member Author

@eyko ready for another review

@vincemtnz
Copy link
Contributor

vincemtnz commented Jan 17, 2018

👍 let's go for it!

@osahyoun osahyoun merged commit 441acb7 into development Jan 17, 2018
@osahyoun osahyoun deleted the feature.logging branch January 17, 2018 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants