Skip to content

Commit 841f748

Browse files
committed
feat(otel): Add X-Ray e2e integration tests for span validation
1 parent 78987e9 commit 841f748

8 files changed

Lines changed: 535 additions & 5 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,44 @@ jobs:
6666
cache: maven
6767
- name: Build locally
6868
run: mvn -B -q -Dmaven.test.skip=true install --file pom.xml
69+
- name: Mask sensitive values
70+
run: |
71+
echo "::add-mask::${{ secrets.DURABLE_INTEGRATION_TEST_ROLE_ARN }}"
72+
echo "::add-mask::${{ secrets.ACTIONS_INTEGRATION_ROLE_NAME }}"
73+
# Mask the AWS account ID extracted from the role ARN
74+
ACCOUNT_ID=$(echo "${{ secrets.DURABLE_INTEGRATION_TEST_ROLE_ARN }}" | grep -oE '[0-9]{12}' | head -1)
75+
if [ -n "$ACCOUNT_ID" ]; then
76+
echo "::add-mask::$ACCOUNT_ID"
77+
fi
6978
- name: sam build
7079
run: | # add --no-cached if debugging sam build
71-
sam build --debug --parameter-overrides \
80+
sam build --parameter-overrides \
7281
'ParameterKey=Architecture,ParameterValue=x86_64 ParameterKey=JavaVersion,ParameterValue=java${{ matrix.java }} ParameterKey=RoleArn,ParameterValue=${{ secrets.DURABLE_INTEGRATION_TEST_ROLE_ARN }}'
7382
working-directory: ./examples
7483
- name: sam deploy
75-
run: |
76-
sam deploy --stack-name JavaSDKCloudBasedIntegrationTestStack-Java${{ matrix.java }}Runtime \
84+
run: |
85+
STACK_NAME="JavaSDKCloudBasedIntegrationTestStack-Java${{ matrix.java }}Runtime"
86+
sam deploy --no-progressbar --disable-rollback \
87+
--stack-name "$STACK_NAME" \
7788
--resolve-image-repos --resolve-s3 --parameter-overrides \
78-
'ParameterKey=Architecture,ParameterValue=x86_64 ParameterKey=JavaVersion,ParameterValue=java${{ matrix.java }} ParameterKey=RoleArn,ParameterValue=${{ secrets.DURABLE_INTEGRATION_TEST_ROLE_ARN }}'
89+
'ParameterKey=Architecture,ParameterValue=x86_64 ParameterKey=JavaVersion,ParameterValue=java${{ matrix.java }} ParameterKey=RoleArn,ParameterValue=${{ secrets.DURABLE_INTEGRATION_TEST_ROLE_ARN }}' \
90+
> /dev/null 2>&1 || true
91+
92+
# Check stack status and surface a safe error summary
93+
STACK_STATUS=$(aws cloudformation describe-stacks \
94+
--stack-name "$STACK_NAME" \
95+
--query 'Stacks[0].StackStatus' --output text 2>/dev/null || echo "UNKNOWN")
96+
echo "Stack status: $STACK_STATUS"
97+
98+
if [[ "$STACK_STATUS" != *"COMPLETE"* ]] || [[ "$STACK_STATUS" == *"ROLLBACK"* ]]; then
99+
echo "::error::Deployment failed with stack status: $STACK_STATUS"
100+
# Show failed resources without exposing full error messages
101+
aws cloudformation describe-stack-events \
102+
--stack-name "$STACK_NAME" \
103+
--query 'StackEvents[?ResourceStatus==`CREATE_FAILED` || ResourceStatus==`UPDATE_FAILED`].[LogicalResourceId, ResourceStatus, ResourceType]' \
104+
--output table 2>/dev/null || true
105+
exit 1
106+
fi
79107
working-directory: ./examples
80108
- name: Cloud Based Integration Tests
81109
run: mvn clean test -B -Dtest.cloud.enabled=true -Dtest=CloudBasedIntegrationTest -Dtest.function.name.suffix='-java${{ matrix.java }}-runtime'

examples/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@
5050
<version>1.63.0</version>
5151
</dependency>
5252

53+
<!-- OTLP gRPC exporter (required for X-Ray via ADOT collector) -->
54+
<dependency>
55+
<groupId>io.opentelemetry</groupId>
56+
<artifactId>opentelemetry-exporter-otlp</artifactId>
57+
<version>1.63.0</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>io.grpc</groupId>
61+
<artifactId>grpc-netty-shaded</artifactId>
62+
<version>1.72.0</version>
63+
</dependency>
64+
5365
<!-- AWS Lambda Java Core -->
5466
<dependency>
5567
<groupId>com.amazonaws</groupId>
@@ -91,6 +103,11 @@
91103
<artifactId>sts</artifactId>
92104
<scope>test</scope>
93105
</dependency>
106+
<dependency>
107+
<groupId>software.amazon.awssdk</groupId>
108+
<artifactId>xray</artifactId>
109+
<scope>test</scope>
110+
</dependency>
94111
<dependency>
95112
<groupId>org.junit.jupiter</groupId>
96113
<artifactId>junit-jupiter</artifactId>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package software.amazon.lambda.durable.examples.otel;
4+
5+
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
6+
import io.opentelemetry.sdk.trace.SdkTracerProvider;
7+
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
8+
import software.amazon.lambda.durable.DurableConfig;
9+
import software.amazon.lambda.durable.DurableContext;
10+
import software.amazon.lambda.durable.DurableHandler;
11+
import software.amazon.lambda.durable.examples.types.GreetingRequest;
12+
import software.amazon.lambda.durable.otel.OpenTelemetryDurablePlugin;
13+
14+
/**
15+
* OTel + X-Ray example: simple steps in a single invocation.
16+
*
17+
* <p>Exports spans via OTLP gRPC to the ADOT collector extension (Lambda layer), which forwards to X-Ray. Used by
18+
* {@code OtelXRayIntegrationTest} to verify spans appear correctly in X-Ray.
19+
*
20+
* <p>Expected trace structure in X-Ray:
21+
*
22+
* <pre>
23+
* durable.invocation
24+
* ├── durable.step:create-greeting
25+
* │ └── durable.step:create-greeting [attempt 1]
26+
* └── durable.step:transform
27+
* └── durable.step:transform [attempt 1]
28+
* </pre>
29+
*/
30+
public class OtelXRayStepExample extends DurableHandler<GreetingRequest, String> {
31+
32+
@Override
33+
protected DurableConfig createConfiguration() {
34+
var otlpExporter = OtlpGrpcSpanExporter.builder()
35+
.setEndpoint("http://localhost:4317")
36+
.build();
37+
38+
var otelPlugin = new OpenTelemetryDurablePlugin(
39+
SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(otlpExporter)));
40+
41+
return DurableConfig.builder().withPlugins(otelPlugin).build();
42+
}
43+
44+
@Override
45+
public String handleRequest(GreetingRequest input, DurableContext context) {
46+
context.getLogger().info("Starting OTel X-Ray step example for {}", input.getName());
47+
48+
var greeting = context.step("create-greeting", String.class, stepCtx -> "Hello, " + input.getName());
49+
50+
var result = context.step("transform", String.class, stepCtx -> greeting.toUpperCase() + "!");
51+
52+
context.getLogger().info("OTel X-Ray step example complete: {}", result);
53+
return result;
54+
}
55+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package software.amazon.lambda.durable.examples.otel;
4+
5+
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
6+
import io.opentelemetry.sdk.trace.SdkTracerProvider;
7+
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
8+
import java.time.Duration;
9+
import software.amazon.lambda.durable.DurableConfig;
10+
import software.amazon.lambda.durable.DurableContext;
11+
import software.amazon.lambda.durable.DurableHandler;
12+
import software.amazon.lambda.durable.examples.types.GreetingRequest;
13+
import software.amazon.lambda.durable.otel.OpenTelemetryDurablePlugin;
14+
15+
/**
16+
* OTel + X-Ray example: step → wait → step pattern that forces multiple Lambda invocations.
17+
*
18+
* <p>This handler exercises the critical multi-invocation tracing scenario:
19+
*
20+
* <ol>
21+
* <li>Invocation 1: "before-wait" step completes → wait suspends execution
22+
* <li>Invocation 2: replays "before-wait" (no-op) → wait completes → "after-wait" step runs
23+
* </ol>
24+
*
25+
* <p>Exports spans via OTLP gRPC to the ADOT collector extension (Lambda layer), which forwards to X-Ray.
26+
*
27+
* <p>Used by {@code OtelXRayIntegrationTest} to verify that deterministic trace IDs correctly stitch spans from
28+
* multiple invocations into a single X-Ray trace.
29+
*
30+
* <p>Expected trace structure in X-Ray:
31+
*
32+
* <pre>
33+
* Trace (single trace ID across both invocations)
34+
* ├── durable.invocation (invocation 1)
35+
* │ ├── durable.step:before-wait
36+
* │ │ └── durable.step:before-wait [attempt 1]
37+
* │ └── durable.wait:pause (ended as PENDING)
38+
* └── durable.invocation (invocation 2)
39+
* ├── durable.wait:pause (completed)
40+
* └── durable.step:after-wait
41+
* └── durable.step:after-wait [attempt 1]
42+
* </pre>
43+
*
44+
* <p>All spans share the same deterministic trace ID derived from the execution ARN.
45+
*/
46+
public class OtelXRayWaitExample extends DurableHandler<GreetingRequest, String> {
47+
48+
@Override
49+
protected DurableConfig createConfiguration() {
50+
var otlpExporter = OtlpGrpcSpanExporter.builder()
51+
.setEndpoint("http://localhost:4317")
52+
.build();
53+
54+
var otelPlugin = new OpenTelemetryDurablePlugin(
55+
SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(otlpExporter)));
56+
57+
return DurableConfig.builder().withPlugins(otelPlugin).build();
58+
}
59+
60+
@Override
61+
public String handleRequest(GreetingRequest input, DurableContext context) {
62+
context.getLogger().info("Starting OTel X-Ray wait example for {}", input.getName());
63+
64+
var before = context.step("before-wait", String.class, stepCtx -> "Prepared: " + input.getName());
65+
66+
// This wait forces Lambda to suspend and re-invoke after the duration
67+
context.wait("pause", Duration.ofSeconds(5));
68+
69+
var after = context.step("after-wait", String.class, stepCtx -> before + " | Resumed and completed");
70+
71+
context.getLogger().info("OTel X-Ray wait example complete: {}", after);
72+
return after;
73+
}
74+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
endpoint: "localhost:4317"
6+
http:
7+
endpoint: "localhost:4318"
8+
9+
exporters:
10+
awsxray:
11+
12+
service:
13+
pipelines:
14+
traces:
15+
receivers: [otlp]
16+
exporters: [awsxray]

0 commit comments

Comments
 (0)