Skip to content

Commit

Permalink
[mq] working branch - merge d3d78c9 on top of main at 405d5b4
Browse files Browse the repository at this point in the history
{"baseBranch":"main","baseCommit":"405d5b47fd6dd6302c028294dc93bd42ce02242b","createdAt":"2024-11-25T22:05:23.073032Z","headSha":"d3d78c962cfaad7c4e77943aa4ef3a34a291a3a9","id":"0fe4a5ac-d537-439c-9f79-b7057bc57fd2","priority":"200","pullRequestNumber":"340","queuedAt":"2024-11-25T22:05:23.072472Z","status":"STATUS_QUEUED"}
  • Loading branch information
dd-mergequeue[bot] authored Nov 25, 2024
2 parents 7a3094d + d3d78c9 commit 47b881b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/datadog-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class DatadogLambda extends Construct {
transport: Transport;

constructor(scope: Construct, id: string, props: DatadogLambdaProps) {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() === "true") {
log.setLevel("debug");
}
super(scope, id);
Expand Down
13 changes: 13 additions & 0 deletions src/datadog-step-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ Please open a feature request in https://github.com/DataDog/datadog-cdk-construc

export class DatadogStepFunctions extends Construct {
public static buildLambdaPayloadToMergeTraces(payload: { [key: string]: any } = {}): { [key: string]: any } {
log.debug(`Building lambda payload to merge traces`);
return buildStepFunctionLambdaTaskPayloadToMergeTraces(payload);
}

public static buildStepFunctionTaskInputToMergeTraces(input: { [key: string]: any } = {}): {
[key: string]: any;
} {
log.debug(`Building step function task input to merge traces`);
return buildStepFunctionSfnExecutionTaskInputToMergeTraces(input);
}

Expand All @@ -40,6 +42,10 @@ export class DatadogStepFunctions extends Construct {
stack: Stack;

constructor(scope: Construct, id: string, props: DatadogStepFunctionsProps) {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() === "true") {
log.setLevel("debug");
}

super(scope, id);
this.scope = scope;
this.props = props;
Expand All @@ -53,6 +59,8 @@ export class DatadogStepFunctions extends Construct {
}

private addStateMachine(stateMachine: sfn.StateMachine, _construct?: Construct) {
log.debug(`\nInstrumenting state machine ${stateMachine.node.path}`);

const logGroup = this.setUpLogging(stateMachine);

if (this.props.forwarderArn !== undefined) {
Expand Down Expand Up @@ -84,6 +92,7 @@ export class DatadogStepFunctions extends Construct {
}

// Set log level and includeExecutionData
log.debug(`Setting log level to ALL`);
cfnStateMachine.loggingConfiguration = {
...cfnStateMachine.loggingConfiguration,
level: "ALL",
Expand All @@ -93,6 +102,7 @@ export class DatadogStepFunctions extends Construct {
let logGroup: logs.ILogGroup;
// Set destination log group if not set
if (!cfnStateMachine.loggingConfiguration.destinations) {
log.debug(`Logging destination is not set. Creating a new log group.`);
const logGroupName = buildLogGroupName(stateMachine, this.props.env);
logGroup = new logs.LogGroup(stateMachine, "LogGroup", {
retention: logs.RetentionDays.ONE_WEEK,
Expand All @@ -110,6 +120,7 @@ export class DatadogStepFunctions extends Construct {
],
};
} else {
log.debug(`Logging destination is already set. Extracting log group ARN.`);
// Extract log group from logging config
const destinations = cfnStateMachine.loggingConfiguration.destinations;
if (!this.isLogDestinationPropertyArray(destinations)) {
Expand All @@ -131,6 +142,7 @@ export class DatadogStepFunctions extends Construct {
}

const logGroupArn = logGroupConfig.logGroupArn;
log.debug(`Extracted log group ARN: ${logGroupArn}`);
if (logGroupArn === undefined) {
throw new Error(`logGroupArn is undefined. ${unsupportedCaseErrorMessage}`);
}
Expand All @@ -140,6 +152,7 @@ export class DatadogStepFunctions extends Construct {

// Configure state machine role to have permission to log to CloudWatch Logs, following
// https://docs.aws.amazon.com/step-functions/latest/dg/cw-logs.html#cloudwatch-iam-policy
log.debug(`Adding permissions to the state machine role to log to CloudWatch Logs`);
stateMachine.role.addToPrincipalPolicy(
new iam.PolicyStatement({
actions: [
Expand Down

0 comments on commit 47b881b

Please sign in to comment.