Skip to content

Commit aa6fa08

Browse files
authored
Port upstream fix (PR#10736) to downstream v1 Lambda stream handler (#1047)
- **V2 Issue:** [Non-top-level server span created by Lambda instrumentation](open-telemetry/opentelemetry-java-instrumentation#7808) - **V2 PR:** [#10736](open-telemetry/opentelemetry-java-instrumentation#10736) The fix has been ported to v1 as a patch for non-stream handlers. This change extends the fix to the stream handler in the v1 repository. ### Testing - All unit tests pass. - End-to-end tests pass. (with Java11, 17, and 21 runtime on Lambda) ### Backward Compatibility - No risk of breaking existing functionality. - The change only adds instrumentation for `RequestStreamHandler` without modifying existing behavior for `RequestHandler`. - Existing users who do not use `RequestStreamHandler` remain unaffected. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9f7f969 commit aa6fa08

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lambda-layer/patches/StreamHandlerInstrumentation.patch

+11-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ index 35d6b70ed6..b6a305178e 100644
3434
}
3535
diff --git a/instrumentation/aws-lambda/aws-lambda-core-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awslambdacore/v1_0/AwsLambdaRequestStreamHandlerInstrumentation.java b/instrumentation/aws-lambda/aws-lambda-core-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awslambdacore/v1_0/AwsLambdaRequestStreamHandlerInstrumentation.java
3636
new file mode 100644
37-
index 0000000000..73b82a62a2
37+
index 0000000000..1c4ef1ac07
3838
--- /dev/null
3939
+++ b/instrumentation/aws-lambda/aws-lambda-core-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awslambdacore/v1_0/AwsLambdaRequestStreamHandlerInstrumentation.java
40-
@@ -0,0 +1,90 @@
40+
@@ -0,0 +1,98 @@
4141
+/*
4242
+ * Copyright The OpenTelemetry Authors
4343
+ * SPDX-License-Identifier: Apache-2.0
@@ -50,7 +50,9 @@ index 0000000000..73b82a62a2
5050
+import static io.opentelemetry.javaagent.instrumentation.awslambdacore.v1_0.AwsLambdaInstrumentationHelper.functionInstrumenter;
5151
+import static net.bytebuddy.matcher.ElementMatchers.isMethod;
5252
+import static net.bytebuddy.matcher.ElementMatchers.isPublic;
53+
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
5354
+import static net.bytebuddy.matcher.ElementMatchers.named;
55+
+import static net.bytebuddy.matcher.ElementMatchers.not;
5456
+import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
5557
+
5658
+import com.amazonaws.services.lambda.runtime.Context;
@@ -76,7 +78,13 @@ index 0000000000..73b82a62a2
7678
+
7779
+ @Override
7880
+ public ElementMatcher<TypeDescription> typeMatcher() {
79-
+ return implementsInterface(named("com.amazonaws.services.lambda.runtime.RequestStreamHandler"));
81+
+ return implementsInterface(named("com.amazonaws.services.lambda.runtime.RequestStreamHandler"))
82+
+ .and(not(nameStartsWith("com.amazonaws.services.lambda.runtime.api.client")))
83+
+ // In Java 8 and Java 11 runtimes,
84+
+ // AWS Lambda runtime is packaged under `lambdainternal` package.
85+
+ // But it is `com.amazonaws.services.lambda.runtime.api.client`
86+
+ // for new runtime likes Java 17 and Java 21.
87+
+ .and(not(nameStartsWith("lambdainternal")));
8088
+ }
8189
+
8290
+ @Override

0 commit comments

Comments
 (0)