Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion datadog_lambda/durable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ def extract_durable_function_tags(event):
if not parsed:
logger.error("Failed to parse DurableExecutionArn: %s", durable_execution_arn)
return {}

execution_name, execution_id = parsed
# Use the number of operations to determine if it's the first invocation. This is
# what the durable execution SDK does to determine the replay status.
operations = event.get("InitialExecutionState", {}).get("Operations", [])
is_first_invocation = len(operations) == 1
return {
"durable_function_execution_name": execution_name,
"durable_function_execution_id": execution_id,
"durable_function_first_invocation": str(is_first_invocation).lower(),
}
28 changes: 26 additions & 2 deletions tests/test_durable.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,42 @@ 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_sets_first_invocation_true_when_only_execution_operation(self):
# One operation (the current EXECUTION operation itself) → not replaying → first invocation
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",
"InitialExecutionState": {"Operations": []},
"InitialExecutionState": {"Operations": [{"OperationType": "EXECUTION"}]},
}
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",
},
)

def test_sets_first_invocation_false_when_multiple_operations(self):
# More than one operation → replaying → not first invocation
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",
"InitialExecutionState": {
"Operations": [
{"OperationType": "EXECUTION"},
{"OperationType": "STEP"},
]
},
}
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": "false",
},
)

Expand Down
Loading