diff --git a/src/datadog-step-functions.ts b/src/datadog-step-functions.ts index 5e8a0091..f619187e 100644 --- a/src/datadog-step-functions.ts +++ b/src/datadog-step-functions.ts @@ -147,7 +147,7 @@ export class DatadogStepFunctions extends Construct { throw new Error(`logGroupArn is undefined. ${unsupportedCaseErrorMessage}`); } - logGroup = logs.LogGroup.fromLogGroupArn(this, "LogGroup", logGroupArn); + logGroup = logs.LogGroup.fromLogGroupArn(stateMachine, "LogGroup", logGroupArn); } // Configure state machine role to have permission to log to CloudWatch Logs, following diff --git a/test/datadog-step-functions.spec.ts b/test/datadog-step-functions.spec.ts index cb07bfc8..aca40d15 100644 --- a/test/datadog-step-functions.spec.ts +++ b/test/datadog-step-functions.spec.ts @@ -42,6 +42,32 @@ describe("DatadogStepFunctions", () => { expect(logConfig.destinations).toHaveLength(1); }); + it("supports multiple state machines with pre-existing, distinct log groups", () => { + const stack = new Stack(); + const stateMachineOne = new sfn.StateMachine(stack, "StateMachineOne", { + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Pass(stack, "PassStateOne")), + logs: { + destination: new logs.LogGroup(stack, "LogGroupOne"), + level: sfn.LogLevel.ERROR, + includeExecutionData: false, + }, + }); + const stateMachineTwo = new sfn.StateMachine(stack, "StateMachineTwo", { + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Pass(stack, "PassStateTwo")), + logs: { + destination: new logs.LogGroup(stack, "LogGroupTwo"), + level: sfn.LogLevel.ERROR, + includeExecutionData: false, + }, + }); + + const datadogSfn = new DatadogStepFunctions(stack, "DatadogStepFunctions", {}); + expect(() => { + datadogSfn.addStateMachines([stateMachineOne]); + datadogSfn.addStateMachines([stateMachineTwo]); + }).not.toThrow(); + }); + it("throws if loggingConfiguration is an unresolved token", () => { const stack = new Stack(); const stateMachine = new sfn.StateMachine(stack, "StateMachine", {