Skip to content

Commit e854efe

Browse files
committed
improv: support kwargs
1 parent 1e87b8a commit e854efe

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

aws_lambda_powertools/tracing/tracer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def handler(event, context):
269269
lambda_handler_name = lambda_handler.__name__
270270

271271
@functools.wraps(lambda_handler)
272-
def decorate(event, context):
272+
def decorate(event, context, **kwargs):
273273
with self.provider.in_subsegment(name=f"## {lambda_handler_name}") as subsegment:
274274
global is_cold_start
275275
if is_cold_start:
@@ -279,7 +279,7 @@ def decorate(event, context):
279279

280280
try:
281281
logger.debug("Calling lambda handler")
282-
response = lambda_handler(event, context)
282+
response = lambda_handler(event, context, **kwargs)
283283
logger.debug("Received lambda handler response successfully")
284284
self._add_response_as_metadata(
285285
method_name=lambda_handler_name,

tests/functional/test_tracing.py

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ def handler(event, context):
3434
handler({}, {})
3535

3636

37+
def test_capture_lambda_handler_with_additional_kwargs(dummy_response):
38+
# GIVEN tracer lambda handler decorator is used
39+
tracer = Tracer(disabled=True)
40+
41+
# WHEN a lambda handler signature has additional keyword arguments
42+
@tracer.capture_lambda_handler
43+
def handler(event, context, my_extra_option=None, **kwargs):
44+
return dummy_response
45+
46+
# THEN tracer should not raise an Exception
47+
handler({}, {}, blah="blah")
48+
49+
3750
def test_capture_method(dummy_response):
3851
# GIVEN tracer method decorator is used
3952
tracer = Tracer(disabled=True)

0 commit comments

Comments
 (0)