Chapter 7. Logging, Metrics, and Tracing

In this chapter, we’ll explore how to enhance the observability of Lambda functions through logging, metrics, and tracing. Through logging, you’ll learn how to gain information from specific events occuring during the execution of your Lambda functions. Platform and business metrics will give insight into the operational health of our serverless application. Finally, distributed tracing will let you see how requests flow to the different managed services and components that make up our architecture.

We’ll use the Weather API from Chapter 5 to explore the wide variety of logging, metrics, and tracing options available for serverless applications on AWS. Similar to the data pipeline changes we made in Chapter 6, you’ll notice that the Weather API Lambda functions have been refactored to use the aws-lambda-java-events library.

Logging

Given the following log message, what can we infer about the state of the application that generated it?

Recorded a temperature of 78 F from Brooklyn, NY

We know the values of some of the data (the temperature measurement and location), but not much else. When was this data received or processed? In the larger context of our application, what request generated this data? Which Java class and method produced this log message? How can we correlate this with other, possibly related, log messages?

Fundamentally, this is an unhelpful log message. It lacks context and specificity. If a message like this was repeated ...

Get Programming AWS Lambda now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.