Skip to content

revert(metrics): typing regression on log_metrics callable #744

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
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
20 changes: 8 additions & 12 deletions aws_lambda_powertools/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import json
import logging
import warnings
from typing import Any, Callable, Dict, Optional, Union, cast
from typing import Any, Callable, Dict, Optional, Union

from ..shared.types import AnyCallableT
from .base import MetricManager, MetricUnit
from .metric import single_metric

Expand Down Expand Up @@ -130,7 +129,7 @@ def log_metrics(
capture_cold_start_metric: bool = False,
raise_on_empty_metrics: bool = False,
default_dimensions: Optional[Dict[str, str]] = None,
) -> AnyCallableT:
):
"""Decorator to serialize and publish metrics at the end of a function execution.

Be aware that the log_metrics **does call* the decorated function (e.g. lambda_handler).
Expand Down Expand Up @@ -170,14 +169,11 @@ def handler(event, context):
# Return a partial function with args filled
if lambda_handler is None:
logger.debug("Decorator called with parameters")
return cast(
AnyCallableT,
functools.partial(
self.log_metrics,
capture_cold_start_metric=capture_cold_start_metric,
raise_on_empty_metrics=raise_on_empty_metrics,
default_dimensions=default_dimensions,
),
return functools.partial(
self.log_metrics,
capture_cold_start_metric=capture_cold_start_metric,
raise_on_empty_metrics=raise_on_empty_metrics,
default_dimensions=default_dimensions,
)

@functools.wraps(lambda_handler)
Expand All @@ -198,7 +194,7 @@ def decorate(event, context):

return response

return cast(AnyCallableT, decorate)
return decorate

def __add_cold_start_metric(self, context: Any) -> None:
"""Add cold start metric and function_name dimension
Expand Down