-
Notifications
You must be signed in to change notification settings - Fork 421
feat(logger): add DatadogLogFormatter and observability provider #2183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
35a3195
97965da
e3b4e5a
ad667d5
dd58bb5
3b2fc9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Built-in Logger formatters for Observability Providers that require custom config.""" | ||
|
||
# NOTE: we don't expose formatters directly (barrel import) | ||
# as we cannot know if they'll need additional dependencies in the future | ||
# so we isolate to avoid a performance hit and workarounds like lazy imports |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
from __future__ import annotations | ||||||
|
||||||
from typing import Any, Callable | ||||||
|
||||||
from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter | ||||||
|
||||||
|
||||||
class DatadogLogFormatter(LambdaPowertoolsFormatter): | ||||||
def __init__( | ||||||
self, | ||||||
json_serializer: Callable[[dict], str] | None = None, | ||||||
json_deserializer: Callable[[dict | str | bool | int | float], str] | None = None, | ||||||
json_default: Callable[[Any], Any] | None = None, | ||||||
datefmt: str | None = None, | ||||||
use_datetime_directive: bool = False, | ||||||
log_record_order: list[str] | None = None, | ||||||
utc: bool = False, | ||||||
use_rfc3339: bool = True, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not change required, just a question: the only difference between this constructor and the base LambdaPowertoolsFormatter is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would there be any downsides to making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or something similar :) it helps future readers to spot the difference |
||||||
**kwargs, | ||||||
): | ||||||
super().__init__( | ||||||
json_serializer, | ||||||
json_deserializer, | ||||||
json_default, | ||||||
datefmt, | ||||||
use_datetime_directive, | ||||||
log_record_order, | ||||||
utc, | ||||||
use_rfc3339, | ||||||
**kwargs, | ||||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from aws_lambda_powertools import Logger | ||
from aws_lambda_powertools.logging.formatters.datadog import DatadogLogFormatter | ||
|
||
logger = Logger(service="payment", logger_formatter=DatadogLogFormatter()) | ||
logger.info("hello") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some docstring explaining why this exist and what the small difference is to the base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're the best! Doing that now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Added a specific list so we can easily append if future changes are required - lemme know if that addresses it.