Skip to content
Draft
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
11 changes: 8 additions & 3 deletions aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,18 @@ def handler(event, context):

@functools.wraps(lambda_handler)
def decorate(event, context, *args, **kwargs):
lambda_context = build_lambda_context_model(context)
unwrapped_context = (
build_lambda_context_model(context.lambda_context)
if hasattr(context, "step")
else build_lambda_context_model(context)
)

cold_start = _is_cold_start()

if clear_state:
self.structure_logs(cold_start=cold_start, **lambda_context.__dict__)
self.structure_logs(cold_start=cold_start, **unwrapped_context.__dict__)
else:
self.append_keys(cold_start=cold_start, **lambda_context.__dict__)
self.append_keys(cold_start=cold_start, **unwrapped_context.__dict__)

if correlation_id_path:
self.set_correlation_id(
Expand Down
5 changes: 3 additions & 2 deletions aws_lambda_powertools/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,13 @@ def handler(event, context):

@functools.wraps(lambda_handler)
def decorate(event, context, *args, **kwargs):
unwrapped_context = context.lambda_context if hasattr(context, "step") else context
try:
if default_dimensions:
self.set_default_dimensions(**default_dimensions)
response = lambda_handler(event, context, *args, **kwargs)
response = lambda_handler(event, unwrapped_context, *args, **kwargs)
if capture_cold_start_metric:
self._add_cold_start_metric(context=context)
self._add_cold_start_metric(context=unwrapped_context)
finally:
self.flush_metrics(raise_on_empty_metrics=raise_on_empty_metrics)

Expand Down
3 changes: 2 additions & 1 deletion aws_lambda_powertools/metrics/provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ def decorate(event, context, *args, **kwargs):
try:
response = lambda_handler(event, context, *args, **kwargs)
if capture_cold_start_metric:
self._add_cold_start_metric(context=context)
unwrapped_context = context.lambda_context if hasattr(context, "step") else context
self._add_cold_start_metric(context=unwrapped_context)
finally:
self.flush_metrics(raise_on_empty_metrics=raise_on_empty_metrics)

Expand Down