Skip to content

Commit 7ad64c5

Browse files
Adding unit test for using extract_context_from_lambda_context
1 parent 006caee commit 7ad64c5

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tests/test_tracing.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
)
4949

5050
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
5252

5353

5454
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):
621621
]
622622
)
623623

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+
624658
def _test_step_function_trace_data_common(
625659
self, event, expected_trace_id, expected_span_id, expected_tid
626660
):

0 commit comments

Comments
 (0)