@@ -38,14 +38,6 @@ def setUp(self):
3838 self .mock_threadstats_flush_distributions = patcher .start ()
3939 self .addCleanup (patcher .stop )
4040
41- self .metric_lambda_stats_patcher = patch ("datadog_lambda.metric.lambda_stats" )
42- self .mock_metric_lambda_stats = self .metric_lambda_stats_patcher .start ()
43- self .addCleanup (self .metric_lambda_stats_patcher .stop )
44-
45- self .wrapper_lambda_stats_patcher = patch ("datadog_lambda.wrapper.lambda_stats" )
46- self .mock_wrapper_lambda_stats = self .wrapper_lambda_stats_patcher .start ()
47- self .addCleanup (self .wrapper_lambda_stats_patcher .stop )
48-
4941 patcher = patch ("datadog_lambda.wrapper.extract_dd_trace_context" )
5042 self .mock_extract_dd_trace_context = patcher .start ()
5143 self .mock_extract_dd_trace_context .return_value = ({}, None )
@@ -101,10 +93,23 @@ def lambda_handler(event, context):
10193
10294 lambda_handler (lambda_event , lambda_context )
10395
104- self .mock_metric_lambda_stats .distribution .assert_has_calls (
105- [call ("test.metric" , 100 , timestamp = None , tags = ANY )]
96+ self .mock_threadstats_flush_distributions .assert_has_calls (
97+ [
98+ call (
99+ [
100+ {
101+ "metric" : "test.metric" ,
102+ "points" : [[ANY , [100 ]]],
103+ "type" : "distribution" ,
104+ "host" : None ,
105+ "device" : None ,
106+ "tags" : ANY ,
107+ "interval" : 10 ,
108+ }
109+ ]
110+ )
111+ ]
106112 )
107- self .mock_wrapper_lambda_stats .flush .assert_called ()
108113 self .mock_extract_dd_trace_context .assert_called_with (
109114 lambda_event , lambda_context , extractor = None
110115 )
@@ -122,16 +127,11 @@ def lambda_handler(event, context):
122127 lambda_event = {}
123128 lambda_handler (lambda_event , get_mock_context ())
124129
125- self .mock_metric_lambda_stats .distribution .assert_not_called ()
126- self .mock_wrapper_lambda_stats .flush .assert_not_called ()
130+ self .mock_threadstats_flush_distributions .assert_not_called ()
127131
128132 del os .environ ["DD_FLUSH_TO_LOG" ]
129133
130134 def test_datadog_lambda_wrapper_flush_in_thread (self ):
131- # stop patchers so mock_threadstats_flush_distributions gets called
132- self .metric_lambda_stats_patcher .stop ()
133- self .wrapper_lambda_stats_patcher .stop ()
134-
135135 # force ThreadStats to flush in thread
136136 import datadog_lambda .metric as metric_module
137137
@@ -158,15 +158,7 @@ def lambda_handler(event, context):
158158 metric_module .lambda_stats .stop ()
159159 metric_module .lambda_stats .start (flush_in_thread = False )
160160
161- # resume patchers
162- self .metric_lambda_stats_patcher .start ()
163- self .wrapper_lambda_stats_patcher .start ()
164-
165161 def test_datadog_lambda_wrapper_not_flush_in_thread (self ):
166- # stop patchers so mock_threadstats_flush_distributions gets called
167- self .metric_lambda_stats_patcher .stop ()
168- self .wrapper_lambda_stats_patcher .stop ()
169-
170162 # force ThreadStats to not flush in thread
171163 import datadog_lambda .metric as metric_module
172164
@@ -193,10 +185,6 @@ def lambda_handler(event, context):
193185 metric_module .lambda_stats .stop ()
194186 metric_module .lambda_stats .start (flush_in_thread = False )
195187
196- # resume patchers
197- self .metric_lambda_stats_patcher .start ()
198- self .wrapper_lambda_stats_patcher .start ()
199-
200188 def test_datadog_lambda_wrapper_inject_correlation_ids (self ):
201189 os .environ ["DD_LOGS_INJECTION" ] = "True"
202190
@@ -445,5 +433,4 @@ def lambda_handler(event, context):
445433 lambda_handler_double_wrapped (lambda_event , get_mock_context ())
446434
447435 self .mock_patch_all .assert_called_once ()
448- self .mock_wrapper_lambda_stats .flush .assert_called_once ()
449436 self .mock_submit_invocations_metric .assert_called_once ()
0 commit comments