Skip to content

Commit b87f8c6

Browse files
jchrostek-ddclaude
andcommitted
fix(integration-tests): address review feedback
- Remove unused payload parsing in invoke.ts - Implement SLEEP_MS support in default handlers for trace isolation testing - Remove unused RETURN_REQUEST_ID env var from lmi.ts - Fix missing await in forceColdStart causing race condition - Fix grammar typo in datadog.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 861a1f9 commit b87f8c6

File tree

8 files changed

+39
-16
lines changed

8 files changed

+39
-16
lines changed

integration-tests/lambda/default-dotnet/Function.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Amazon.Lambda.Core;
2+
using System;
23
using System.Collections.Generic;
34
using System.Text.Json;
5+
using System.Threading;
46

57
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
68

@@ -12,6 +14,13 @@ public Dictionary<string, object> FunctionHandler(JsonElement input, ILambdaCont
1214
{
1315
context.Logger.LogLine("Hello world!");
1416

17+
var sleepMsStr = Environment.GetEnvironmentVariable("SLEEP_MS");
18+
if (!string.IsNullOrEmpty(sleepMsStr) && int.TryParse(sleepMsStr, out int sleepMs) && sleepMs > 0)
19+
{
20+
context.Logger.LogLine($"Sleeping for {sleepMs}ms");
21+
Thread.Sleep(sleepMs);
22+
}
23+
1524
var body = new Dictionary<string, object>
1625
{
1726
{ "message", "Success" },

integration-tests/lambda/default-java/src/main/java/example/Handler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ public class Handler implements RequestHandler<Map<String, Object>, Map<String,
1414
public Map<String, Object> handleRequest(Map<String, Object> event, Context context) {
1515
context.getLogger().log("Hello world!");
1616

17+
String sleepMsStr = System.getenv("SLEEP_MS");
18+
if (sleepMsStr != null && !sleepMsStr.isEmpty()) {
19+
try {
20+
int sleepMs = Integer.parseInt(sleepMsStr);
21+
if (sleepMs > 0) {
22+
context.getLogger().log("Sleeping for " + sleepMs + "ms");
23+
Thread.sleep(sleepMs);
24+
}
25+
} catch (InterruptedException e) {
26+
Thread.currentThread().interrupt();
27+
} catch (NumberFormatException e) {
28+
context.getLogger().log("Invalid SLEEP_MS value: " + sleepMsStr);
29+
}
30+
}
31+
1732
Map<String, Object> body = new HashMap<>();
1833
body.put("message", "Success");
1934
body.put("requestId", context.getAwsRequestId());

integration-tests/lambda/default-node/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
exports.handler = async (event, context) => {
22
console.log('Hello world!');
33

4+
const sleepMs = parseInt(process.env.SLEEP_MS || '0', 10);
5+
if (sleepMs > 0) {
6+
console.log(`Sleeping for ${sleepMs}ms`);
7+
await new Promise(resolve => setTimeout(resolve, sleepMs));
8+
}
9+
410
return {
511
statusCode: 200,
612
body: JSON.stringify({

integration-tests/lambda/default-python/lambda_function.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
22
import logging
3+
import os
4+
import time
35

46
logger = logging.getLogger()
57
logger.setLevel(logging.INFO)
@@ -8,6 +10,11 @@
810
def handler(event, context):
911
logger.info('Hello world!')
1012

13+
sleep_ms = int(os.environ.get('SLEEP_MS', '0'))
14+
if sleep_ms > 0:
15+
logger.info(f'Sleeping for {sleep_ms}ms')
16+
time.sleep(sleep_ms / 1000)
17+
1118
return {
1219
'statusCode': 200,
1320
'body': json.dumps({

integration-tests/lib/stacks/lmi.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class LambdaManagedInstancesStack extends cdk.Stack {
4141
DD_SERVICE: nodeFunctionName,
4242
DD_TRACE_ENABLED: 'true',
4343
DD_LAMBDA_HANDLER: 'index.handler',
44-
RETURN_REQUEST_ID: 'true',
4544
},
4645
logGroup: createLogGroup(this, nodeFunctionName)
4746
});
@@ -69,7 +68,6 @@ export class LambdaManagedInstancesStack extends cdk.Stack {
6968
DD_TRACE_ENABLED: 'true',
7069
DD_LAMBDA_HANDLER: 'lambda_function.handler',
7170
DD_TRACE_AGENT_URL: 'http://127.0.0.1:8126',
72-
RETURN_REQUEST_ID: 'true',
7371
},
7472
logGroup: createLogGroup(this, pythonFunctionName)
7573
});
@@ -96,7 +94,6 @@ export class LambdaManagedInstancesStack extends cdk.Stack {
9694
AWS_LAMBDA_EXEC_WRAPPER: '/opt/datadog_wrapper',
9795
DD_SERVICE: javaFunctionName,
9896
DD_TRACE_ENABLED: 'true',
99-
RETURN_REQUEST_ID: 'true',
10097
},
10198
logGroup: createLogGroup(this, javaFunctionName)
10299
});
@@ -123,7 +120,6 @@ export class LambdaManagedInstancesStack extends cdk.Stack {
123120
AWS_LAMBDA_EXEC_WRAPPER: '/opt/datadog_wrapper',
124121
DD_SERVICE: dotnetFunctionName,
125122
DD_TRACE_ENABLED: 'true',
126-
RETURN_REQUEST_ID: 'true',
127123
},
128124
logGroup: createLogGroup(this, dotnetFunctionName)
129125
});

integration-tests/tests/utils/datadog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function getTraces(
7070
requestId: string,
7171
): Promise<DatadogTrace[]> {
7272
const now = Date.now();
73-
const fromTime = now - (1 * 60 * 60 * 1000); // 1 hours ago
73+
const fromTime = now - (1 * 60 * 60 * 1000); // 1 hour ago
7474
const toTime = now;
7575
try {
7676
// Convert service name to lowercase as Datadog stores it that way

integration-tests/tests/utils/invoke.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ export async function invokeLambda(
2525
throw error;
2626
}
2727

28-
let responsePayload;
29-
try {
30-
responsePayload = JSON.parse(new TextDecoder().decode(response.Payload));
31-
console.log(`Response payload: ${JSON.stringify(responsePayload)}`);
32-
} catch (error: any) {
33-
console.error('Failed to parse response payload:', error.message);
34-
console.log('Raw payload:', new TextDecoder().decode(response.Payload));
35-
throw error;
36-
}
37-
3828
const requestId: string = response.$metadata.requestId || '';
3929

4030
return {

integration-tests/tests/utils/lambda.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { LambdaClient, UpdateFunctionConfigurationCommand, GetFunctionConfigurat
33
const lambdaClient = new LambdaClient({ region: 'us-east-1' });
44

55
export async function forceColdStart(functionName: string): Promise<void> {
6-
setTimestampEnvVar(functionName)
6+
await setTimestampEnvVar(functionName);
77
await new Promise(resolve => setTimeout(resolve, 10000));
88
}
99

0 commit comments

Comments
 (0)