Skip to content

Commit 97dbedf

Browse files
vaib-amzVaib Suri
andauthored
Adding Tracing property to State Machine resource (#1697)
* Step Functions: Adding support for X-Ray tracing * Renaming TracingConfiguration to Tracing Co-authored-by: Vaib Suri <[email protected]>
1 parent ed2f24e commit 97dbedf

File tree

9 files changed

+95
-1
lines changed

9 files changed

+95
-1
lines changed

samtranslator/model/sam_resources.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,8 @@ class SamStateMachine(SamResourceMacro):
11201120
"Name": PropertyType(False, is_str()),
11211121
"Type": PropertyType(False, is_str()),
11221122
"Tags": PropertyType(False, is_type(dict)),
1123-
"Policies": PropertyType(False, one_of(is_str(), is_type(dict), list_of(one_of(is_str(), is_type(dict))))),
1123+
"Policies": PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))),
1124+
"Tracing": PropertyType(False, is_type(dict)),
11241125
}
11251126
event_resolver = ResourceTypeResolver(samtranslator.model.stepfunctions.events,)
11261127

@@ -1142,6 +1143,7 @@ def to_cloudformation(self, **kwargs):
11421143
definition_substitutions=self.DefinitionSubstitutions,
11431144
role=self.Role,
11441145
state_machine_type=self.Type,
1146+
tracing=self.Tracing,
11451147
events=self.Events,
11461148
event_resources=event_resources,
11471149
event_resolver=self.event_resolver,

samtranslator/model/stepfunctions/generators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(
4040
definition_substitutions,
4141
role,
4242
state_machine_type,
43+
tracing,
4344
events,
4445
event_resources,
4546
event_resolver,
@@ -62,6 +63,7 @@ def __init__(
6263
:param definition_substitutions: Variable-to-value mappings to be replaced in the State Machine definition
6364
:param role: Role ARN to use for the execution role
6465
:param state_machine_type: Type of the State Machine
66+
:param tracing: Tracing configuration for the State Machine
6567
:param events: List of event sources for the State Machine
6668
:param event_resources: Event resources to link
6769
:param event_resolver: Resolver that maps Event types to Event classes
@@ -83,6 +85,7 @@ def __init__(
8385
self.definition_substitutions = definition_substitutions
8486
self.role = role
8587
self.type = state_machine_type
88+
self.tracing = tracing
8689
self.events = events
8790
self.event_resources = event_resources
8891
self.event_resolver = event_resolver
@@ -144,6 +147,7 @@ def to_cloudformation(self):
144147
self.state_machine.StateMachineName = self.name
145148
self.state_machine.StateMachineType = self.type
146149
self.state_machine.LoggingConfiguration = self.logging
150+
self.state_machine.TracingConfiguration = self.tracing
147151
self.state_machine.Tags = self._construct_tag_list()
148152

149153
event_resources = self._generate_event_resources()

samtranslator/model/stepfunctions/resources.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class StepFunctionsStateMachine(Resource):
1515
"StateMachineType": PropertyType(False, is_str()),
1616
"Tags": PropertyType(False, list_of(is_type(dict))),
1717
"DefinitionSubstitutions": PropertyType(False, is_type(dict)),
18+
"TracingConfiguration": PropertyType(False, is_type(dict)),
1819
}
1920

2021
runtime_attrs = {

tests/model/stepfunctions/test_state_machine_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def setUp(self):
2222
"definition_substitutions": None,
2323
"role": None,
2424
"state_machine_type": None,
25+
"tracing": None,
2526
"events": None,
2627
"event_resources": None,
2728
"event_resolver": None,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Resources:
2+
StateMachine:
3+
Type: AWS::Serverless::StateMachine
4+
Properties:
5+
Name: MyStateMachineWithXRayTracing
6+
Type: STANDARD
7+
DefinitionUri: s3://sam-demo-bucket/my-state-machine.asl.json
8+
Role: arn:aws:iam::123456123456:role/service-role/SampleRole
9+
Tracing:
10+
Enabled: true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Resources": {
3+
"StateMachine": {
4+
"Type": "AWS::StepFunctions::StateMachine",
5+
"Properties": {
6+
"Tags": [
7+
{
8+
"Value": "SAM",
9+
"Key": "stateMachine:createdBy"
10+
}
11+
],
12+
"RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole",
13+
"StateMachineName": "MyStateMachineWithXRayTracing",
14+
"TracingConfiguration": {
15+
"Enabled": true
16+
},
17+
"StateMachineType": "STANDARD",
18+
"DefinitionS3Location": {
19+
"Bucket": "sam-demo-bucket",
20+
"Key": "my-state-machine.asl.json"
21+
}
22+
}
23+
}
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Resources": {
3+
"StateMachine": {
4+
"Type": "AWS::StepFunctions::StateMachine",
5+
"Properties": {
6+
"Tags": [
7+
{
8+
"Value": "SAM",
9+
"Key": "stateMachine:createdBy"
10+
}
11+
],
12+
"RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole",
13+
"StateMachineName": "MyStateMachineWithXRayTracing",
14+
"TracingConfiguration": {
15+
"Enabled": true
16+
},
17+
"StateMachineType": "STANDARD",
18+
"DefinitionS3Location": {
19+
"Bucket": "sam-demo-bucket",
20+
"Key": "my-state-machine.asl.json"
21+
}
22+
}
23+
}
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Resources": {
3+
"StateMachine": {
4+
"Type": "AWS::StepFunctions::StateMachine",
5+
"Properties": {
6+
"Tags": [
7+
{
8+
"Value": "SAM",
9+
"Key": "stateMachine:createdBy"
10+
}
11+
],
12+
"RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole",
13+
"StateMachineName": "MyStateMachineWithXRayTracing",
14+
"TracingConfiguration": {
15+
"Enabled": true
16+
},
17+
"StateMachineType": "STANDARD",
18+
"DefinitionS3Location": {
19+
"Bucket": "sam-demo-bucket",
20+
"Key": "my-state-machine.asl.json"
21+
}
22+
}
23+
}
24+
}
25+
}

tests/translator/test_translator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class TestTranslatorEndToEnd(TestCase):
298298
"state_machine_with_api_resource_policy",
299299
"state_machine_with_api_auth_default_scopes",
300300
"state_machine_with_condition_and_events",
301+
"state_machine_with_xray",
301302
"function_with_file_system_config",
302303
],
303304
[

0 commit comments

Comments
 (0)