Skip to content

Commit

Permalink
chore: rename Lambda related interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lym953 committed Oct 11, 2024
1 parent ba9f865 commit 94ff02b
Show file tree
Hide file tree
Showing 20 changed files with 1,021 additions and 114 deletions.
42 changes: 39 additions & 3 deletions examples/go-stack/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,38 @@ func NewAppStackWithoutDatadog(scope constructs.Construct, id *string, props *Ap
return stack, myFunction
}

// Creates a stack with Datadog integration set up
func NewAppStackWithDatadog(scope constructs.Construct, id string, props *AppStackProps) awscdk.Stack {
// Creates a stack with Datadog integration set up, using the new API (DatadogLambda, DatadogLambdaProps)
func NewAppStackWithDatadogLambda(scope constructs.Construct, id string, props *AppStackProps) awscdk.Stack {
stack, lambdaFunction := NewAppStackWithoutDatadog(scope, &id, props)

// Set up Datadog integration
datadog := ddcdkconstruct.NewDatadogLambda(
stack,
jsii.String("Datadog"),
&ddcdkconstruct.DatadogLambdaProps{
NodeLayerVersion: jsii.Number(113),
PythonLayerVersion: jsii.Number(97),
JavaLayerVersion: jsii.Number(21),
DotnetLayerVersion: jsii.Number(15),
AddLayers: jsii.Bool(true),
ExtensionLayerVersion: jsii.Number(62),
FlushMetricsToLogs: jsii.Bool(true),
Site: jsii.String("datadoghq.com"),
ApiKey: jsii.String(os.Getenv("DD_API_KEY")),
EnableDatadogTracing: jsii.Bool(true),
EnableMergeXrayTraces: jsii.Bool(true),
EnableDatadogLogs: jsii.Bool(true),
InjectLogContext: jsii.Bool(true),
LogLevel: jsii.String("debug"),
})
datadog.AddLambdaFunctions(&[]interface{}{lambdaFunction}, nil)

return stack
}

// Creates a stack with Datadog integration set up, using the old API (Datadog, DatadogProps) to ensure
// backward compatibility. Users are recommended to use the new API.
func NewAppStackWithDatadogOldApi(scope constructs.Construct, id string, props *AppStackProps) awscdk.Stack {
stack, lambdaFunction := NewAppStackWithoutDatadog(scope, &id, props)

// Set up Datadog integration
Expand Down Expand Up @@ -82,7 +112,13 @@ func main() {

app := awscdk.NewApp(nil)

NewAppStackWithDatadog(app, "AppStack", &AppStackProps{
NewAppStackWithDatadogLambda(app, "CdkGoStack", &AppStackProps{
awscdk.StackProps{
Env: env(),
},
})

NewAppStackWithDatadogOldApi(app, "CdkGoLambdaOldApiStack", &AppStackProps{
awscdk.StackProps{
Env: env(),
},
Expand Down
2 changes: 2 additions & 0 deletions examples/python-stack/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
from aws_cdk import App
from cdk_python.cdk_python_stack import CdkPythonStack
from cdk_python.cdk_python_lambda_old_api_stack import CdkPythonLambdaOldApiStack

app = App()
CdkPythonStack(app, "CdkPythonStack")
CdkPythonLambdaOldApiStack(app, "CdkPythonLambdaOldApiStack")

app.synth()
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from constructs import Construct
from datadog_cdk_constructs_v2 import Datadog, DatadogProps
import os
from cdk_python.cdk_python_stack_base import CdkPythonStackBase

class CdkPythonLambdaOldApiStack(CdkPythonStackBase):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)

datadog = Datadog(
self,
"Datadog",
dotnet_layer_version=15,
node_layer_version=107,
python_layer_version=89,
extension_layer_version=55,
add_layers=True,
api_key=os.getenv("DD_API_KEY"),
enable_datadog_tracing=True,
enable_datadog_asm=True,
flush_metrics_to_logs=True,
site="datadoghq.com",
)

# Ensure DatadogProps can be imported properly
props = DatadogProps()
datadog.add_lambda_functions(self.lambdaFunctions)
10 changes: 5 additions & 5 deletions examples/python-stack/cdk_python/cdk_python_stack.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from constructs import Construct
from datadog_cdk_constructs_v2 import Datadog, DatadogProps
from datadog_cdk_constructs_v2 import DatadogLambda, DatadogLambdaProps
import os
from cdk_python.cdk_python_stack_base import CdkPythonStackBase

class CdkPythonStack(CdkPythonStackBase):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)

datadog = Datadog(
datadog = DatadogLambda(
self,
"Datadog",
dotnet_layer_version=15,
Expand All @@ -22,6 +22,6 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
site="datadoghq.com",
)

# Ensure DatadogProps can be imported properly
props = DatadogProps()
# Ensure DatadogLambdaProps can be imported properly
props = DatadogLambdaProps()
datadog.add_lambda_functions(self.lambdaFunctions)
2 changes: 2 additions & 0 deletions examples/typescript-stack/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env node
import * as cdk from "aws-cdk-lib";
import { CdkTypeScriptStack } from "../lib/cdk-typescript-stack";
import { CdkTypeScriptLambdaOldApiStack } from "../lib/cdk-typescript-lambda-old-api-stack";

const app = new cdk.App();
new CdkTypeScriptStack(app, "CdkTypeScriptStack", {});
new CdkTypeScriptLambdaOldApiStack(app, "CdkTypeScriptLambdaOldApiStack", {});
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import { Datadog, DatadogProps } from "datadog-cdk-constructs-v2";
import { CdkTypeScriptStackBase } from "./cdk-typescript-stack-base";

export class CdkTypeScriptLambdaOldApiStack extends CdkTypeScriptStackBase {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

console.log("Instrumenting Lambda Functions in TypeScript stack using the old Datadog Lambda API");

const datadogProps: DatadogProps = {
dotnetLayerVersion: 15,
nodeLayerVersion: 108,
pythonLayerVersion: 89,
extensionLayerVersion: 55,
addLayers: true,
apiKey: process.env.DD_API_KEY,
enableDatadogTracing: true,
enableDatadogASM: true,
flushMetricsToLogs: true,
site: "datadoghq.com",
};

const datadog = new Datadog(this, "Datadog", datadogProps);

datadog.addLambdaFunctions(this.lambdaFunctions);
}
}
2 changes: 1 addition & 1 deletion examples/typescript-stack/lib/cdk-typescript-stack-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Function } from "aws-cdk-lib/aws-lambda";
import { HttpLambdaIntegration } from "aws-cdk-lib/aws-apigatewayv2-integrations";
import { Construct } from "constructs";

export class CdkTypeScriptStackBase extends Stack {
export abstract class CdkTypeScriptStackBase extends Stack {
protected lambdaFunctions: lambda.Function[];
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
Expand Down
6 changes: 3 additions & 3 deletions examples/typescript-stack/lib/cdk-typescript-stack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import { Datadog, DatadogProps } from "datadog-cdk-constructs-v2";
import { DatadogLambda, DatadogLambdaProps } from "datadog-cdk-constructs-v2";
import { CdkTypeScriptStackBase } from "./cdk-typescript-stack-base";

export class CdkTypeScriptStack extends CdkTypeScriptStackBase {
Expand All @@ -9,7 +9,7 @@ export class CdkTypeScriptStack extends CdkTypeScriptStackBase {

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

const datadogProps: DatadogProps = {
const datadogLambdaProps: DatadogLambdaProps = {
dotnetLayerVersion: 15,
nodeLayerVersion: 108,
pythonLayerVersion: 89,
Expand All @@ -22,7 +22,7 @@ export class CdkTypeScriptStack extends CdkTypeScriptStackBase {
site: "datadoghq.com",
};

const datadog = new Datadog(this, "Datadog", datadogProps);
const datadog = new DatadogLambda(this, "Datadog", datadogLambdaProps);

datadog.addLambdaFunctions(this.lambdaFunctions);
}
Expand Down
Loading

0 comments on commit 94ff02b

Please sign in to comment.