|
48 | 48 | ) |
49 | 49 |
|
50 | 50 | from datadog_lambda.trigger import parse_event_source |
51 | | -from tests.utils import get_mock_context |
| 51 | +from tests.utils import get_mock_context, ClientContext |
52 | 52 |
|
53 | 53 |
|
54 | 54 | function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test" |
@@ -621,6 +621,40 @@ def test_with_complete_datadog_trace_headers_with_trigger_tags(self): |
621 | 621 | ] |
622 | 622 | ) |
623 | 623 |
|
| 624 | + def test_request_header_malformed(self): |
| 625 | + """Testing that if a RUM AppSync event is malformed, the tracer will attempt |
| 626 | + to get the trace context from the lambda context in the |
| 627 | + extract_context_from_request_header_or_context function.""" |
| 628 | + lambda_ctx = get_mock_context() |
| 629 | + lambda_ctx.client_context = ClientContext(custom={ |
| 630 | + "_datadog": { |
| 631 | + "x-datadog-parent-id": "67890", |
| 632 | + "x-datadog-sampling-priority": "1", |
| 633 | + "x-datadog-trace-id": "12345", |
| 634 | + }}) |
| 635 | + request_header_event = { |
| 636 | + "identity": "None", |
| 637 | + "info": { |
| 638 | + "fieldName": "getItems", |
| 639 | + "parentTypeName": "Query", |
| 640 | + "selectionSetGraphQL": "{\n id\n}", |
| 641 | + "selectionSetList":["id"] |
| 642 | + }, |
| 643 | + "prev": "None", |
| 644 | + "request": "hello", |
| 645 | + "source": "None" |
| 646 | + } |
| 647 | + ctx, source, _ = extract_dd_trace_context(request_header_event, lambda_ctx) |
| 648 | + expected_context = Context( |
| 649 | + trace_id = 12345, |
| 650 | + span_id = 67890, |
| 651 | + sampling_priority = 1, |
| 652 | + ) |
| 653 | + |
| 654 | + self.assertEqual(ctx, expected_context) |
| 655 | + self.assertEqual(source, "event") |
| 656 | + |
| 657 | + |
624 | 658 | def _test_step_function_trace_data_common( |
625 | 659 | self, event, expected_trace_id, expected_span_id, expected_tid |
626 | 660 | ): |
|
0 commit comments