Skip to content

add datadog exampes #602

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

Merged
merged 4 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/datadog-zip/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cdk.out
node_modules
53 changes: 53 additions & 0 deletions examples/datadog-zip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Datadog support for Lambda Web Adapter

This folder contains examples using Lambda Web Adapter and Datadog instrumentation in nodejs (expressjs) using a zipfile and layers instead of a container.

The examples use aws cdk to deploy and curl to test, so make sure they are installed.

# How to use

Instructions are for expressjs

## Install dependencies

Install aws cdk dependencies

```sh
cd expressjs/cdk
npm i
cd -
```

## Deploy and Run

Deploy with

```sh
cd expressjs/cdk
cdk deploy
cd -
```

After confirming the deployment, a log will show a public Lambda URL to invoke the endpoint with

```sh
Outputs:
lwa-stack.LambdaFunctionUrl = https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.lambda-url.us-east-1.on.aws/
```

and the function can be invoked with (note the call_lwa at the end of the URL)

```sh
curl https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.lambda-url.us-east-1.on.aws/call_lwa
```

NB
this deployment will create a publicly accessible URL link with no security restriction and usage limits! Make sure to run

```sh
cd expressjs/cdk
cdk destroy
cd -
```

after the example test is done
14 changes: 14 additions & 0 deletions examples/datadog-zip/expressjs/cdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Welcome to your CDK TypeScript project

This is a blank project for CDK development with TypeScript.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

## Useful commands

* `npm run build` compile typescript to js
* `npm run watch` watch for changes and compile
* `npm run test` perform the jest unit tests
* `npx cdk deploy` deploy this stack to your default AWS account/region
* `npx cdk diff` compare deployed stack with current state
* `npx cdk synth` emits the synthesized CloudFormation template
55 changes: 55 additions & 0 deletions examples/datadog-zip/expressjs/cdk/app/cdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { App, CfnOutput, Duration, Stack, StackProps } from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";

import { FunctionUrlAuthType, Code } from "aws-cdk-lib/aws-lambda";
import * as path from "path";

const app = new App();

class LwaStack extends Stack {
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);

const lwa_lambda = new lambda.Function(this, id, {
code: Code.fromAsset(path.join(__dirname, "../../lambda-asset/src")),
runtime: lambda.Runtime.NODEJS_20_X,
handler: "run.sh",
functionName: id + "-lambda",
timeout: Duration.seconds(9),
});

const functionUrl = lwa_lambda.addFunctionUrl({
authType: FunctionUrlAuthType.NONE,
});

new CfnOutput(this, "LambdaFunctionUrl", {
value: functionUrl.url,
description: "The Lambda Function URL",
});

lwa_lambda.addEnvironment(
"AWS_LWA_LAMBDA_RUNTIME_API_PROXY",
"127.0.0.1:9002",
);

lwa_lambda.addEnvironment("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS", "1");
lwa_lambda.addEnvironment("DD_TRACE_PARTIAL_FLUSH_ENABLED", "false");
lwa_lambda.addEnvironment("DD_API_KEY", process.env.DD_API_KEY || "");
lwa_lambda.addEnvironment("DD_SERVICE", id);
lwa_lambda.addEnvironment("AWS_LAMBDA_EXEC_WRAPPER", "/opt/bootstrap");

const lwa_lambda_layer = lambda.LayerVersion.fromLayerVersionArn(
this,
"lwa_lambda-layer",
"arn:aws:lambda:us-east-1:753240598075:layer:LambdaAdapterLayerX86:25",
);
const dd_layer = lambda.LayerVersion.fromLayerVersionArn(
this,
"lwa_lambda-dd-layer",
"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:77",
);
lwa_lambda.addLayers(lwa_lambda_layer, dd_layer);
}
}

new LwaStack(app, "lwa-stack", {});
5 changes: 5 additions & 0 deletions examples/datadog-zip/expressjs/cdk/cdk.context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"acknowledged-issue-numbers": [
32775
]
}
73 changes: 73 additions & 0 deletions examples/datadog-zip/expressjs/cdk/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"app": "npx ts-node --prefer-ts-exts app/cdk.ts",
"watch": {
"include": ["**"],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false,
"@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true,
"@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true,
"@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true,
"@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true,
"@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true,
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true
}
}
8 changes: 8 additions & 0 deletions examples/datadog-zip/expressjs/cdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
Loading
Loading