From 81cd12a3289c4ca06d23a5a21af05f3ebb604950 Mon Sep 17 00:00:00 2001 From: Yiming Luo Date: Fri, 13 Mar 2026 16:12:49 -0400 Subject: [PATCH] Add durable_function_first_invocation tag to aws.lambda spans Extends extract_durable_function_tags() to also include durable_function_first_invocation ("true"/"false"), derived from the absence of CheckpointToken in the event payload (present on replays, absent on first invocation). Co-Authored-By: Claude Sonnet 4.6 --- datadog_lambda/durable.py | 2 ++ tests/test_durable.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/datadog_lambda/durable.py b/datadog_lambda/durable.py index e9443f92..3af4776f 100644 --- a/datadog_lambda/durable.py +++ b/datadog_lambda/durable.py @@ -43,7 +43,9 @@ def extract_durable_function_tags(event): return {} execution_name, execution_id = parsed + is_first_invocation = event.get("CheckpointToken") is None return { "durable_function_execution_name": execution_name, "durable_function_execution_id": execution_id, + "durable_function_first_invocation": str(is_first_invocation).lower(), } diff --git a/tests/test_durable.py b/tests/test_durable.py index 60914934..80770458 100644 --- a/tests/test_durable.py +++ b/tests/test_durable.py @@ -45,7 +45,7 @@ def test_works_with_numeric_version_qualifier(self): class TestExtractDurableFunctionTags(unittest.TestCase): - def test_extracts_tags_from_event_with_durable_execution_arn(self): + def test_extracts_tags_from_event_with_checkpoint_token(self): event = { "DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-func:1/durable-execution/my-execution/550e8400-e29b-41d4-a716-446655440004", "CheckpointToken": "some-token", @@ -57,6 +57,21 @@ def test_extracts_tags_from_event_with_durable_execution_arn(self): { "durable_function_execution_name": "my-execution", "durable_function_execution_id": "550e8400-e29b-41d4-a716-446655440004", + "durable_function_first_invocation": "false", + }, + ) + + def test_extracts_tags_from_event_without_checkpoint_token(self): + event = { + "DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-func:1/durable-execution/my-execution/550e8400-e29b-41d4-a716-446655440004", + } + result = extract_durable_function_tags(event) + self.assertEqual( + result, + { + "durable_function_execution_name": "my-execution", + "durable_function_execution_id": "550e8400-e29b-41d4-a716-446655440004", + "durable_function_first_invocation": "true", }, )