No-code AWS Lambda Monitoring
Tags: serverless, node, python, aws
Published: 2021-05-25 21:11:19

Auto-instrumenting AWS [Lambda Monitoring](https://sentry.io/for/serverless/) didn’t originate through a focus group or business plan. It started as a hackathon project that addressed the tedium of removing manual code instrumentation. Developer environments often include hundreds of AWS Lambda functions. And our existing instrumentation required initialization code to be manually placed on every single function. So to fix this, our growth team used Amazon CloudWatch to build a prototype that could instrument AWS Lambda functions.

This prototype began by using AWS CloudFormation stack to automatically create resources in a customer environment. Then we streamed Amazon CloudWatch Logs to Sentry through the Amazon Kinesis Data Firehose. This made it so all you had to do was put in your AWS account ID and create the stack using a pre-configured AWS CloudFormation stack.

But in order to get this production-ready, we had to take a closer look at a few things:

-   Since we just picked a mocked-up stack trace for our demo, the streamed logs were not grouped into issues — or even formatted to pull out stack traces.
-   While the Amazon CloudWatch logs could display stack traces, they didn’t even come close to Sentry’s representation of stack traces, as they had a different use case (though that’s a conversation for another day).
-   Through this automated instrumentation, it wasn’t possible to choose or create a project for your AWS Lambda functions, as we had hard-coded these values for the hackathon.

Ultimately, this meant that we would not use logs to productize no-code AWS Lambda monitoring, as logs would limit our tracing capabilities. Instead, we used [AWS Lambda Extensions](https://aws.amazon.com/blogs/compute/introducing-aws-lambda-extensions-in-preview/), which tied Sentry’s [AWS Lambda Layers](https://docs.aws.amazon.com/lambda/latest/dg/invocation-layers.html) — along with environment variables and code wrapping — to instrument AWS Lambda functions. Doing so ensured that:

-   We were a part of the runtime environments that captured issues/performance and reported them in real-time.
-   We could connect developers to formatted stack traces along with in-context environment variables and breadcrumbs.
-   Developers were able to make changes to Sentry’s instrumentation rather than creating in a black box.
-   Developers could control the sample rate for the function traces, as well as activation/deactivation of Sentry directly from the UI.

Using the AWS Lambda Layers approach and skipping the Amazon CloudWatch had two minor — but manageable — downsides:

-   We needed a specific SDK AWS Lambda Layer for every programming language. We launched with support for Node and Python.
-   We’d miss out on some metrics like memory usage and timeout issues since they are reported after an AWS Lambda function has finished executing.

## Outcome

Instrumenting Sentry on your AWS Lambda functions is now as easy as following a following few simple, UI-specific  [steps](https://docs.sentry.io/product/integrations/aws-lambda/):

### 1. Select Project
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78mqjhnz5squq2pyzl7i.png)

### 2. Add CloudFormation Stack
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4tmls9kvb2k2dti4hng.png)

### 3. Select Functions to Instrument
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/necwogqa9f00f8jqma6b.png)

And that's it! You can even toggle function instrumentation on the fly from the AWS integration management page.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdrask0tbblbbpvvo2id.png)

Ok, so why should you care? Well, developers seem to appreciate the value in auto-instrumentation — more than a third of our instrumentations for AWS Lambda monitoring are now coming through auto-instrumentation. The folks at AWS thought it wasn’t bad either. They helped us become an [AWS Partner](https://partners.amazonaws.com/partners/0010L00001sCEb6QAG/Sentry) and gave us a [AWS Lambda Ready](https://aws.amazon.com/partners/programs/service-ready/) Designation.

You can learn more about Sentry’s support for Serverless Monitoring [here](https://docs.sentry.io/product/integrations/#cloud-monitoring).