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", }, )