Use instance field for wrapped lambda instead of static.
MODIFY
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestApiGatewayWrapper.java
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestApiGatewayWrapper.java
@@ -21,7 +21,7 @@ public class TracingRequestApiGatewayWrapper
}
// Visible for testing
- TracingRequestApiGatewayWrapper(OpenTelemetrySdk openTelemetrySdk) {
- super(openTelemetrySdk);
+ TracingRequestApiGatewayWrapper(OpenTelemetrySdk openTelemetrySdk, WrappedLambda wrappedLambda) {
+ super(openTelemetrySdk, wrappedLambda);
}
}

MODIFY
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestStreamWrapper.java
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestStreamWrapper.java
@@ -21,29 +21,28 @@ import java.io.OutputStream;
*/
public class TracingRequestStreamWrapper extends TracingRequestStreamHandler {
- // visible for testing
- static WrappedLambda WRAPPED_LAMBDA = WrappedLambda.fromConfiguration();
+ private final WrappedLambda wrappedLambda;
public TracingRequestStreamWrapper() {
- this(OpenTelemetrySdkAutoConfiguration.initialize());
+ this(OpenTelemetrySdkAutoConfiguration.initialize(), WrappedLambda.fromConfiguration());
}
// Visible for testing
- TracingRequestStreamWrapper(OpenTelemetrySdk openTelemetrySdk) {
+ TracingRequestStreamWrapper(OpenTelemetrySdk openTelemetrySdk, WrappedLambda wrappedLambda) {
super(openTelemetrySdk, WrapperConfiguration.flushTimeout());
+ this.wrappedLambda = wrappedLambda;
}
@Override
protected void doHandleRequest(InputStream inputStream, OutputStream output, Context context)
throws IOException {
- if (!(WRAPPED_LAMBDA.getTargetObject() instanceof RequestStreamHandler)) {
+ if (!(wrappedLambda.getTargetObject() instanceof RequestStreamHandler)) {
throw new RuntimeException(
- WRAPPED_LAMBDA.getTargetClass().getName()
- + " is not an instance of RequestStreamHandler");
+ wrappedLambda.getTargetClass().getName() + " is not an instance of RequestStreamHandler");
}
- ((RequestStreamHandler) WRAPPED_LAMBDA.getTargetObject())
+ ((RequestStreamHandler) wrappedLambda.getTargetObject())
.handleRequest(inputStream, output, context);
}
}

MODIFY
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapper.java
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapper.java
@@ -17,7 +17,7 @@ public class TracingRequestWrapper extends TracingRequestWrapperBase<Object, Obj
}
// Visible for testing
- TracingRequestWrapper(OpenTelemetrySdk openTelemetrySdk) {
- super(openTelemetrySdk);
+ TracingRequestWrapper(OpenTelemetrySdk openTelemetrySdk, WrappedLambda wrappedLambda) {
+ super(openTelemetrySdk, wrappedLambda);
}
}

MODIFY
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapperBase.java
instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapperBase.java
@@ -17,18 +17,18 @@ import java.lang.reflect.Method;
*/
abstract class TracingRequestWrapperBase<I, O> extends TracingRequestHandler<I, O> {
+ private final WrappedLambda wrappedLambda;
+
protected TracingRequestWrapperBase() {
- this(OpenTelemetrySdkAutoConfiguration.initialize());
+ this(OpenTelemetrySdkAutoConfiguration.initialize(), WrappedLambda.fromConfiguration());
}
// Visible for testing
- TracingRequestWrapperBase(OpenTelemetrySdk openTelemetrySdk) {
+ TracingRequestWrapperBase(OpenTelemetrySdk openTelemetrySdk, WrappedLambda wrappedLambda) {
super(openTelemetrySdk, WrapperConfiguration.flushTimeout());
+ this.wrappedLambda = wrappedLambda;
}
- // visible for testing
- static WrappedLambda WRAPPED_LAMBDA = WrappedLambda.fromConfiguration();
-
private Object[] createParametersArray(Method targetMethod, I input, Context context) {
Class<?>[] parameterTypes = targetMethod.getParameterTypes();
Object[] parameters = new Object[parameterTypes.length];
@@ -51,12 +51,12 @@ abstract class TracingRequestWrapperBase<I, O> extends TracingRequestHandler<I,
@Override
protected O doHandleRequest(I input, Context context) {
- Method targetMethod = WRAPPED_LAMBDA.getRequestTargetMethod();
+ Method targetMethod = wrappedLambda.getRequestTargetMethod();
Object[] parameters = createParametersArray(targetMethod, input, context);
O result;
try {
- result = (O) targetMethod.invoke(WRAPPED_LAMBDA.getTargetObject(), parameters);
+ result = (O) targetMethod.invoke(wrappedLambda.getTargetObject(), parameters);
} catch (IllegalAccessException e) {
throw new RuntimeException("Method is inaccessible", e);
} catch (InvocationTargetException e) {

MODIFY
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestApiGatewayWrapperTest.groovy
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestApiGatewayWrapperTest.groovy
@@ -38,7 +38,7 @@ class TracingRequestApiGatewayWrapperTest extends TracingRequestWrapperTestBase
def "handler traced with trace propagation"() {
given:
- setLambda(TestApiGatewayHandler.getName() + "::handleRequest", { new TracingRequestApiGatewayWrapper(it) })
+ setLambda(TestApiGatewayHandler.getName() + "::handleRequest", TracingRequestApiGatewayWrapper.metaClass.&invokeConstructor)
def headers = ImmutableMap.builder()
.putAll(propagationHeaders())
@@ -83,7 +83,7 @@ class TracingRequestApiGatewayWrapperTest extends TracingRequestWrapperTestBase
def "test empty request & response"() {
given:
- setLambda(TestApiGatewayHandler.getName() + "::handleRequest", { new TracingRequestApiGatewayWrapper(it) })
+ setLambda(TestApiGatewayHandler.getName() + "::handleRequest", TracingRequestApiGatewayWrapper.metaClass.&invokeConstructor)
def input = new APIGatewayProxyRequestEvent()
.withBody("empty")

MODIFY
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestStreamWrapperPropagationTest.groovy
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestStreamWrapperPropagationTest.groovy
@@ -49,8 +49,7 @@ class TracingRequestStreamWrapperPropagationTest extends LibraryInstrumentationS
def setup() {
environmentVariables.set(WrappedLambda.OTEL_LAMBDA_HANDLER_ENV_KEY, "io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamWrapperPropagationTest\$TestRequestHandler::handleRequest")
- TracingRequestStreamWrapper.WRAPPED_LAMBDA = WrappedLambda.fromConfiguration()
- wrapper = new TracingRequestStreamWrapper(testRunner().openTelemetrySdk)
+ wrapper = new TracingRequestStreamWrapper(testRunner().openTelemetrySdk, WrappedLambda.fromConfiguration())
}
def cleanup() {

MODIFY
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestStreamWrapperTest.groovy
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestStreamWrapperTest.groovy
@@ -45,8 +45,7 @@ class TracingRequestStreamWrapperTest extends LibraryInstrumentationSpecificatio
def setup() {
environmentVariables.set(WrappedLambda.OTEL_LAMBDA_HANDLER_ENV_KEY, "io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamWrapperTest\$TestRequestHandler::handleRequest")
- TracingRequestStreamWrapper.WRAPPED_LAMBDA = WrappedLambda.fromConfiguration()
- wrapper = new TracingRequestStreamWrapper(testRunner().openTelemetrySdk)
+ wrapper = new TracingRequestStreamWrapper(testRunner().openTelemetrySdk, WrappedLambda.fromConfiguration())
}
def cleanup() {

MODIFY
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapperTest.groovy
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapperTest.groovy
@@ -27,7 +27,7 @@ class TracingRequestWrapperTest extends TracingRequestWrapperTestBase {
def "handler string traced"() {
given:
- setLambda(TestRequestHandlerString.getName() + "::handleRequest", { new TracingRequestWrapper(it) })
+ setLambda(TestRequestHandlerString.getName() + "::handleRequest", TracingRequestWrapper.metaClass.&invokeConstructor)
when:
def result = wrapper.handleRequest("hello", context)
@@ -51,7 +51,7 @@ class TracingRequestWrapperTest extends TracingRequestWrapperTestBase {
def "handler with exception"() {
given:
- setLambda(TestRequestHandlerString.getName() + "::handleRequest", { new TracingRequestWrapper(it) })
+ setLambda(TestRequestHandlerString.getName() + "::handleRequest", TracingRequestWrapper.metaClass.&invokeConstructor)
when:
def thrown

MODIFY
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapperTestBase.groovy
instrumentation/aws-lambda-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/awslambda/v1_0/TracingRequestWrapperTestBase.groovy
@@ -31,7 +31,6 @@ class TracingRequestWrapperTestBase extends LibraryInstrumentationSpecification
def setLambda(handler, Closure<TracingRequestWrapperBase> wrapperConstructor) {
environmentVariables.set(WrappedLambda.OTEL_LAMBDA_HANDLER_ENV_KEY, handler)
- TracingRequestWrapper.WRAPPED_LAMBDA = WrappedLambda.fromConfiguration()
- wrapper = wrapperConstructor.call(testRunner().openTelemetrySdk)
+ wrapper = wrapperConstructor.call(testRunner().openTelemetrySdk, WrappedLambda.fromConfiguration())
}
}

Use instance field for wrapped lambda instead of static. (#2579)