Description
Is this related to an existing feature request or issue?
Which AWS Lambda Powertools utility does this relate to?
Logger
Summary
This RFC is the first of three that will detail how the Logger, Metrics, and Tracer utilities can be extended to support a bring-your-own-observability-provider format for customers who want to use platforms other than AWS CloudWatch.
This RFC will be specifically for the Logger. Currently, in the Logger for Python (and Typescript), customers can bring their own Logging Formatter and have the option to provide a configuration option to define the output format when they're setting up their Logger in order to allow for better integration with observability solutions other than CloudWatch.
Since this is already quite powerful, we are seeking to improve the existing mechanism by offering out of the box support for Datadog and a few other providers (TBD) for the Logger Formatter.
Metrics RFC: #2015
Tracer RFC: #2030
Use case
The primary use case for this utility would be for developers who want a simplified way to integrate the Logger Formatter with the most popular third party observability providers (ie. DataDog).
Proposal
Current Logger Formatter experience
Below is a simple snippet of how the Logger Formatter currently works:
from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter
class CustomFormatter(LambdaPowertoolsFormatter):
def serialize(self, log: dict) -> str:
"""Serialize final structured log dict to JSON str"""
log["event"] = log.pop("message") # rename message key to event
return self.json_serializer(log) # use configured json serializer
logger = Logger(service="payment", logger_formatter=CustomFormatter())logger.info("hello")
logger = Logger(service="payment", logger_formatter=CustomFormatter())
logger.info("hello")
Output
{
"level": "INFO",
"location": "hello_name:8",
"event": "Request from Alice received",
"timestamp": "2023-03-21 13:25:36,129+0100",
"service": "service_undefined"
}
Logger Formatter proposal
For this new utility, we propose a new parameter to the existing logger that developers can use to specify which observability provider they would like to receive their logs. The below code snippet is a rudimentary look at how this utility can be used and how it will function. Out of the box, we will support DataDog and a few other providers (TBD).
from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.providers import DatadogLogFormatter
logger = Logger(service="payment", logger_formatter=DatadogLogFormatter())
logger.info("hello")
Output
{
"datetime": "2021-11-22 15:32:02,145",
"level": "INFO",
"message": "Request from Alice received",
"requestId": "9b1deb4d-3b7d-4bad"
}
Custom logger usage
If the customer would like to use another observability provider, or define their own logger functions, we will define an interface that the customer can implement and pass in to the Logger class.
Out of scope
Sending logs from Powertools to the customer's desired observability platform will not be in the scope of this project. The implementation should only support modifying the output of the Logger so that the customer can push them to their platform of choice using the Lambda Handler.
Potential challenges
We need to determine which platforms we want to support out-of-the-box (apart from Datadog).
Dependencies and Integrations
We will have to integrate with (and thus, have a dependency on) Datadog and any other platforms we decide to support out-of-the-box.
Alternative solutions
Acknowledgment
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript