Skip to content

Commit 4ec08d3

Browse files
committed
dont use redriveCount of 0
1 parent 0076581 commit 4ec08d3

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

datadog_lambda/tracing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,10 @@ def _generate_sfn_parent_id(context: dict) -> int:
396396
state_name = context.get("State").get("Name")
397397
state_entered_time = context.get("State").get("EnteredTime")
398398

399+
redrive_postfix = "" if redrive_count == "0" else f"#{redrive_count}"
400+
399401
return _deterministic_sha256_hash(
400-
f"{execution_id}#{state_name}#{state_entered_time}#{redrive_count}",
402+
f"{execution_id}#{state_name}#{state_entered_time}{redrive_postfix}",
401403
HIGHER_64_BITS,
402404
)
403405

tests/test_tracing.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ def test_step_function_trace_data(self):
620620
sfn_event = {
621621
"Execution": {
622622
"Id": "665c417c-1237-4742-aaca-8b3becbb9e75",
623+
"RedriveCount": "0",
623624
},
624625
"StateMachine": {},
625626
"State": {
@@ -631,7 +632,45 @@ def test_step_function_trace_data(self):
631632
self.assertEqual(source, "event")
632633
expected_context = Context(
633634
trace_id=3675572987363469717,
634-
span_id=4929949072763648481,
635+
span_id=6880978411788117524,
636+
sampling_priority=1,
637+
meta={"_dd.p.tid": "e987c84b36b11ab"},
638+
)
639+
self.assertEqual(ctx, expected_context)
640+
self.assertEqual(
641+
get_dd_trace_context(),
642+
{
643+
TraceHeader.TRACE_ID: "3675572987363469717",
644+
TraceHeader.PARENT_ID: "10713633173203262661",
645+
TraceHeader.SAMPLING_PRIORITY: "1",
646+
TraceHeader.TAGS: "_dd.p.tid=e987c84b36b11ab",
647+
},
648+
)
649+
create_dd_dummy_metadata_subsegment(ctx, XraySubsegment.TRACE_KEY)
650+
self.mock_send_segment.assert_called_with(
651+
XraySubsegment.TRACE_KEY,
652+
expected_context,
653+
)
654+
655+
@with_trace_propagation_style("datadog")
656+
def test_step_function_trace_data_redrive(self):
657+
lambda_ctx = get_mock_context()
658+
sfn_event = {
659+
"Execution": {
660+
"Id": "665c417c-1237-4742-aaca-8b3becbb9e75",
661+
"RedriveCount": "1",
662+
},
663+
"StateMachine": {},
664+
"State": {
665+
"Name": "my-awesome-state",
666+
"EnteredTime": "Mon Nov 13 12:43:33 PST 2023",
667+
},
668+
}
669+
ctx, source, event_source = extract_dd_trace_context(sfn_event, lambda_ctx)
670+
self.assertEqual(source, "event")
671+
expected_context = Context(
672+
trace_id=3675572987363469717,
673+
span_id=1201185214297576513,
635674
sampling_priority=1,
636675
meta={"_dd.p.tid": "e987c84b36b11ab"},
637676
)
@@ -658,6 +697,7 @@ def test_step_function_trace_data_lambda_root(self):
658697
"_datadog": {
659698
"Execution": {
660699
"Id": "665c417c-1237-4742-aaca-8b3becbb9e75",
700+
"RedriveCount": "0",
661701
},
662702
"StateMachine": {},
663703
"State": {
@@ -673,7 +713,7 @@ def test_step_function_trace_data_lambda_root(self):
673713
self.assertEqual(source, "event")
674714
expected_context = Context(
675715
trace_id=5821803790426892636,
676-
span_id=4929949072763648481,
716+
span_id=6880978411788117524,
677717
sampling_priority=1,
678718
meta={"_dd.p.tid": "672a7cb100000000"},
679719
)
@@ -700,6 +740,7 @@ def test_step_function_trace_data_sfn_root(self):
700740
"_datadog": {
701741
"Execution": {
702742
"Id": "665c417c-1237-4742-aaca-8b3becbb9e75",
743+
"RedriveCount": "0",
703744
},
704745
"StateMachine": {},
705746
"State": {
@@ -714,7 +755,7 @@ def test_step_function_trace_data_sfn_root(self):
714755
self.assertEqual(source, "event")
715756
expected_context = Context(
716757
trace_id=4521899030418994483,
717-
span_id=4929949072763648481,
758+
span_id=6880978411788117524,
718759
sampling_priority=1,
719760
meta={"_dd.p.tid": "12d1270d99cc5e03"},
720761
)

0 commit comments

Comments
 (0)