Skip to content

Commit 7fc392d

Browse files
Merge pull request #374 from hassaku63/feature/x-ray
feat: X-Ray tracing support for state machine
2 parents 4c6fb92 + 0d42f90 commit 7fc392d

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This is the Serverless Framework plugin for AWS Step Functions.
1818
- [Pre-deployment validation](#pre-deployment-validation)
1919
- [Express Workflow](#express-workflow)
2020
- [CloudWatch Logs](#cloudwatch-logs)
21+
- [X-Ray](#x-ray)
2122
- [Current Gotcha](#current-gotcha)
2223
- [Events](#events)
2324
- [API Gateway](#api-gateway)
@@ -407,6 +408,18 @@ stepFunctions:
407408
- Fn::GetAtt: [MyLogGroup, Arn]
408409
```
409410

411+
### X-Ray
412+
413+
You can enable X-Ray for your state machine, specify `tracingConfig` as shown below.
414+
415+
```yaml
416+
stepFunctions:
417+
stateMachines:
418+
hellostepfunc1:
419+
tracingConfig:
420+
enabled: true
421+
```
422+
410423
## Current Gotcha
411424

412425
Please keep this gotcha in mind if you want to reference the `name` from the `resources` section. To generate Logical ID for CloudFormation, the plugin transforms the specified name in serverless.yml based on the following scheme.

lib/deploy/stepFunctions/compileStateMachines.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ module.exports = {
9999
let RoleArn;
100100
let DependsOn = [];
101101
let LoggingConfiguration;
102+
let TracingConfiguration;
102103
let Tags;
103104
if (stateMachineObj.inheritGlobalTags === false) {
104105
Tags = [];
@@ -204,6 +205,11 @@ module.exports = {
204205
};
205206
}
206207

208+
if (value.tracingConfig) {
209+
TracingConfiguration = {
210+
Enabled: value.tracingConfig.enabled,
211+
};
212+
}
207213

208214
const stateMachineOutputLogicalId = this
209215
.getStateMachineOutputLogicalId(stateMachineName, stateMachineObj);
@@ -215,6 +221,7 @@ module.exports = {
215221
RoleArn,
216222
StateMachineType: stateMachineObj.type,
217223
LoggingConfiguration,
224+
TracingConfiguration,
218225
},
219226
DependsOn,
220227
};

lib/deploy/stepFunctions/compileStateMachines.schema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const loggingConfig = Joi.object().keys({
3434
destinations: Joi.array().items(arn),
3535
});
3636

37+
const tracingConfig = Joi.object().keys({
38+
enabled: Joi.boolean().default(false),
39+
});
40+
3741
const id = Joi.string();
3842
const tags = Joi.object();
3943
const name = Joi.string();
@@ -58,6 +62,7 @@ const schema = Joi.object().keys({
5862
type,
5963
retain,
6064
loggingConfig,
65+
tracingConfig,
6166
inheritGlobalTags,
6267
});
6368

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,42 @@ describe('#compileStateMachines', () => {
14341434
});
14351435
});
14361436

1437+
it('should compile tracing configuration', () => {
1438+
serverless.service.stepFunctions = {
1439+
stateMachines: {
1440+
myStateMachine1: {
1441+
name: 'stateMachineBeta1',
1442+
tracingConfig: {
1443+
enabled: true,
1444+
},
1445+
definition: {
1446+
StartAt: 'A',
1447+
States: {
1448+
A: {
1449+
Type: 'Task',
1450+
Resource: 'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello',
1451+
End: true,
1452+
},
1453+
},
1454+
},
1455+
},
1456+
},
1457+
};
1458+
1459+
serverlessStepFunctions.compileStateMachines();
1460+
const actual = serverlessStepFunctions
1461+
.serverless
1462+
.service
1463+
.provider
1464+
.compiledCloudFormationTemplate
1465+
.Resources
1466+
.StateMachineBeta1
1467+
.Properties;
1468+
1469+
expect(actual).to.haveOwnProperty('TracingConfiguration');
1470+
expect(actual.TracingConfiguration.Enabled).to.equal(true);
1471+
});
1472+
14371473
it('should output cloudformation outputs section', () => {
14381474
serverless.service.stepFunctions = {
14391475
stateMachines: {

0 commit comments

Comments
 (0)