Skip to content
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

AWS Lambda Runtime legacy internal handlers need to be ignored from being instrumented and so traced … #10942

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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public ElementMatcher<ClassLoader> classLoaderOptimization() {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("com.amazonaws.services.lambda.runtime.RequestHandler"))
.and(not(nameStartsWith("com.amazonaws.services.lambda.runtime.api.client")));
.and(not(nameStartsWith("com.amazonaws.services.lambda.runtime.api.client")))
// In Java 8 and Java 11 runtimes,
// AWS Lambda runtime is packaged under `lambdainternal` package.
// But it is `com.amazonaws.services.lambda.runtime.api.client`
// for new runtime likes Java 17 and Java 21.
.and(not(nameStartsWith("lambdainternal")));
serkan-ozal marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.semconv.SemanticAttributes;
import lambdainternal.AwsLambdaLegacyInternalRequestHandler;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -57,6 +58,23 @@ void awsLambdaInternalHandlerIgnoredAndUserHandlerTraced() {
equalTo(SemanticAttributes.FAAS_INVOCATION_ID, "1-22-333"))));
}

@Test
void awsLambdaLegacyInternalHandlerIgnoredAndUserHandlerTraced() {
RequestHandler<String, String> handler = new AwsLambdaLegacyInternalRequestHandler(handler());
String result = handler.handleRequest("hello", context());
assertThat(result).isEqualTo("world");

testing()
.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("my_function")
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.FAAS_INVOCATION_ID, "1-22-333"))));
}

private static final class TestRequestHandler implements RequestHandler<String, String> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package lambdainternal;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class AwsLambdaLegacyInternalRequestHandler implements RequestHandler<String, String> {

private final RequestHandler<String, String> requestHandler;

public AwsLambdaLegacyInternalRequestHandler(RequestHandler<String, String> requestHandler) {
this.requestHandler = requestHandler;
}

@Override
public String handleRequest(String input, Context context) {
return requestHandler.handleRequest(input, context);
}
}
Loading