-
Notifications
You must be signed in to change notification settings - Fork 429
feat(logger): type log record in LambdaPowertoolsFormatter with TypedDict #2419
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
Merged
heitorlessa
merged 19 commits into
aws-powertools:develop
from
erikayao93:logger-typing
Jun 14, 2023
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c09e297
Added types.py for new TypedLog class
erikayao93 652ee8a
Added additional typing options for TypedLog keys, updated bring_your…
erikayao93 9289c4b
Added missing space to satisfy linter
erikayao93 320a728
Merge branch 'develop' into logger-typing
heitorlessa c0ea2fc
Merge branch 'develop' into logger-typing
leandrodamascena d49f22b
Edited types.py for improved TypedDict syntax, reverted changes to ex…
erikayao93 7da4a2c
Attempted changes to formatters to accomodate TypedDict typing
erikayao93 ffb8243
Update pre-commit for cloud desktop environment
erikayao93 85ff2a1
Update pre-commit attempt
erikayao93 39656fc
Updated import logic for TypedDict
erikayao93 80fcae3
chore: break import into two branches to ease reading
heitorlessa 1a3d33e
chore: introduce LogRecord type alias for PowertoolsLogRecord and Dict
heitorlessa 77c08c4
fix: ignore typeddict specific checks and explain why
heitorlessa e95b4a3
Merge branch 'develop' into logger-typing
heitorlessa 2b504ed
chore: move to pipe union annotation; fqdn imports
heitorlessa b1e6a17
chore: fix docs highlighting
heitorlessa 26dc9bf
chore: use immutable version for markdownlint-cli
heitorlessa 318255e
chore: use immutable version for actionlint
heitorlessa 70e9c2a
chore: use immutable version for pre-commit-hooks
heitorlessa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
|
||
if sys.version_info >= (3, 11): | ||
from typing import NotRequired | ||
else: | ||
from typing_extensions import NotRequired | ||
|
||
if sys.version_info >= (3, 8): | ||
from typing import TypedDict | ||
else: | ||
from typing_extensions import TypedDict | ||
|
||
if sys.version_info >= (3, 10): | ||
from typing import TypeAlias | ||
else: | ||
from typing_extensions import TypeAlias | ||
|
||
from typing import Any, Dict, List, Union | ||
|
||
LogRecord: TypeAlias = Union[Dict[str, Any], "PowertoolsLogRecord"] | ||
|
||
|
||
class PowertoolsLogRecord(TypedDict): | ||
# Base fields (required) | ||
level: str | ||
location: str | ||
message: Dict[str, Any] | str | bool | List[Any] | ||
timestamp: str | int | ||
service: str | ||
|
||
# Fields from logger.inject_lambda_context | ||
cold_start: NotRequired[bool] | ||
function_name: NotRequired[str] | ||
function_memory_size: NotRequired[int] | ||
function_arn: NotRequired[str] | ||
function_request_id: NotRequired[str] | ||
# From logger.inject_lambda_context if AWS X-Ray is enabled | ||
xray_trace_id: NotRequired[str] | ||
|
||
# If sample_rate is defined | ||
sampling_rate: NotRequired[float] | ||
erikayao93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# From logger.set_correlation_id | ||
correlation_id: NotRequired[str] | ||
|
||
# Fields from logger.exception | ||
exception_name: NotRequired[str] | ||
exception: NotRequired[str] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.