Skip to content

refactor(tracer): make capture_lambda_handler type more generic #4796

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
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws_lambda_powertools/shared/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from typing_extensions import TypeAlias, get_args, get_origin

AnyCallableT = TypeVar("AnyCallableT", bound=Callable[..., Any]) # noqa: VNE001


# JSON primitives only, mypy doesn't support recursive tho
JSONType = Union[str, int, float, bool, None, Dict[str, Any], List[Any]]

Expand Down
6 changes: 4 additions & 2 deletions aws_lambda_powertools/tracing/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import numbers
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Union, cast, overload
from typing import Any, Callable, Dict, List, Optional, Sequence, TypeVar, Union, cast, overload

from aws_lambda_powertools.shared import constants
from aws_lambda_powertools.shared.functions import (
Expand All @@ -22,6 +22,8 @@

aws_xray_sdk = LazyLoader(constants.XRAY_SDK_MODULE, globals(), constants.XRAY_SDK_MODULE)

T = TypeVar("T")


class Tracer:
"""Tracer using AWS-XRay to provide decorators with known defaults for Lambda functions
Expand Down Expand Up @@ -250,7 +252,7 @@ def patch(self, modules: Optional[Sequence[str]] = None):

def capture_lambda_handler(
self,
lambda_handler: Union[Callable[[Dict, Any], Any], Optional[Callable[[Dict, Any, Optional[Dict]], Any]]] = None,
lambda_handler: Optional[Union[Callable[[T, Any], Any], Callable[[T, Any, Any], Any]]] = None,
capture_response: Optional[bool] = None,
capture_error: Optional[bool] = None,
):
Expand Down