Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update example doc to use DatadogLambda #289

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Aug 29, 2024

What does this PR do?

Make example code in README.md
to use:

  1. DatadogLambda instead of Datadog
  2. DatadogLambdaProps instead of DatadogProps

Motivation

The renaming is to make it cleaner to add DatadogStepFunction class later. Details in [RFC] Changing API for Datadog CDK Construct

Testing Guidelines

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

@lym953 lym953 requested review from a team as code owners August 29, 2024 21:47
@lym953 lym953 force-pushed the yiming.luo/step-function-refactor branch from feb86a7 to feb6e4f Compare September 4, 2024 20:03
Base automatically changed from yiming.luo/step-function-refactor to main September 9, 2024 17:04
@lym953 lym953 force-pushed the yiming.luo/step-function-refactor2 branch 2 times, most recently from 43990ce to 1fe6976 Compare October 16, 2024 18:17
@lym953 lym953 changed the title feat: update example code and doc to use DatadogLambda feat: update example doc to use DatadogLambda Oct 16, 2024
Comment on lines 8 to 40
export class CdkStepFunctionsTypeScriptStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

console.log("Creating Hello World TypeScript stack");

const helloLambdaFunction = new lambda.Function(this, "hello-python", {
runtime: lambda.Runtime.PYTHON_3_12,
timeout: Duration.seconds(10),
memorySize: 256,
code: lambda.Code.fromAsset("../lambda/python", {
bundling: {
image: lambda.Runtime.PYTHON_3_12.bundlingImage,
command: ["bash", "-c", "pip install -r requirements.txt -t /asset-output && cp -aT . /asset-output"],
},
}),
handler: "hello.lambda_handler",
});

const stateMachine = new sfn.StateMachine(this, "MyStateMachine", {
definitionBody: sfn.DefinitionBody.fromChainable(
new tasks.LambdaInvoke(this, "MyLambdaTask", {
lambdaFunction: helloLambdaFunction,
}).next(new sfn.Succeed(this, "GreetedWorld")),
),
});

console.log("Instrumenting Step Functions in TypeScript stack with Datadog");

const datadogSfn = new DatadogStepFunctions(this, "Datadog", {});
datadogSfn.addStateMachines([stateMachine]);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

This class is unnecessary (...read more)

This rule advises against the unnecessary use of classes that contain only static members, or nothing. In JavaScript, classes are primarily used for object-oriented programming, where each instance of a class has its own state and behavior. Static members, on the other hand, belong to the class itself and not to any instance of the class.

When a class contains only static members, it does not make use of JavaScript's object-oriented capabilities, and it can be more difficult to understand, test, and maintain than necessary. In order to avoid this issue, consider using regular functions and variables instead of static class members. This makes your code easier to understand and maintain, and it allows you to make better use of JavaScript's features.

View in Datadog  Leave us feedback  Documentation

@@ -97,3 +97,5 @@ export interface Node {
}

export type LambdaFunction = lambda.Function | lambda.SingletonFunction;

export interface DatadogStepFunctionsProps {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

An empty interface is equivalent to `{}`. (...read more)

Do not use empty interfaces.

View in Datadog  Leave us feedback  Documentation

import { CdkStepFunctionsTypeScriptStack } from "../lib/cdk-step-functions-typescript-stack";

const app = new cdk.App();
new CdkStepFunctionsTypeScriptStack(app, "CdkStepFunctionsTypeScriptStack", {});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Do not use 'new' for side effects. (...read more)

A lonely instance is almost always useless. Do not create objects without assigning them to a variable that you will use later.

View in Datadog  Leave us feedback  Documentation

),
});

console.log("Instrumenting Step Functions in TypeScript stack with Datadog");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unexpected console statement. (...read more)

Debugging with console is not considered a bad practice, but it's easy to forget about console statements and leave them in production code. There is no need to pollute production builds with debugging statements.

View in Datadog  Leave us feedback  Documentation

constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

console.log("Creating Hello World TypeScript stack");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unexpected console statement. (...read more)

Debugging with console is not considered a bad practice, but it's easy to forget about console statements and leave them in production code. There is no need to pollute production builds with debugging statements.

View in Datadog  Leave us feedback  Documentation

this.props = props;
}

public addStateMachines(_stateMachines: sfn.StateMachine[], _construct?: Construct): void {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Code Quality Violation

Suggested change
public addStateMachines(_stateMachines: sfn.StateMachine[], _construct?: Construct): void {}
public addStateMachines(_stateMachines: sfn.StateMachine[], _construct?: Construct): void {/* empty */}
Empty statement. (...read more)

Empty or non-functional blocks in the code can be misleading and lead to maintenance difficulties. They can also lead to a false sense of security or functionality. While they may not directly introduce security issues, their presence can suggest that some logic or error handling is implemented when it is not.

View in Datadog  Leave us feedback  Documentation

@lym953 lym953 force-pushed the yiming.luo/step-function-refactor2 branch from 329adc6 to 75d532f Compare October 17, 2024 18:10
@lym953 lym953 merged commit fbf5c43 into main Oct 17, 2024
10 checks passed
@lym953 lym953 deleted the yiming.luo/step-function-refactor2 branch October 17, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants