Skip to content

Commit a85263a

Browse files
committed
add java and python
1 parent 5ad68e5 commit a85263a

18 files changed

Lines changed: 507 additions & 68 deletions

integration-tests/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,19 @@ Thumbs.db
3838
# Lambda artifacts
3939
response.json
4040
lambda-bundle.zip
41+
42+
# Java build artifacts
43+
lambda/base-java/target/
44+
lambda/base-java/?/
45+
lambda/base-java/.mvn/
46+
lambda/base-java/mvnw
47+
lambda/base-java/mvnw.cmd
48+
lambda/**/target/
49+
lambda/**/?/
50+
lambda/**/.mvn/
51+
lambda/**/mvnw
52+
lambda/**/mvnw.cmd
53+
lambda/**/*.class
54+
lambda/**/.classpath
55+
lambda/**/.project
56+
lambda/**/.settings/

integration-tests/bin/app.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import 'source-map-support/register';
33
import * as cdk from 'aws-cdk-lib';
44
import * as os from 'os';
55
import { BaseNodeStack } from '../lib/stacks/base-node-stack';
6+
import { BasePythonStack } from '../lib/stacks/base-python-stack';
7+
import { BaseJavaStack } from '../lib/stacks/base-java-stack';
8+
import { DynamicInstrumentationPythonStack } from '../lib/stacks/dynamic-instrumentation-python-stack';
69

710
const app = new cdk.App();
811

@@ -40,4 +43,16 @@ new BaseNodeStack(app, `integ-${identifier}-base-node`, {
4043
env,
4144
});
4245

46+
new BasePythonStack(app, `integ-${identifier}-base-python`, {
47+
env,
48+
});
49+
50+
new BaseJavaStack(app, `integ-${identifier}-base-java`, {
51+
env,
52+
});
53+
54+
new DynamicInstrumentationPythonStack(app, `integ-${identifier}-dynamic-instrumentation-python`, {
55+
env,
56+
});
57+
4358
app.synth();
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.datadog</groupId>
7+
<artifactId>base-java-lambda</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.amazonaws</groupId>
20+
<artifactId>aws-lambda-java-core</artifactId>
21+
<version>1.2.3</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.amazonaws</groupId>
25+
<artifactId>aws-lambda-java-log4j2</artifactId>
26+
<version>1.6.0</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.apache.logging.log4j</groupId>
30+
<artifactId>log4j-core</artifactId>
31+
<version>2.23.1</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.logging.log4j</groupId>
35+
<artifactId>log4j-api</artifactId>
36+
<version>2.23.1</version>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-shade-plugin</artifactId>
45+
<version>3.5.1</version>
46+
<configuration>
47+
<createDependencyReducedPom>false</createDependencyReducedPom>
48+
</configuration>
49+
<executions>
50+
<execution>
51+
<phase>package</phase>
52+
<goals>
53+
<goal>shade</goal>
54+
</goals>
55+
</execution>
56+
</executions>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import com.amazonaws.services.lambda.runtime.Context;
2+
import com.amazonaws.services.lambda.runtime.RequestHandler;
3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
5+
6+
import java.util.Map;
7+
import java.util.HashMap;
8+
9+
public class Handler implements RequestHandler<Map<String, Object>, Map<String, Object>> {
10+
private static final Logger logger = LogManager.getLogger(Handler.class);
11+
12+
@Override
13+
public Map<String, Object> handleRequest(Map<String, Object> event, Context context) {
14+
logger.info("Hello world!");
15+
16+
Map<String, Object> response = new HashMap<>();
17+
response.put("statusCode", 200);
18+
return response;
19+
}
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import logging
2+
3+
logger = logging.getLogger()
4+
logger.setLevel(logging.INFO)
5+
6+
def handler(event, context):
7+
logger.info('Hello world!')
8+
return {
9+
'statusCode': 200
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No additional requirements needed - datadog-lambda layer provides dependencies
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import logging
2+
3+
logger = logging.getLogger()
4+
logger.setLevel(logging.INFO)
5+
6+
def handler(event, context):
7+
logger.info('Dynamic instrumentation test function.')
8+
result = process_data(event)
9+
return {
10+
'statusCode': 200,
11+
'body': result
12+
}
13+
14+
def process_data(data):
15+
value = data.get('value', 0)
16+
logger.info(f'Processing data with value: {value}')
17+
multiplied = value * 2
18+
return f'Processed: {multiplied}'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No additional requirements needed - datadog-lambda layer provides dependencies
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as lambda from 'aws-cdk-lib/aws-lambda';
3+
import { Construct } from 'constructs';
4+
import { createLogGroup, defaultDatadogEnvVariables, defaultDatadogSecretPolicy, getExtensionLayer } from '../util';
5+
6+
export class BaseJavaStack extends cdk.Stack {
7+
constructor(scope: Construct, id: string, props: cdk.StackProps) {
8+
super(scope, id, props);
9+
10+
const javaFunctionName = `${id}-lambda`;
11+
12+
const javaFunction = new lambda.Function(this, javaFunctionName, {
13+
runtime: lambda.Runtime.JAVA_11,
14+
architecture: lambda.Architecture.ARM_64,
15+
handler: 'Handler::handleRequest',
16+
code: lambda.Code.fromAsset('./lambda/base-java', {
17+
bundling: {
18+
image: lambda.Runtime.JAVA_11.bundlingImage,
19+
command: [
20+
'/bin/sh',
21+
'-c',
22+
'cd /asset-input && mvn clean package && cd /asset-output && unzip /asset-input/target/base-java-lambda-1.0.0.jar'
23+
]
24+
}
25+
}),
26+
functionName: javaFunctionName,
27+
timeout: cdk.Duration.seconds(30),
28+
memorySize: 512,
29+
environment: {
30+
...defaultDatadogEnvVariables,
31+
DD_SERVICE: javaFunctionName,
32+
DD_TRACE_ENABLED: 'true',
33+
DD_LOG_LEVEL: 'debug',
34+
DD_TRACE_AGENT_URL: 'http://127.0.0.1:8126',
35+
},
36+
logGroup: createLogGroup(this, javaFunctionName)
37+
});
38+
39+
javaFunction.addToRolePolicy(defaultDatadogSecretPolicy);
40+
javaFunction.addLayers(getExtensionLayer(this));
41+
}
42+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as lambda from 'aws-cdk-lib/aws-lambda';
3+
import { Construct } from 'constructs';
4+
import { createLogGroup, defaultDatadogEnvVariables, defaultDatadogSecretPolicy, getExtensionLayer, getPython313Layer } from '../util';
5+
6+
export class BasePythonStack extends cdk.Stack {
7+
constructor(scope: Construct, id: string, props: cdk.StackProps) {
8+
super(scope, id, props);
9+
10+
const pythonFunctionName = `${id}-lambda`
11+
const pythonFunction = new lambda.Function(this, pythonFunctionName, {
12+
runtime: lambda.Runtime.PYTHON_3_13,
13+
architecture: lambda.Architecture.ARM_64,
14+
handler: 'datadog_lambda.handler.handler',
15+
code: lambda.Code.fromAsset('./lambda/base-python'),
16+
functionName: pythonFunctionName,
17+
timeout: cdk.Duration.seconds(30),
18+
memorySize: 256,
19+
environment: {
20+
...defaultDatadogEnvVariables,
21+
DD_SERVICE: pythonFunctionName,
22+
DD_TRACE_ENABLED: 'true',
23+
DD_LAMBDA_HANDLER: 'lambda_function.handler',
24+
DD_LOG_LEVEL: 'debug',
25+
DD_TRACE_AGENT_URL: 'http://127.0.0.1:8126',
26+
DD_COLD_START_TRACING: 'true',
27+
DD_MIN_COLD_START_DURATION: '0',
28+
},
29+
logGroup: createLogGroup(this, pythonFunctionName)
30+
});
31+
pythonFunction.addToRolePolicy(defaultDatadogSecretPolicy)
32+
pythonFunction.addLayers(getExtensionLayer(this));
33+
pythonFunction.addLayers(getPython313Layer(this));
34+
}
35+
}

0 commit comments

Comments
 (0)