Skip to content

Commit b36ab47

Browse files
authored
fix: type check event before treating it as a dict (#233)
* fix: type check event before treating it as a dict * fix: Use doublequotes for binary string
1 parent ef9f18c commit b36ab47

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

datadog_lambda/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def extract_dd_trace_context(event, lambda_context, extractor=None):
334334
parent_id,
335335
sampling_priority,
336336
) = extract_context_custom_extractor(extractor, event, lambda_context)
337-
elif "headers" in event:
337+
elif isinstance(event, (list, dict)) and "headers" in event:
338338
(
339339
trace_id,
340340
parent_id,

tests/test_tracing.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ def test_without_datadog_trace_headers(self):
104104
{},
105105
)
106106

107+
def test_with_non_object_event(self):
108+
lambda_ctx = get_mock_context()
109+
ctx, source = extract_dd_trace_context(b"", lambda_ctx)
110+
self.assertEqual(source, "xray")
111+
self.assertDictEqual(
112+
ctx,
113+
{
114+
"trace-id": fake_xray_header_value_root_decimal,
115+
"parent-id": fake_xray_header_value_parent_decimal,
116+
"sampling-priority": "2",
117+
},
118+
)
119+
self.assertDictEqual(
120+
get_dd_trace_context(),
121+
{
122+
TraceHeader.TRACE_ID: fake_xray_header_value_root_decimal,
123+
TraceHeader.PARENT_ID: fake_xray_header_value_parent_decimal,
124+
TraceHeader.SAMPLING_PRIORITY: "2",
125+
},
126+
{},
127+
)
128+
107129
def test_with_incomplete_datadog_trace_headers(self):
108130
lambda_ctx = get_mock_context()
109131
ctx, source = extract_dd_trace_context(

0 commit comments

Comments
 (0)