|
42 | 42 | service_mapping as global_service_mapping,
|
43 | 43 | propagator,
|
44 | 44 | emit_telemetry_on_exception_outside_of_handler,
|
45 |
| - is_legacy_lambda_step_function, |
| 45 | + is_step_function_event, |
46 | 46 | )
|
47 | 47 | from datadog_lambda.trigger import EventTypes
|
48 | 48 |
|
@@ -836,6 +836,55 @@ def test_step_function_trace_data_sfn_root(self):
|
836 | 836 | expected_context,
|
837 | 837 | )
|
838 | 838 |
|
| 839 | + @with_trace_propagation_style("datadog") |
| 840 | + def test_step_function_trace_data_event_bridge(self): |
| 841 | + lambda_ctx = get_mock_context() |
| 842 | + sfn_event = { |
| 843 | + "_datadog": { |
| 844 | + "Execution": { |
| 845 | + "StartTime": "2025-03-11T01:16:31.408Z", |
| 846 | + "Id": "arn:aws:states:sa-east-1:425362996713:execution:abhinav-inner-state-machine:eb6298d0-93b5-4fe0-8af9-fefe2933b0ed", |
| 847 | + "RedriveCount": 0, |
| 848 | + "RoleArn": "arn:aws:iam::425362996713:role/service-role/StepFunctions-abhinav-activity-state-machine-role-22jpbgl6j", |
| 849 | + "Name": "eb6298d0-93b5-4fe0-8af9-fefe2933b0ed", |
| 850 | + }, |
| 851 | + "StateMachine": { |
| 852 | + "Id": "arn:aws:states:sa-east-1:425362996713:stateMachine:abhinav-inner-state-machine", |
| 853 | + "Name": "abhinav-inner-state-machine", |
| 854 | + }, |
| 855 | + "State": { |
| 856 | + "EnteredTime": "2025-03-11T01:16:31.448Z", |
| 857 | + "RetryCount": 0, |
| 858 | + "Name": "EventBridge PutEvents", |
| 859 | + }, |
| 860 | + "serverless-version": "v1", |
| 861 | + "RootExecutionId": "arn:aws:states:sa-east-1:425362996713:execution:abhinav-inner-state-machine:eb6298d0-93b5-4fe0-8af9-fefe2933b0ed", |
| 862 | + } |
| 863 | + } |
| 864 | + ctx, source, event_source = extract_dd_trace_context(sfn_event, lambda_ctx) |
| 865 | + self.assertEqual(source, "event") |
| 866 | + expected_context = Context( |
| 867 | + trace_id=4521899030418994483, |
| 868 | + span_id=6880978411788117524, |
| 869 | + sampling_priority=1, |
| 870 | + meta={"_dd.p.tid": "12d1270d99cc5e03"}, |
| 871 | + ) |
| 872 | + self.assertEqual(ctx, expected_context) |
| 873 | + self.assertEqual( |
| 874 | + get_dd_trace_context(), |
| 875 | + { |
| 876 | + TraceHeader.TRACE_ID: "4521899030418994483", |
| 877 | + TraceHeader.PARENT_ID: "2685222157636933868", |
| 878 | + TraceHeader.SAMPLING_PRIORITY: "1", |
| 879 | + TraceHeader.TAGS: "_dd.p.tid=12d1270d99cc5e03", |
| 880 | + }, |
| 881 | + ) |
| 882 | + create_dd_dummy_metadata_subsegment(ctx, XraySubsegment.TRACE_KEY) |
| 883 | + self.mock_send_segment.assert_called_with( |
| 884 | + XraySubsegment.TRACE_KEY, |
| 885 | + expected_context, |
| 886 | + ) |
| 887 | + |
839 | 888 |
|
840 | 889 | class TestXRayContextConversion(unittest.TestCase):
|
841 | 890 | def test_convert_xray_trace_id(self):
|
@@ -2282,6 +2331,69 @@ def test_deterministic_m5_hash__always_leading_with_zero(self):
|
2282 | 2331 | if len(result_in_binary) == 66: # "0b" + 64 bits.
|
2283 | 2332 | self.assertTrue(result_in_binary.startswith("0b0"))
|
2284 | 2333 |
|
| 2334 | + def test_is_step_function_event_jsonata(self): |
| 2335 | + event = { |
| 2336 | + "_datadog": { |
| 2337 | + "Execution": { |
| 2338 | + "Id": "665c417c-1237-4742-aaca-8b3becbb9e75", |
| 2339 | + "RedriveCount": 0, |
| 2340 | + }, |
| 2341 | + "StateMachine": {}, |
| 2342 | + "State": { |
| 2343 | + "Name": "my-awesome-state", |
| 2344 | + "EnteredTime": "Mon Nov 13 12:43:33 PST 2023", |
| 2345 | + "RetryCount": 0, |
| 2346 | + }, |
| 2347 | + "x-datadog-trace-id": "5821803790426892636", |
| 2348 | + "x-datadog-tags": "_dd.p.dm=-0,_dd.p.tid=672a7cb100000000", |
| 2349 | + "serverless-version": "v1", |
| 2350 | + } |
| 2351 | + } |
| 2352 | + self.assertTrue(is_step_function_event(event)) |
| 2353 | + |
| 2354 | + def test_is_step_function_event_jsonpath(self): |
| 2355 | + event = { |
| 2356 | + "Execution": { |
| 2357 | + "Id": "665c417c-1237-4742-aaca-8b3becbb9e75", |
| 2358 | + "RedriveCount": 0, |
| 2359 | + }, |
| 2360 | + "StateMachine": {}, |
| 2361 | + "State": { |
| 2362 | + "Name": "my-awesome-state", |
| 2363 | + "EnteredTime": "Mon Nov 13 12:43:33 PST 2023", |
| 2364 | + "RetryCount": 0, |
| 2365 | + }, |
| 2366 | + } |
| 2367 | + self.assertTrue(is_step_function_event(event)) |
| 2368 | + |
| 2369 | + def test_is_step_function_event_legacy_lambda(self): |
| 2370 | + event = { |
| 2371 | + "Payload": { |
| 2372 | + "Execution": { |
| 2373 | + "Id": "665c417c-1237-4742-aaca-8b3becbb9e75", |
| 2374 | + "RedriveCount": 0, |
| 2375 | + }, |
| 2376 | + "StateMachine": {}, |
| 2377 | + "State": { |
| 2378 | + "Name": "my-awesome-state", |
| 2379 | + "EnteredTime": "Mon Nov 13 12:43:33 PST 2023", |
| 2380 | + "RetryCount": 0, |
| 2381 | + }, |
| 2382 | + } |
| 2383 | + } |
| 2384 | + self.assertTrue(is_step_function_event(event)) |
| 2385 | + |
| 2386 | + def test_is_step_function_event_dd_header(self): |
| 2387 | + event = { |
| 2388 | + "_datadog": { |
| 2389 | + "x-datadog-trace-id": "5821803790426892636", |
| 2390 | + "x-datadog-parent-id": "5821803790426892636", |
| 2391 | + "x-datadog-tags": "_dd.p.dm=-0,_dd.p.tid=672a7cb100000000", |
| 2392 | + "x-datadog-sampling-priority": "1", |
| 2393 | + } |
| 2394 | + } |
| 2395 | + self.assertFalse(is_step_function_event(event)) |
| 2396 | + |
2285 | 2397 |
|
2286 | 2398 | class TestExceptionOutsideHandler(unittest.TestCase):
|
2287 | 2399 | @patch("datadog_lambda.tracing.dd_tracing_enabled", True)
|
|
0 commit comments