Skip to content

Commit 354a61b

Browse files
committed
Add test for no Parent in _X_AMZN_TRACE_ID.
1 parent f8d6173 commit 354a61b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

datadog_lambda/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _convert_xray_sampling(xray_sampled):
8989
return SamplingPriority.USER_KEEP if xray_sampled else SamplingPriority.USER_REJECT
9090

9191

92-
def _get_xray_trace_context() -> Optional[Context]:
92+
def _get_xray_trace_context():
9393
if not is_lambda_context():
9494
return None
9595

tests/test_tracing.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from datadog_lambda.constants import (
1515
SamplingPriority,
1616
TraceHeader,
17+
TraceContextSource,
1718
XraySubsegment,
1819
)
1920
from datadog_lambda.tracing import (
@@ -854,6 +855,30 @@ def test_mixed_parent_context_when_merging(self):
854855
self.mock_activate.assert_called()
855856
self.mock_activate.assert_has_calls([call(expected_context)])
856857

858+
def test_set_dd_trace_py_root_no_span_id(self):
859+
os.environ["_X_AMZN_TRACE_ID"] = "Root=1-5e272390-8c398be037738dc042009320"
860+
861+
lambda_ctx = get_mock_context()
862+
ctx, source, event_type = extract_dd_trace_context(
863+
{
864+
"headers": {
865+
TraceHeader.TRACE_ID: "123",
866+
TraceHeader.PARENT_ID: "321",
867+
TraceHeader.SAMPLING_PRIORITY: "1",
868+
}
869+
},
870+
lambda_ctx,
871+
)
872+
set_dd_trace_py_root(TraceContextSource.EVENT, True)
873+
874+
expected_context = Context(
875+
trace_id=123, # Trace Id from incomming context
876+
span_id=321, # Span Id from incoming context
877+
sampling_priority=1, # Sampling priority from incomming context
878+
)
879+
self.mock_activate.assert_called()
880+
self.mock_activate.assert_has_calls([call(expected_context)])
881+
857882

858883
class TestAuthorizerInferredSpans(unittest.TestCase):
859884
def setUp(self):

0 commit comments

Comments
 (0)