Skip to content

Commit 57bb8a6

Browse files
committed
use redrive count to generate step functions parent ID
1 parent ed8c462 commit 57bb8a6

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

datadog_lambda/tracing.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,21 @@ def _parse_high_64_bits(trace_tags: str) -> str:
384384

385385

386386
def _generate_sfn_parent_id(context: dict) -> int:
387+
"""
388+
The upstream Step Function can propagate its execution context to downstream Lambdas. The Lambda can use these
389+
details to share the same traceID and infer its parent's spanID.
390+
391+
Excluding redriveCount when its 0 to account for cases where customers are using an old version of the Lambda layer
392+
that doesn't use this value for its parentID generation.
393+
"""
387394
execution_id = context.get("Execution").get("Id")
395+
redrive_count = context.get("Execution").get("RedriveCount")
388396
state_name = context.get("State").get("Name")
389397
state_entered_time = context.get("State").get("EnteredTime")
390398

391399
return _deterministic_sha256_hash(
392-
f"{execution_id}#{state_name}#{state_entered_time}", HIGHER_64_BITS
400+
f"{execution_id}#{state_name}#{state_entered_time}#{redrive_count}",
401+
HIGHER_64_BITS,
393402
)
394403

395404

tests/test_tracing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def test_step_function_trace_data(self):
631631
self.assertEqual(source, "event")
632632
expected_context = Context(
633633
trace_id=3675572987363469717,
634-
span_id=6880978411788117524,
634+
span_id=4929949072763648481,
635635
sampling_priority=1,
636636
meta={"_dd.p.tid": "e987c84b36b11ab"},
637637
)
@@ -673,7 +673,7 @@ def test_step_function_trace_data_lambda_root(self):
673673
self.assertEqual(source, "event")
674674
expected_context = Context(
675675
trace_id=5821803790426892636,
676-
span_id=6880978411788117524,
676+
span_id=4929949072763648481,
677677
sampling_priority=1,
678678
meta={"_dd.p.tid": "672a7cb100000000"},
679679
)
@@ -714,7 +714,7 @@ def test_step_function_trace_data_sfn_root(self):
714714
self.assertEqual(source, "event")
715715
expected_context = Context(
716716
trace_id=4521899030418994483,
717-
span_id=6880978411788117524,
717+
span_id=4929949072763648481,
718718
sampling_priority=1,
719719
meta={"_dd.p.tid": "12d1270d99cc5e03"},
720720
)

tests/test_xray.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def test_get_xray_host_port_success(self):
3434

3535
def test_send_segment_sampled_out(self):
3636
os.environ["AWS_XRAY_DAEMON_ADDRESS"] = "fake-agent.com:8080"
37-
os.environ[
38-
"_X_AMZN_TRACE_ID"
39-
] = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=0;Lineage=c6c5b1b9:0"
37+
os.environ["_X_AMZN_TRACE_ID"] = (
38+
"Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=0;Lineage=c6c5b1b9:0"
39+
)
4040

4141
with patch(
4242
"datadog_lambda.xray.sock.send", MagicMock(return_value=None)
@@ -47,9 +47,9 @@ def test_send_segment_sampled_out(self):
4747

4848
def test_send_segment_sampled(self):
4949
os.environ["AWS_XRAY_DAEMON_ADDRESS"] = "fake-agent.com:8080"
50-
os.environ[
51-
"_X_AMZN_TRACE_ID"
52-
] = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1;Lineage=c6c5b1b9:0"
50+
os.environ["_X_AMZN_TRACE_ID"] = (
51+
"Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1;Lineage=c6c5b1b9:0"
52+
)
5353
with patch(
5454
"datadog_lambda.xray.sock.send", MagicMock(return_value=None)
5555
) as mock_send:

0 commit comments

Comments
 (0)