Skip to content

Commit 1cceed6

Browse files
committed
feat: Support both Lambda APIs in the example Go stack
1 parent 7d27646 commit 1cceed6

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

examples/go-stack/app.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,38 @@ func NewAppStackWithoutDatadog(scope constructs.Construct, id *string, props *Ap
4848
return stack, myFunction
4949
}
5050

51-
// Creates a stack with Datadog integration set up
52-
func NewAppStackWithDatadog(scope constructs.Construct, id string, props *AppStackProps) awscdk.Stack {
51+
// Creates a stack with Datadog integration set up, using the new API (DatadogLambda, DatadogLambdaProps)
52+
func NewAppStackWithDatadogLambda(scope constructs.Construct, id string, props *AppStackProps) awscdk.Stack {
53+
stack, lambdaFunction := NewAppStackWithoutDatadog(scope, &id, props)
54+
55+
// Set up Datadog integration
56+
datadog := ddcdkconstruct.NewDatadogLambda(
57+
stack,
58+
jsii.String("Datadog"),
59+
&ddcdkconstruct.DatadogLambdaProps{
60+
NodeLayerVersion: jsii.Number(113),
61+
PythonLayerVersion: jsii.Number(97),
62+
JavaLayerVersion: jsii.Number(21),
63+
DotnetLayerVersion: jsii.Number(15),
64+
AddLayers: jsii.Bool(true),
65+
ExtensionLayerVersion: jsii.Number(62),
66+
FlushMetricsToLogs: jsii.Bool(true),
67+
Site: jsii.String("datadoghq.com"),
68+
ApiKey: jsii.String(os.Getenv("DD_API_KEY")),
69+
EnableDatadogTracing: jsii.Bool(true),
70+
EnableMergeXrayTraces: jsii.Bool(true),
71+
EnableDatadogLogs: jsii.Bool(true),
72+
InjectLogContext: jsii.Bool(true),
73+
LogLevel: jsii.String("debug"),
74+
})
75+
datadog.AddLambdaFunctions(&[]interface{}{lambdaFunction}, nil)
76+
77+
return stack
78+
}
79+
80+
// Creates a stack with Datadog integration set up, using the old API (Datadog, DatadogLambda)
81+
// It is just to ensure backward compatibility. Users are recommended to use the new API.
82+
func NewAppStackWithDatadogOldApi(scope constructs.Construct, id string, props *AppStackProps) awscdk.Stack {
5383
stack, lambdaFunction := NewAppStackWithoutDatadog(scope, &id, props)
5484

5585
// Set up Datadog integration
@@ -82,7 +112,13 @@ func main() {
82112

83113
app := awscdk.NewApp(nil)
84114

85-
NewAppStackWithDatadog(app, "AppStack", &AppStackProps{
115+
NewAppStackWithDatadogLambda(app, "CdkGoStack", &AppStackProps{
116+
awscdk.StackProps{
117+
Env: env(),
118+
},
119+
})
120+
121+
NewAppStackWithDatadogOldApi(app, "CdkGoLambdaOldApiStack", &AppStackProps{
86122
awscdk.StackProps{
87123
Env: env(),
88124
},

0 commit comments

Comments
 (0)