1313def get_mock_context (
1414 aws_request_id = "request-id-1" ,
1515 memory_limit_in_mb = "256" ,
16- invoked_function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:foobar " ,
16+ invoked_function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:1 " ,
1717 function_version = "1" ,
1818):
1919 lambda_context = MagicMock ()
@@ -146,10 +146,9 @@ def lambda_handler(event, context):
146146 "region:us-west-1" ,
147147 "account_id:123457598159" ,
148148 "functionname:python-layer-test" ,
149- "resource:python-layer-test:foobar " ,
149+ "resource:python-layer-test:1 " ,
150150 "cold_start:true" ,
151151 "memorysize:256" ,
152- "executedversion:1" ,
153152 "runtime:python2.7" ,
154153 "dd_lambda_layer:datadog-python27_0.1.0" ,
155154 ],
@@ -176,10 +175,9 @@ def lambda_handler(event, context):
176175 "region:us-west-1" ,
177176 "account_id:123457598159" ,
178177 "functionname:python-layer-test" ,
179- "resource:python-layer-test:foobar " ,
178+ "resource:python-layer-test:1 " ,
180179 "cold_start:true" ,
181180 "memorysize:256" ,
182- "executedversion:1" ,
183181 "runtime:python2.7" ,
184182 "dd_lambda_layer:datadog-python27_0.1.0" ,
185183 ],
@@ -191,10 +189,9 @@ def lambda_handler(event, context):
191189 "region:us-west-1" ,
192190 "account_id:123457598159" ,
193191 "functionname:python-layer-test" ,
194- "resource:python-layer-test:foobar " ,
192+ "resource:python-layer-test:1 " ,
195193 "cold_start:true" ,
196194 "memorysize:256" ,
197- "executedversion:1" ,
198195 "runtime:python2.7" ,
199196 "dd_lambda_layer:datadog-python27_0.1.0" ,
200197 ],
@@ -226,10 +223,9 @@ def lambda_handler(event, context):
226223 "region:us-west-1" ,
227224 "account_id:123457598159" ,
228225 "functionname:python-layer-test" ,
229- "resource:python-layer-test:foobar " ,
226+ "resource:python-layer-test:1 " ,
230227 "cold_start:true" ,
231228 "memorysize:256" ,
232- "executedversion:1" ,
233229 "runtime:python2.7" ,
234230 "dd_lambda_layer:datadog-python27_0.1.0" ,
235231 ],
@@ -241,17 +237,80 @@ def lambda_handler(event, context):
241237 "region:us-west-1" ,
242238 "account_id:123457598159" ,
243239 "functionname:python-layer-test" ,
244- "resource:python-layer-test:foobar " ,
240+ "resource:python-layer-test:1 " ,
245241 "cold_start:false" ,
246242 "memorysize:256" ,
247- "executedversion:1" ,
248243 "runtime:python2.7" ,
249244 "dd_lambda_layer:datadog-python27_0.1.0" ,
250245 ],
251246 ),
252247 ]
253248 )
254249
250+ def test_enhanced_metrics_latest (self ):
251+ @datadog_lambda_wrapper
252+ def lambda_handler (event , context ):
253+ lambda_metric ("test.metric" , 100 )
254+
255+ lambda_event = {}
256+ lambda_context = get_mock_context ()
257+
258+ lambda_context .invoked_function_arn = (
259+ "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:$Latest"
260+ )
261+ lambda_handler (lambda_event , lambda_context )
262+
263+ self .mock_write_metric_point_to_stdout .assert_has_calls (
264+ [
265+ call (
266+ "aws.lambda.enhanced.invocations" ,
267+ 1 ,
268+ tags = [
269+ "region:us-west-1" ,
270+ "account_id:123457598159" ,
271+ "functionname:python-layer-test" ,
272+ "resource:python-layer-test:Latest" ,
273+ "cold_start:true" ,
274+ "memorysize:256" ,
275+ "runtime:python2.7" ,
276+ "dd_lambda_layer:datadog-python27_0.1.0" ,
277+ ],
278+ )
279+ ]
280+ )
281+
282+ def test_enhanced_metrics_alias (self ):
283+ @datadog_lambda_wrapper
284+ def lambda_handler (event , context ):
285+ lambda_metric ("test.metric" , 100 )
286+
287+ lambda_event = {}
288+ lambda_context = get_mock_context ()
289+ # tests wouldn't run because line was too long
290+ alias_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:My_alias-1"
291+ lambda_context .invoked_function_arn = alias_arn
292+ lambda_handler (lambda_event , lambda_context )
293+
294+ self .mock_write_metric_point_to_stdout .assert_has_calls (
295+ [
296+ call (
297+ "aws.lambda.enhanced.invocations" ,
298+ 1 ,
299+ tags = [
300+ "region:us-west-1" ,
301+ "account_id:123457598159" ,
302+ "functionname:python-layer-test" ,
303+ "executedversion:1" ,
304+ "resource:python-layer-test:My_alias-1" ,
305+ "cold_start:true" ,
306+ "memorysize:256" ,
307+ "runtime:python2.7" ,
308+ "dd_lambda_layer:datadog-python27_0.1.0" ,
309+ ],
310+ )
311+ ]
312+ )
313+
255314 def test_no_enhanced_metrics_without_env_var (self ):
256315 os .environ ["DD_ENHANCED_METRICS" ] = "false"
257316
0 commit comments