AWS Lambda console : exploring single pane view of metrics, logs, and traces
Tags: aws, serverless, lambda, observability
Published: 2024-01-02 10:55:04

## Introduction
Recently AWS announced that [AWS Lambda console now features a single pane view of metrics, logs, and traces](https://aws.amazon.com/about-aws/whats-new/2023/11/aws-lambda-console-single-pane-metrics-logs-traces/). Lambda console now features a new simplified design with a single pane view of metrics, logs, and traces, along with universal filters for time range, time zone, and refresh options. Let's explore this new functionallity.

## Exploring single pane view of metrics, logs, and traces in AWS Lambda

For the demonstration purposes we'll use the [sample application](https://github.com/Vadym79/AWSLambdaJavaSnapStart/tree/main/pure-lambda-21-big) with enabled X-Ray tracing on API Gateway and Lambda in [template.yaml](https://github.com/Vadym79/AWSLambdaJavaSnapStart/blob/main/pure-lambda-21-big/template.yaml). For API Gateway the relevant configuration is:

```
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: !Ref Stage
      TracingEnabled: true
      ...
```
and for Lambda it is:

```
  Function:
    CodeUri: target/aws-pure-lambda-snap-start-21-1.0.0-SNAPSHOT.jar
    Runtime: java21
    Timeout: 30 
    MemorySize: 1024
    Tracing: Active
    ....
```
We also need the tracing to the DynamoDB call through adding **execution tracing interceptor** in [DynamoProductDao](https://github.com/Vadym79/AWSLambdaJavaSnapStart/blob/main/pure-lambda-21-big/src/main/java/software/amazonaws/example/product/dao/DynamoProductDao.java).

```
 private static final DynamoDbClient dynamoDbClient = DynamoDbClient.builder()
    .credentialsProvider(DefaultCredentialsProvider.create())
    .region(Region.EU_CENTRAL_1)
    .overrideConfiguration(ClientOverrideConfiguration.builder()
       .addExecutionInterceptor(new TracingInterceptor())
      .build())
    .build();

```
Don't forget to add multiple aws-xray-* dependencies to the 
[pom.xml](https://github.com/Vadym79/AWSLambdaJavaSnapStart/blob/main/pure-lambda-21-big/pom.xml)

Let's produce some invocations of the "GetProductByIdWithPureJava21LambdaBig" Lambda function and then navigate into the "Monitor" tab.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/18h0tucpbjeozy5cf8m1.png).

We'll find the following in this Lambda pane :

CloudWatch metrics like Invocations, Duration, Error Count, Throttles and so on.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/synzj5kly4hq2hm3z5r3.png)


CloudWatch Logs for "Recent invocations" and "Most expensive invocations in GB-seconds" looks like this.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2nnuoa4gekna4m665n0.png)

AWS X-Ray and CloudWatch ServiceLens which contains a "Service Map" with possibility to view and analyze traces and view the dashboard.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf5m4lnhi7tvxbfwklvh.png)

AWS X-Ray and CloudWatch ServiceLens also contains X-Ray traces and the functionality to [filter those traces](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-filters.html).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5x0h7yrk727fxd97hqr.png)

## Conclusion

The single pane indeed eliminates the need to navigate between multiple dashboards and apply filters to each of them separately, reducing the number of clicks required to monitor your Lambda functions. The single pane view also makes it easy to correlate metrics, logs, and traces, reducing the mean time to recovery (MTTR) when troubleshooting errors in your Lambda functions.  Very handy functionallity!

As an improvement I'd like to see Amazon DevOps Guru integration with Lambda single pane. In case that DevOps Guru recognized the anomaly with Lambda function involved time range of the anomaly should be pre-selected automatically. Currently DevOps Guru only shows corresponding CloudWatch metrics and CloudWatch Logs for the anomaly with Lambda involved and misses AWS X-Ray and CloudWatch ServiceLens information. In case you'd like to know more about DevOps Guru I write the [article series](https://dev.to/aws-builders/amazon-devops-guru-for-the-serverless-applications-part-1-introduction-to-devops-guru-39i0) about it. Check it out!