Module aws_lambda_powertools.logging.types

Expand source code
from __future__ import annotations

from typing import Any, Dict, List, Union

from aws_lambda_powertools.shared.types import NotRequired, TypeAlias, TypedDict

LogRecord: TypeAlias = Union[Dict[str, Any], "PowertoolsLogRecord"]
LogStackTrace: TypeAlias = Union[Dict[str, Any], "PowertoolsStackTrace"]


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]

    # From logger.set_correlation_id
    correlation_id: NotRequired[str]

    # Fields from logger.exception
    exception_name: NotRequired[str]
    exception: NotRequired[str]
    stack_trace: NotRequired[Dict[str, Any]]


class PowertoolsStackTrace(TypedDict):
    type: str
    value: str
    module: str
    frames: List[Dict[str, Any]]

Classes

class PowertoolsLogRecord (*args, **kwargs)

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Expand source code
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]

    # From logger.set_correlation_id
    correlation_id: NotRequired[str]

    # Fields from logger.exception
    exception_name: NotRequired[str]
    exception: NotRequired[str]
    stack_trace: NotRequired[Dict[str, Any]]

Ancestors

  • builtins.dict

Class variables

var cold_start : bool
var correlation_id : str
var exception : str
var exception_name : str
var function_arn : str
var function_memory_size : int
var function_name : str
var function_request_id : str
var level : str
var location : str
var message : Union[Dict[str, Any], str, bool, List[Any]]
var sampling_rate : float
var service : str
var stack_trace : Dict[str, Any]
var timestamp : str | int
var xray_trace_id : str
class PowertoolsStackTrace (*args, **kwargs)

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Expand source code
class PowertoolsStackTrace(TypedDict):
    type: str
    value: str
    module: str
    frames: List[Dict[str, Any]]

Ancestors

  • builtins.dict

Class variables

var frames : List[Dict[str, Any]]
var module : str
var type : str
var value : str