File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -53,19 +53,19 @@ class _LambdaDecorator(object):
53
53
and extracts/injects trace context.
54
54
"""
55
55
56
- _instance = None
57
56
_force_new = False
58
57
59
58
def __new__ (cls , func ):
60
59
"""
61
- If the decorator is accidentally applied to multiple functions or
62
- the same function multiple times, only the first one takes effect.
60
+ If the decorator is accidentally applied to the same function multiple times,
61
+ only the first one takes effect.
63
62
64
63
If _force_new, always return a real decorator, useful for unit tests.
65
64
"""
66
- if cls ._force_new or cls ._instance is None :
67
- cls ._instance = super (_LambdaDecorator , cls ).__new__ (cls )
68
- return cls ._instance
65
+ if cls ._force_new or not getattr (func , "_dd_wrapped" , False ):
66
+ wrapped = super (_LambdaDecorator , cls ).__new__ (cls )
67
+ wrapped ._dd_wrapped = True
68
+ return wrapped
69
69
else :
70
70
return _NoopDecorator (func )
71
71
Original file line number Diff line number Diff line change @@ -269,13 +269,11 @@ def lambda_handler(event, context):
269
269
# the second @datadog_lambda_wrapper should actually be no-op.
270
270
datadog_lambda_wrapper ._force_new = False
271
271
272
- @datadog_lambda_wrapper
273
- def lambda_handler_wrapper (event , context ):
274
- lambda_handler (event , context )
272
+ lambda_handler_double_wrapped = datadog_lambda_wrapper (lambda_handler )
275
273
276
274
lambda_event = {}
277
275
278
- lambda_handler_wrapper (lambda_event , get_mock_context ())
276
+ lambda_handler_double_wrapped (lambda_event , get_mock_context ())
279
277
280
278
self .mock_patch_all .assert_called_once ()
281
279
self .mock_wrapper_lambda_stats .flush .assert_called_once ()
You can’t perform that action at this time.
0 commit comments