Webinar: Continuous Code Improvement Series | How to Improve with AI-Assisted Workflows Register Here Today!
February 7th, 2017 • By Elliott Spira
Our friends at GorillaStack wanted to share how they set up Rollbar with the Serverless framework, and made a handy tool so you can do the same.
Here at GorillaStack, we are big lovers of the Serverless framework. By default, the Serverless framework uses CloudWatch logs to store any system log messages and output from your lambda code. Pretty quickly, we found ourselves needing to escalate log messages such that we could be notified of application errors and act on them more proactively.
Enter Rollbar. I have been using their service on many side projects since discovering their free tier some years ago. We also robbed them of almost all their swag at the last re:Invent conference. Rollbar is a great system to use for escalating errors and messages from your applications. Best of all, there are options for adding it as a transport for popular logging solutions. As users of the node module 'winston', we found a transport available for Rollbar. Unfortunately, it wasn’t quite up to date, and didn’t format certain argument orders correctly, so we forked it ourselves. :)
Using this integration with your application logging library, messages of all levels will still be logged to CloudWatch logs, but those at or above a configured log level will be escalated to Rollbar, which will then notify you of application errors as they occur.
As we usually do, we decided to publish an open source example to demonstrate our approach. To get started, the only thing you will need is a Rollbar API token. Simply export this into your environment before deploying our example repository to see it in action.
export ROLLBAR_SERVER_ACCESS_TOKEN= <_access_token_here_> git clone email@example.com:GorillaStack/serverless-rollbar-example.git npm install sls deploy sls invoke -f happyEndpoint sls invoke -f unhappyEndpoint
You will receive an email after invoking the
unhappyEndpoint with a summary of the
error log message. If you check your CloudWatch logs, you will see log messages of all levels.
This is a simple example of how to very simply level up your lambda logging using Rollbar. Have you achieved this in a simpler way? Let us know in the comments.
If you haven’t already, sign up for a 14-day free trial of Rollbar and let us help you take control of your application errors.