@@ -62,6 +62,18 @@ def setUp(self):
6262 self .mock_python_version_tuple .return_value = ("2" , "7" , "10" )
6363 self .addCleanup (patcher .stop )
6464
65+ patcher = patch ("datadog_lambda.metric.write_metric_point_to_stdout" )
66+ self .mock_write_metric_point_to_stdout = patcher .start ()
67+ self .addCleanup (patcher .stop )
68+
69+ patcher = patch ("datadog_lambda.tags._format_dd_lambda_layer_tag" )
70+ self .mock_format_dd_lambda_layer_tag = patcher .start ()
71+ # Mock the layer version so we don't have to update tests on every version bump
72+ self .mock_format_dd_lambda_layer_tag .return_value = (
73+ "dd_lambda_layer:datadog-python27_0.1.0"
74+ )
75+ self .addCleanup (patcher .stop )
76+
6577 def test_datadog_lambda_wrapper (self ):
6678 @datadog_lambda_wrapper
6779 def lambda_handler (event , context ):
@@ -111,8 +123,6 @@ def lambda_handler(event, context):
111123 del os .environ ["DD_LOGS_INJECTION" ]
112124
113125 def test_invocations_metric (self ):
114- os .environ ["DD_ENHANCED_METRICS" ] = "True"
115-
116126 @datadog_lambda_wrapper
117127 def lambda_handler (event , context ):
118128 lambda_metric ("test.metric" , 100 )
@@ -121,7 +131,7 @@ def lambda_handler(event, context):
121131
122132 lambda_handler (lambda_event , get_mock_context ())
123133
124- self .mock_lambda_metric .assert_has_calls (
134+ self .mock_write_metric_point_to_stdout .assert_has_calls (
125135 [
126136 call (
127137 "aws.lambda.enhanced.invocations" ,
@@ -133,16 +143,13 @@ def lambda_handler(event, context):
133143 "cold_start:true" ,
134144 "memorysize:256" ,
135145 "runtime:python2.7" ,
146+ "dd_lambda_layer:datadog-python27_0.1.0" ,
136147 ],
137148 )
138149 ]
139150 )
140151
141- del os .environ ["DD_ENHANCED_METRICS" ]
142-
143152 def test_errors_metric (self ):
144- os .environ ["DD_ENHANCED_METRICS" ] = "True"
145-
146153 @datadog_lambda_wrapper
147154 def lambda_handler (event , context ):
148155 raise RuntimeError ()
@@ -152,7 +159,7 @@ def lambda_handler(event, context):
152159 with self .assertRaises (RuntimeError ):
153160 lambda_handler (lambda_event , get_mock_context ())
154161
155- self .mock_lambda_metric .assert_has_calls (
162+ self .mock_write_metric_point_to_stdout .assert_has_calls (
156163 [
157164 call (
158165 "aws.lambda.enhanced.invocations" ,
@@ -164,6 +171,7 @@ def lambda_handler(event, context):
164171 "cold_start:true" ,
165172 "memorysize:256" ,
166173 "runtime:python2.7" ,
174+ "dd_lambda_layer:datadog-python27_0.1.0" ,
167175 ],
168176 ),
169177 call (
@@ -176,16 +184,13 @@ def lambda_handler(event, context):
176184 "cold_start:true" ,
177185 "memorysize:256" ,
178186 "runtime:python2.7" ,
187+ "dd_lambda_layer:datadog-python27_0.1.0" ,
179188 ],
180189 ),
181190 ]
182191 )
183192
184- del os .environ ["DD_ENHANCED_METRICS" ]
185-
186193 def test_enhanced_metrics_cold_start_tag (self ):
187- os .environ ["DD_ENHANCED_METRICS" ] = "True"
188-
189194 @datadog_lambda_wrapper
190195 def lambda_handler (event , context ):
191196 lambda_metric ("test.metric" , 100 )
@@ -200,7 +205,7 @@ def lambda_handler(event, context):
200205 lambda_event , get_mock_context (aws_request_id = "second-request-id" )
201206 )
202207
203- self .mock_lambda_metric .assert_has_calls (
208+ self .mock_write_metric_point_to_stdout .assert_has_calls (
204209 [
205210 call (
206211 "aws.lambda.enhanced.invocations" ,
@@ -212,6 +217,7 @@ def lambda_handler(event, context):
212217 "cold_start:true" ,
213218 "memorysize:256" ,
214219 "runtime:python2.7" ,
220+ "dd_lambda_layer:datadog-python27_0.1.0" ,
215221 ],
216222 ),
217223 call (
@@ -224,14 +230,15 @@ def lambda_handler(event, context):
224230 "cold_start:false" ,
225231 "memorysize:256" ,
226232 "runtime:python2.7" ,
233+ "dd_lambda_layer:datadog-python27_0.1.0" ,
227234 ],
228235 ),
229236 ]
230237 )
231238
232- del os .environ ["DD_ENHANCED_METRICS" ]
233-
234239 def test_no_enhanced_metrics_without_env_var (self ):
240+ os .environ ["DD_ENHANCED_METRICS" ] = "false"
241+
235242 @datadog_lambda_wrapper
236243 def lambda_handler (event , context ):
237244 raise RuntimeError ()
@@ -241,4 +248,6 @@ def lambda_handler(event, context):
241248 with self .assertRaises (RuntimeError ):
242249 lambda_handler (lambda_event , get_mock_context ())
243250
244- self .mock_lambda_metric .assert_not_called ()
251+ self .mock_write_metric_point_to_stdout .assert_not_called ()
252+
253+ del os .environ ["DD_ENHANCED_METRICS" ]
0 commit comments