Remove setGlobalPropagators calls from lambda tests. (#2057)
This commit is contained in:
parent
cfbfc5623d
commit
72a4b9a891
|
|
@ -12,10 +12,7 @@ import com.amazonaws.services.lambda.runtime.RequestHandler
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
|
||||||
import com.google.common.collect.ImmutableMap
|
import com.google.common.collect.ImmutableMap
|
||||||
import io.opentelemetry.api.OpenTelemetry
|
|
||||||
import io.opentelemetry.api.trace.attributes.SemanticAttributes
|
import io.opentelemetry.api.trace.attributes.SemanticAttributes
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators
|
|
||||||
import io.opentelemetry.extension.trace.propagation.B3Propagator
|
|
||||||
|
|
||||||
class TracingRequestApiGatewayWrapperTest extends TracingRequestWrapperTestBase {
|
class TracingRequestApiGatewayWrapperTest extends TracingRequestWrapperTestBase {
|
||||||
|
|
||||||
|
|
@ -34,13 +31,8 @@ class TracingRequestApiGatewayWrapperTest extends TracingRequestWrapperTestBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def childSetupSpec() {
|
|
||||||
super.childSetupSpec()
|
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.create(B3Propagator.getInstance()))
|
|
||||||
}
|
|
||||||
|
|
||||||
def propagationHeaders() {
|
def propagationHeaders() {
|
||||||
return ImmutableMap.of("X-B3-TraceId", "4fd0b6131f19f39af59518d127b0cafe", "X-B3-SpanId", "0000000000000456", "X-B3-Sampled", "true")
|
return Collections.singletonMap("traceparent", "00-4fd0b6131f19f39af59518d127b0cafe-0000000000000456-01")
|
||||||
}
|
}
|
||||||
|
|
||||||
def "handler traced with trace propagation"() {
|
def "handler traced with trace propagation"() {
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,7 @@ import com.amazonaws.services.lambda.runtime.Context
|
||||||
import com.amazonaws.services.lambda.runtime.RequestStreamHandler
|
import com.amazonaws.services.lambda.runtime.RequestStreamHandler
|
||||||
import com.fasterxml.jackson.databind.JsonNode
|
import com.fasterxml.jackson.databind.JsonNode
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import io.opentelemetry.api.OpenTelemetry
|
|
||||||
import io.opentelemetry.api.trace.attributes.SemanticAttributes
|
import io.opentelemetry.api.trace.attributes.SemanticAttributes
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators
|
|
||||||
import io.opentelemetry.extension.trace.propagation.B3Propagator
|
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationTestTrait
|
import io.opentelemetry.instrumentation.test.InstrumentationTestTrait
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
|
@ -52,7 +49,6 @@ class TracingRequestStreamWrapperPropagationTest extends InstrumentationSpecific
|
||||||
TracingRequestStreamWrapper wrapper
|
TracingRequestStreamWrapper wrapper
|
||||||
|
|
||||||
def childSetup() {
|
def childSetup() {
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.create(B3Propagator.getInstance()))
|
|
||||||
environmentVariables.set(WrappedLambda.OTEL_LAMBDA_HANDLER_ENV_KEY, "io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamWrapperPropagationTest\$TestRequestHandler::handleRequest")
|
environmentVariables.set(WrappedLambda.OTEL_LAMBDA_HANDLER_ENV_KEY, "io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamWrapperPropagationTest\$TestRequestHandler::handleRequest")
|
||||||
TracingRequestStreamWrapper.WRAPPED_LAMBDA = WrappedLambda.fromConfiguration()
|
TracingRequestStreamWrapper.WRAPPED_LAMBDA = WrappedLambda.fromConfiguration()
|
||||||
wrapper = new TracingRequestStreamWrapper()
|
wrapper = new TracingRequestStreamWrapper()
|
||||||
|
|
@ -67,7 +63,7 @@ class TracingRequestStreamWrapperPropagationTest extends InstrumentationSpecific
|
||||||
String content =
|
String content =
|
||||||
"{" +
|
"{" +
|
||||||
"\"headers\" : {" +
|
"\"headers\" : {" +
|
||||||
"\"X-B3-TraceId\": \"4fd0b6131f19f39af59518d127b0cafe\", \"X-B3-SpanId\": \"0000000000000456\", \"X-B3-Sampled\": \"true\"" +
|
"\"traceparent\": \"00-4fd0b6131f19f39af59518d127b0cafe-0000000000000456-01\"" +
|
||||||
"}," +
|
"}," +
|
||||||
"\"body\" : \"hello\"" +
|
"\"body\" : \"hello\"" +
|
||||||
"}"
|
"}"
|
||||||
|
|
@ -100,7 +96,7 @@ class TracingRequestStreamWrapperPropagationTest extends InstrumentationSpecific
|
||||||
String content =
|
String content =
|
||||||
"{" +
|
"{" +
|
||||||
"\"headers\" : {" +
|
"\"headers\" : {" +
|
||||||
"\"X-B3-TraceId\": \"4fd0b6131f19f39af59518d127b0cafe\", \"X-B3-SpanId\": \"0000000000000456\", \"X-B3-Sampled\": \"true\"" +
|
"\"traceparent\": \"00-4fd0b6131f19f39af59518d127b0cafe-0000000000000456-01\"" +
|
||||||
"}," +
|
"}," +
|
||||||
"\"body\" : \"bye\"" +
|
"\"body\" : \"bye\"" +
|
||||||
"}"
|
"}"
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,7 @@ import static io.opentelemetry.api.trace.Span.Kind.SERVER
|
||||||
|
|
||||||
import com.amazonaws.services.lambda.runtime.Context
|
import com.amazonaws.services.lambda.runtime.Context
|
||||||
import com.amazonaws.services.lambda.runtime.RequestStreamHandler
|
import com.amazonaws.services.lambda.runtime.RequestStreamHandler
|
||||||
import io.opentelemetry.api.OpenTelemetry
|
|
||||||
import io.opentelemetry.api.trace.attributes.SemanticAttributes
|
import io.opentelemetry.api.trace.attributes.SemanticAttributes
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators
|
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationTestTrait
|
import io.opentelemetry.instrumentation.test.InstrumentationTestTrait
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
|
@ -46,8 +44,6 @@ class TracingRequestStreamWrapperTest extends InstrumentationSpecification imple
|
||||||
TracingRequestStreamWrapper wrapper
|
TracingRequestStreamWrapper wrapper
|
||||||
|
|
||||||
def childSetup() {
|
def childSetup() {
|
||||||
// no propagators
|
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.noop())
|
|
||||||
environmentVariables.set(WrappedLambda.OTEL_LAMBDA_HANDLER_ENV_KEY, "io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamWrapperTest\$TestRequestHandler::handleRequest")
|
environmentVariables.set(WrappedLambda.OTEL_LAMBDA_HANDLER_ENV_KEY, "io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamWrapperTest\$TestRequestHandler::handleRequest")
|
||||||
TracingRequestStreamWrapper.WRAPPED_LAMBDA = WrappedLambda.fromConfiguration()
|
TracingRequestStreamWrapper.WRAPPED_LAMBDA = WrappedLambda.fromConfiguration()
|
||||||
wrapper = new TracingRequestStreamWrapper()
|
wrapper = new TracingRequestStreamWrapper()
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@
|
||||||
package io.opentelemetry.instrumentation.awslambda.v1_0
|
package io.opentelemetry.instrumentation.awslambda.v1_0
|
||||||
|
|
||||||
import com.amazonaws.services.lambda.runtime.Context
|
import com.amazonaws.services.lambda.runtime.Context
|
||||||
import io.opentelemetry.api.OpenTelemetry
|
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators
|
|
||||||
import io.opentelemetry.extension.trace.propagation.B3Propagator
|
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationTestTrait
|
import io.opentelemetry.instrumentation.test.InstrumentationTestTrait
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
|
|
@ -31,8 +28,6 @@ class TracingRequestWrapperTestBase extends InstrumentationSpecification impleme
|
||||||
context.getFunctionName() >> "my_function"
|
context.getFunctionName() >> "my_function"
|
||||||
context.getAwsRequestId() >> "1-22-333"
|
context.getAwsRequestId() >> "1-22-333"
|
||||||
context.getInvokedFunctionArn() >> "arn:aws:lambda:us-east-1:123456789:function:test"
|
context.getInvokedFunctionArn() >> "arn:aws:lambda:us-east-1:123456789:function:test"
|
||||||
|
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.create(B3Propagator.getInstance()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def setLambda(handler, wrapperClass) {
|
def setLambda(handler, wrapperClass) {
|
||||||
|
|
|
||||||
|
|
@ -13,22 +13,31 @@ import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.DefaultOpenTelemetry;
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.extension.trace.propagation.AwsXRayPropagator;
|
import io.opentelemetry.extension.trace.propagation.AwsXRayPropagator;
|
||||||
import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
||||||
|
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class ApiGatewayProxyRequestTest {
|
class ApiGatewayProxyRequestTest {
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void resetOpenTelemetry() {
|
||||||
|
OpenTelemetry.set(OpenTelemetrySdk.builder().build());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateNoopRequestIfNoPropagatorsSet() throws IOException {
|
public void shouldCreateNoopRequestIfNoPropagatorsSet() throws IOException {
|
||||||
// given
|
// given
|
||||||
InputStream mock = mock(InputStream.class);
|
InputStream mock = mock(InputStream.class);
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.noop());
|
OpenTelemetry.set(
|
||||||
|
DefaultOpenTelemetry.builder().setPropagators(ContextPropagators.noop()).build());
|
||||||
// when
|
// when
|
||||||
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
||||||
// then
|
// then
|
||||||
|
|
@ -40,7 +49,10 @@ class ApiGatewayProxyRequestTest {
|
||||||
public void shouldCreateNoopRequestIfXRayPropagatorsSet() throws IOException {
|
public void shouldCreateNoopRequestIfXRayPropagatorsSet() throws IOException {
|
||||||
// given
|
// given
|
||||||
InputStream mock = mock(InputStream.class);
|
InputStream mock = mock(InputStream.class);
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.create(AwsXRayPropagator.getInstance()));
|
OpenTelemetry.set(
|
||||||
|
DefaultOpenTelemetry.builder()
|
||||||
|
.setPropagators(ContextPropagators.create(AwsXRayPropagator.getInstance()))
|
||||||
|
.build());
|
||||||
// when
|
// when
|
||||||
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
||||||
// then
|
// then
|
||||||
|
|
@ -53,7 +65,10 @@ class ApiGatewayProxyRequestTest {
|
||||||
// given
|
// given
|
||||||
InputStream mock = mock(InputStream.class);
|
InputStream mock = mock(InputStream.class);
|
||||||
given(mock.markSupported()).willReturn(true);
|
given(mock.markSupported()).willReturn(true);
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.create(B3Propagator.getInstance()));
|
OpenTelemetry.set(
|
||||||
|
DefaultOpenTelemetry.builder()
|
||||||
|
.setPropagators(ContextPropagators.create(B3Propagator.getInstance()))
|
||||||
|
.build());
|
||||||
// when
|
// when
|
||||||
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
||||||
// then
|
// then
|
||||||
|
|
@ -68,8 +83,10 @@ class ApiGatewayProxyRequestTest {
|
||||||
InputStream mock = mock(InputStream.class);
|
InputStream mock = mock(InputStream.class);
|
||||||
given(mock.markSupported()).willReturn(false);
|
given(mock.markSupported()).willReturn(false);
|
||||||
given(mock.read(any(byte[].class))).willReturn(-1);
|
given(mock.read(any(byte[].class))).willReturn(-1);
|
||||||
|
OpenTelemetry.set(
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.create(B3Propagator.getInstance()));
|
DefaultOpenTelemetry.builder()
|
||||||
|
.setPropagators(ContextPropagators.create(B3Propagator.getInstance()))
|
||||||
|
.build());
|
||||||
// when
|
// when
|
||||||
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
ApiGatewayProxyRequest created = ApiGatewayProxyRequest.forStream(mock);
|
||||||
// then
|
// then
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,25 @@ package io.opentelemetry.instrumentation.awslambda.v1_0;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.opentelemetry.api.DefaultOpenTelemetry;
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
import io.opentelemetry.api.trace.Span;
|
import io.opentelemetry.api.trace.Span;
|
||||||
import io.opentelemetry.api.trace.SpanContext;
|
import io.opentelemetry.api.trace.SpanContext;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
||||||
|
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class ParentContextExtractorTest {
|
class ParentContextExtractorTest {
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void resetOpenTelemetry() {
|
||||||
|
OpenTelemetry.set(OpenTelemetrySdk.builder().build());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldExtractCaseInsensitiveHeaders() {
|
public void shouldExtractCaseInsensitiveHeaders() {
|
||||||
// given
|
// given
|
||||||
|
|
@ -30,7 +38,10 @@ class ParentContextExtractorTest {
|
||||||
"0000000000000456",
|
"0000000000000456",
|
||||||
"X-B3-Sampled",
|
"X-B3-Sampled",
|
||||||
"true");
|
"true");
|
||||||
OpenTelemetry.setGlobalPropagators(ContextPropagators.create(B3Propagator.getInstance()));
|
OpenTelemetry.set(
|
||||||
|
DefaultOpenTelemetry.builder()
|
||||||
|
.setPropagators(ContextPropagators.create(B3Propagator.getInstance()))
|
||||||
|
.build());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Context context = ParentContextExtractor.fromHttpHeaders(headers);
|
Context context = ParentContextExtractor.fromHttpHeaders(headers);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue