AWS Lambda Runtime internal handlers need to be ignored from being instrumented and so traced. (#10736)
This commit is contained in:
parent
df83eaa502
commit
e988d48f4b
|
@ -10,7 +10,9 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.
|
||||||
import static io.opentelemetry.javaagent.instrumentation.awslambdacore.v1_0.AwsLambdaInstrumentationHelper.functionInstrumenter;
|
import static io.opentelemetry.javaagent.instrumentation.awslambdacore.v1_0.AwsLambdaInstrumentationHelper.functionInstrumenter;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||||
|
|
||||||
import com.amazonaws.services.lambda.runtime.Context;
|
import com.amazonaws.services.lambda.runtime.Context;
|
||||||
|
@ -35,7 +37,8 @@ public class AwsLambdaRequestHandlerInstrumentation implements TypeInstrumentati
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||||
return implementsInterface(named("com.amazonaws.services.lambda.runtime.RequestHandler"));
|
return implementsInterface(named("com.amazonaws.services.lambda.runtime.RequestHandler"))
|
||||||
|
.and(not(nameStartsWith("com.amazonaws.services.lambda.runtime.api.client")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.amazonaws.services.lambda.runtime.api.client;
|
||||||
|
|
||||||
|
import com.amazonaws.services.lambda.runtime.Context;
|
||||||
|
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||||
|
|
||||||
|
public class AwsLambdaInternalRequestHandler implements RequestHandler<String, String> {
|
||||||
|
|
||||||
|
private final RequestHandler<String, String> requestHandler;
|
||||||
|
|
||||||
|
public AwsLambdaInternalRequestHandler(RequestHandler<String, String> requestHandler) {
|
||||||
|
this.requestHandler = requestHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String handleRequest(String input, Context context) {
|
||||||
|
return requestHandler.handleRequest(input, context);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,14 +5,19 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.awslambdacore.v1_0;
|
package io.opentelemetry.javaagent.instrumentation.awslambdacore.v1_0;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.amazonaws.services.lambda.runtime.Context;
|
import com.amazonaws.services.lambda.runtime.Context;
|
||||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||||
|
import com.amazonaws.services.lambda.runtime.api.client.AwsLambdaInternalRequestHandler;
|
||||||
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
import io.opentelemetry.instrumentation.awslambdacore.v1_0.AbstractAwsLambdaTest;
|
import io.opentelemetry.instrumentation.awslambdacore.v1_0.AbstractAwsLambdaTest;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.semconv.SemanticAttributes;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
public class AwsLambdaTest extends AbstractAwsLambdaTest {
|
public class AwsLambdaTest extends AbstractAwsLambdaTest {
|
||||||
|
@ -35,6 +40,23 @@ public class AwsLambdaTest extends AbstractAwsLambdaTest {
|
||||||
assertThat(testing.forceFlushCalled()).isTrue();
|
assertThat(testing.forceFlushCalled()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void awsLambdaInternalHandlerIgnoredAndUserHandlerTraced() {
|
||||||
|
RequestHandler<String, String> handler = new AwsLambdaInternalRequestHandler(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> {
|
private static final class TestRequestHandler implements RequestHandler<String, String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -53,6 +53,10 @@ public abstract class AbstractAwsLambdaTest {
|
||||||
assertThat(testing().forceFlushCalled()).isTrue();
|
assertThat(testing().forceFlushCalled()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Context context() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void handlerTraced() {
|
void handlerTraced() {
|
||||||
String result = handler().handleRequest("hello", context);
|
String result = handler().handleRequest("hello", context);
|
||||||
|
|
Loading…
Reference in New Issue