From 17d9ec9fab7e66f0a4edf521ee0bc2a6f79ddb1d Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 14 Dec 2024 10:20:01 -0500 Subject: [PATCH 01/11] start converting --- .../Aws2SqsSuppressReceiveSpansTest.groovy | 56 +- .../v2_2/Aws2SqsSuppressReceiveSpansTest.java | 35 + .../Aws2SqsSuppressReceiveSpansTest.groovy | 109 --- ...ressReceiveSpansDefaultPropagatorTest.java | 50 ++ .../v2_2/Aws2SqsSuppressReceiveSpansTest.java | 37 + ...ansW3CPropagatorAndXrayPropagatorTest.java | 24 + ...SuppressReceiveSpansW3CPropagatorTest.java | 19 + ...ractAws2SqsSuppressReceiveSpansTest.groovy | 786 +++++++++--------- .../awssdk/v2_2/AbstractAws2SqsBaseTest.java | 176 ++++ ...stractAws2SqsSuppressReceiveSpansTest.java | 298 +++++++ .../v2_2/AbstractAws2SqsTracingTest.java | 206 +---- 11 files changed, 1078 insertions(+), 718 deletions(-) create mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java delete mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.groovy create mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java create mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java create mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java create mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java create mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java create mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy index e7f2128682d6..9aa812f746a7 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy @@ -1,27 +1,29 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import io.opentelemetry.instrumentation.awssdk.v2_2.AbstractAws2SqsSuppressReceiveSpansTest -import io.opentelemetry.instrumentation.test.AgentTestTrait -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration -import software.amazon.awssdk.services.sqs.SqsAsyncClient -import software.amazon.awssdk.services.sqs.SqsClient - -class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest implements AgentTestTrait { - @Override - ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { - return ClientOverrideConfiguration.builder() - } - - @Override - SqsClient configureSqsClient(SqsClient sqsClient) { - return sqsClient - } - - @Override - SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { - return sqsClient - } -} +///* +// * Copyright The OpenTelemetry Authors +// * SPDX-License-Identifier: Apache-2.0 +// */ +// +//import io.opentelemetry.instrumentation.awssdk.v2_2.AbstractAws2SqsSuppressReceiveSpansTest +//import io.opentelemetry.instrumentation.test.AgentTestTrait +//import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration +//import software.amazon.awssdk.services.sqs.SqsAsyncClient +//import software.amazon.awssdk.services.sqs.SqsClient +// +//class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest implements AgentTestTrait { +// +// +// @Override +// ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { +// return ClientOverrideConfiguration.builder() +// } +// +// @Override +// SqsClient configureSqsClient(SqsClient sqsClient) { +// return sqsClient +// } +// +// @Override +// SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { +// return sqsClient +// } +//} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java new file mode 100644 index 000000000000..e68eee5afa2a --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java @@ -0,0 +1,35 @@ +package io.opentelemetry.javaagent.instrumentation.awssdk.v2_2; + +import io.opentelemetry.instrumentation.awssdk.v2_2.AbstractAws2SqsSuppressReceiveSpansTest; +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import org.junit.jupiter.api.extension.RegisterExtension; +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; +import software.amazon.awssdk.services.sqs.SqsAsyncClient; +import software.amazon.awssdk.services.sqs.SqsClient; + +class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest { + + @RegisterExtension + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + @Override + protected InstrumentationExtension getTesting() { + return testing; + } + + @Override + protected SqsClient configureSqsClient(SqsClient sqsClient) { + return sqsClient; + } + + @Override + protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { + return sqsClient; + } + + @Override + protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { + return ClientOverrideConfiguration.builder(); + } +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.groovy deleted file mode 100644 index af05d2ee6d8c..000000000000 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.groovy +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.awssdk.v2_2 - -import io.opentelemetry.instrumentation.test.LibraryTestTrait -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration -import software.amazon.awssdk.services.sqs.SqsAsyncClient -import software.amazon.awssdk.services.sqs.SqsClient - -abstract class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest implements LibraryTestTrait { - static AwsSdkTelemetry telemetry - - def setupSpec() { - def telemetryBuilder = AwsSdkTelemetry.builder(getOpenTelemetry()) - .setCaptureExperimentalSpanAttributes(true) - configure(telemetryBuilder) - telemetry = telemetryBuilder.build() - } - - abstract void configure(AwsSdkTelemetryBuilder telemetryBuilder) - - @Override - ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { - return ClientOverrideConfiguration.builder() - .addExecutionInterceptor( - telemetry.newExecutionInterceptor()) - } - - @Override - SqsClient configureSqsClient(SqsClient sqsClient) { - return telemetry.wrap(sqsClient) - } - - @Override - SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { - return telemetry.wrap(sqsClient) - } -} - -class Aws2SqsSuppressReceiveSpansDefaultPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { - - @Override - void configure(AwsSdkTelemetryBuilder telemetryBuilder) {} - - @Override - boolean isSqsAttributeInjectionEnabled() { - false - } - - def "duplicate tracing interceptor"() { - setup: - def builder = SqsClient.builder() - configureSdkClient(builder) - def overrideConfiguration = ClientOverrideConfiguration.builder() - .addExecutionInterceptor(telemetry.newExecutionInterceptor()) - .addExecutionInterceptor(telemetry.newExecutionInterceptor()) - .build() - builder.overrideConfiguration(overrideConfiguration) - def client = configureSqsClient(builder.build()) - - client.createQueue(createQueueRequest) - - when: - client.sendMessage(sendMessageRequest) - - def resp = client.receiveMessage(receiveMessageRequest) - - then: - resp.messages().size() == 1 - resp.messages.each {message -> runWithSpan("process child") {}} - assertSqsTraces() - } -} - -class Aws2SqsSuppressReceiveSpansW3CPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { - - @Override - void configure(AwsSdkTelemetryBuilder telemetryBuilder) { - telemetryBuilder.setUseConfiguredPropagatorForMessaging(isSqsAttributeInjectionEnabled()) // Difference to main test - .setUseXrayPropagator(isXrayInjectionEnabled()) // Disable to confirm messaging propagator actually works - } - - @Override - boolean isSqsAttributeInjectionEnabled() { - true - } - - @Override - boolean isXrayInjectionEnabled() { - false - } -} - -/** We want to test the combination of W3C + Xray, as that's what you'll get in prod if you enable W3C. */ -class Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { - - @Override - void configure(AwsSdkTelemetryBuilder telemetryBuilder) { - telemetryBuilder.setUseConfiguredPropagatorForMessaging(isSqsAttributeInjectionEnabled()) // Difference to main test - } - - @Override - boolean isSqsAttributeInjectionEnabled() { - true - } -} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java new file mode 100644 index 000000000000..067d6008f871 --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java @@ -0,0 +1,50 @@ +package io.opentelemetry.instrumentation.awssdk.v2_2; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; +import software.amazon.awssdk.services.sqs.SqsClient; +import software.amazon.awssdk.services.sqs.SqsClientBuilder; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; +import java.net.URISyntaxException; + +import static org.assertj.core.api.Assertions.assertThat; + +class Aws2SqsSuppressReceiveSpansDefaultPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { + + @BeforeAll + static void setup() { + AwsSdkTelemetryBuilder telemetryBuilder = AwsSdkTelemetry.builder(testing.getOpenTelemetry()) + .setCaptureExperimentalSpanAttributes(true); + configure(telemetryBuilder); + telemetry = telemetryBuilder.build(); + } + + static void configure(AwsSdkTelemetryBuilder telemetryBuilder) {} + + @Override + boolean isSqsAttributeInjectionEnabled() { + return false; + } + + @Test + void testDuplicateTracingInterceptor() throws URISyntaxException { + SqsClientBuilder builder = SqsClient.builder(); + configureSdkClient(builder); + ClientOverrideConfiguration overrideConfiguration = ClientOverrideConfiguration.builder() + .addExecutionInterceptor(telemetry.newExecutionInterceptor()) + .addExecutionInterceptor(telemetry.newExecutionInterceptor()) + .build(); + builder.overrideConfiguration(overrideConfiguration); + SqsClient client = configureSqsClient(builder.build()); + + client.createQueue(createQueueRequest); + client.sendMessage(sendMessageRequest); + ReceiveMessageResponse response = client.receiveMessage(receiveMessageRequest); + + assertThat(response.messages().size()).isEqualTo(1); + response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); + + assertSqsTraces(true, false); + } +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java new file mode 100644 index 000000000000..275fa2c24f49 --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java @@ -0,0 +1,37 @@ +package io.opentelemetry.instrumentation.awssdk.v2_2; + +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; +import org.junit.jupiter.api.extension.RegisterExtension; +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; +import software.amazon.awssdk.services.sqs.SqsAsyncClient; +import software.amazon.awssdk.services.sqs.SqsClient; + +public abstract class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest { + @RegisterExtension + static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); + + @Override + protected InstrumentationExtension getTesting() { + return testing; + } + + protected static AwsSdkTelemetry telemetry; + + @Override + protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { + return ClientOverrideConfiguration.builder() + .addExecutionInterceptor( + telemetry.newExecutionInterceptor()); + } + + @Override + protected SqsClient configureSqsClient(SqsClient sqsClient) { + return telemetry.wrap(sqsClient); + } + + @Override + protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { + return telemetry.wrap(sqsClient); + } +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java new file mode 100644 index 000000000000..d5043db64433 --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java @@ -0,0 +1,24 @@ +package io.opentelemetry.instrumentation.awssdk.v2_2; + +import org.junit.jupiter.api.BeforeAll; + +/** We want to test the combination of W3C + Xray, as that's what you'll get in prod if you enable W3C. */ +class Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { + + @BeforeAll + static void setup() { + AwsSdkTelemetryBuilder telemetryBuilder = AwsSdkTelemetry.builder(testing.getOpenTelemetry()) + .setCaptureExperimentalSpanAttributes(true); + configure(telemetryBuilder); + telemetry = telemetryBuilder.build(); + } + + static void configure(AwsSdkTelemetryBuilder telemetryBuilder) { + telemetryBuilder.setUseConfiguredPropagatorForMessaging(isSqsAttributeInjectionEnabled()); // Difference to main test + } + + @Override + boolean isSqsAttributeInjectionEnabled() { + return true; + } +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java new file mode 100644 index 000000000000..b857886613f8 --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java @@ -0,0 +1,19 @@ +package io.opentelemetry.instrumentation.awssdk.v2_2; + +class Aws2SqsSuppressReceiveSpansW3CPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { + @Override + void configure(AwsSdkTelemetryBuilder telemetryBuilder) { + telemetryBuilder.setUseConfiguredPropagatorForMessaging(isSqsAttributeInjectionEnabled()) // Difference to main test + .setUseXrayPropagator(isXrayInjectionEnabled()); // Disable to confirm messaging propagator actually works + } + + @Override + boolean isSqsAttributeInjectionEnabled() { + return true; + } + + @Override + boolean isXrayInjectionEnabled() { + return false; + } +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy index a0dd2a8adae0..3dc35fb29b4b 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy @@ -1,393 +1,393 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.awssdk.v2_2 - -import io.opentelemetry.instrumentation.test.InstrumentationSpecification -import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes -import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes -import io.opentelemetry.semconv.ServerAttributes -import io.opentelemetry.semconv.HttpAttributes -import io.opentelemetry.semconv.UrlAttributes -import org.elasticmq.rest.sqs.SQSRestServerBuilder -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration -import software.amazon.awssdk.regions.Region -import software.amazon.awssdk.services.sqs.SqsAsyncClient -import software.amazon.awssdk.services.sqs.SqsBaseClientBuilder -import software.amazon.awssdk.services.sqs.SqsClient -import software.amazon.awssdk.services.sqs.model.CreateQueueRequest -import software.amazon.awssdk.services.sqs.model.MessageAttributeValue -import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest -import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest -import software.amazon.awssdk.services.sqs.model.SendMessageRequest -import spock.lang.Shared - -import static io.opentelemetry.api.trace.SpanKind.CLIENT -import static io.opentelemetry.api.trace.SpanKind.CONSUMER -import static io.opentelemetry.api.trace.SpanKind.PRODUCER - -abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSpecification { - - private static final StaticCredentialsProvider CREDENTIALS_PROVIDER = StaticCredentialsProvider - .create(AwsBasicCredentials.create("my-access-key", "my-secret-key")) - - @Shared - def sqs - - @Shared - int sqsPort - - static Map dummyMessageAttributes(count) { - (0.. e.messageBody("e1").id("i1"), - // 8 attributes, injection always possible - e -> e.messageBody("e2").id("i2") - .messageAttributes(dummyMessageAttributes(8)), - // 10 attributes, injection with custom propagator never possible - e -> e.messageBody("e3").id("i3").messageAttributes(dummyMessageAttributes(10))) - .build() - - boolean isSqsAttributeInjectionEnabled() { - AbstractAws2ClientCoreTest.isSqsAttributeInjectionEnabled() - } - - boolean isXrayInjectionEnabled() { - true - } - - void configureSdkClient(SqsBaseClientBuilder builder) { - builder - .overrideConfiguration(createOverrideConfigurationBuilder().build()) - .endpointOverride(new URI("http://localhost:" + sqsPort)) - builder - .region(Region.AP_NORTHEAST_1) - .credentialsProvider(CREDENTIALS_PROVIDER) - } - - abstract SqsClient configureSqsClient(SqsClient sqsClient) - - abstract SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) - - abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() - - def setupSpec() { - sqs = SQSRestServerBuilder.withPort(0).withInterface("localhost").start() - def server = sqs.waitUntilStarted() - sqsPort = server.localAddress().port - println getClass().name + " SQS server started at: localhost:$sqsPort/" - } - - def cleanupSpec() { - if (sqs != null) { - sqs.stopAndWait() - } - } - - void assertSqsTraces(withParent = false) { - assertTraces(2 + (withParent ? 1 : 0)) { - trace(0, 1) { - - span(0) { - name "Sqs.CreateQueue" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.queue.name" "testSdkSqs" - "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } - "rpc.system" "aws-api" - "rpc.service" "Sqs" - "rpc.method" "CreateQueue" - "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" sqsPort - } - } - } - trace(1, 3) { - span(0) { - name "testSdkSqs publish" - kind PRODUCER - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" - "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } - "rpc.system" "aws-api" - "rpc.method" "SendMessage" - "rpc.service" "Sqs" - "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" sqsPort - "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS - "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" - "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "publish" - "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String - } - } - span(1) { - name "testSdkSqs process" - kind CONSUMER - childOf span(0) - hasNoLinks() - attributes { - "aws.agent" "java-aws-sdk" - "rpc.method" "ReceiveMessage" - "rpc.system" "aws-api" - "rpc.service" "Sqs" - "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" sqsPort - "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS - "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" - "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" - "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String - } - } - span(2) { - name "process child" - childOf span(1) - attributes { - } - } - } - if (withParent) { - /** - * This span represents HTTP "sending of receive message" operation. It's always single, while there can be multiple CONSUMER spans (one per consumed message). - * This one could be suppressed (by IF in TracingRequestHandler#beforeRequest but then HTTP instrumentation span would appear - */ - trace(2, 2) { - span(0) { - name "parent" - hasNoParent() - } - span(1) { - name "Sqs.ReceiveMessage" - kind CLIENT - childOf span(0) - hasNoLinks() - attributes { - "aws.agent" "java-aws-sdk" - "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } - "rpc.method" "ReceiveMessage" - "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" - "rpc.system" "aws-api" - "rpc.service" "Sqs" - "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" sqsPort - } - } - } - } - } - } - - def "simple sqs producer-consumer services: sync"() { - setup: - def builder = SqsClient.builder() - configureSdkClient(builder) - def client = configureSqsClient(builder.build()) - - client.createQueue(createQueueRequest) - - when: - client.sendMessage(sendMessageRequest) - - def resp = client.receiveMessage(receiveMessageRequest) - - then: - resp.messages.size() == 1 - resp.messages.each {message -> runWithSpan("process child") {}} - assertSqsTraces() - } - - def "simple sqs producer-consumer services with parent: sync"() { - setup: - def builder = SqsClient.builder() - configureSdkClient(builder) - def client = configureSqsClient(builder.build()) - - client.createQueue(createQueueRequest) - - when: - client.sendMessage(sendMessageRequest) - - def resp = runWithSpan("parent") { - client.receiveMessage(receiveMessageRequest) - } - - then: - resp.messages.size() == 1 - resp.messages.each {message -> runWithSpan("process child") {}} - assertSqsTraces(true) - } - - def "simple sqs producer-consumer services: async"() { - setup: - def builder = SqsAsyncClient.builder() - configureSdkClient(builder) - def client = configureSqsClient(builder.build()) - - client.createQueue(createQueueRequest).get() - - when: - client.sendMessage(sendMessageRequest).get() - - def resp = client.receiveMessage(receiveMessageRequest).get() - - then: - resp.messages.size() == 1 - resp.messages.each {message -> runWithSpan("process child") {}} - assertSqsTraces() - } - - def "batch sqs producer-consumer services: sync"() { - setup: - def builder = SqsClient.builder() - configureSdkClient(builder) - def client = configureSqsClient(builder.build()) - - client.createQueue(createQueueRequest) - - when: - client.sendMessageBatch(sendMessageBatchRequest) - - def resp = client.receiveMessage(receiveMessageBatchRequest) - def totalAttrs = resp.messages().sum {it.messageAttributes().size() } - - then: - resp.messages().size() == 3 - - // +2: 3 messages, 2x traceparent, 1x not injected due to too many attrs - totalAttrs == 18 + (sqsAttributeInjectionEnabled ? 2 : 0) - - assertTraces(xrayInjectionEnabled ? 2 : 3) { - trace(0, 1) { - - span(0) { - name "Sqs.CreateQueue" - kind CLIENT - } - } - trace(1, xrayInjectionEnabled ? 4 : 3) { - span(0) { - name "testSdkSqs publish" - kind PRODUCER - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" - "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it.trim() == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } - "rpc.system" "aws-api" - "rpc.method" "SendMessageBatch" - "rpc.service" "Sqs" - "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" sqsPort - "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS - "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" - "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "publish" - } - } - for (int i: 1..(xrayInjectionEnabled ? 3 : 2)) { - span(i) { - name "testSdkSqs process" - kind CONSUMER - childOf span(0) - hasNoLinks() - - attributes { - "aws.agent" "java-aws-sdk" - "rpc.method" "ReceiveMessage" - "rpc.system" "aws-api" - "rpc.service" "Sqs" - "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" sqsPort - "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS - "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" - "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" - "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String - } - } - } - } - if (!xrayInjectionEnabled) { - trace(2, 1) { - span(0) { - name "testSdkSqs process" - kind CONSUMER - - // TODO This is not nice at all, and can also happen if producer is not instrumented - hasNoParent() - hasNoLinks() - - attributes { - "aws.agent" "java-aws-sdk" - "rpc.method" "ReceiveMessage" - "rpc.system" "aws-api" - "rpc.service" "Sqs" - "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" sqsPort - "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS - "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" - "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" - "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String - } - } - } - } - } - } -} +///* +// * Copyright The OpenTelemetry Authors +// * SPDX-License-Identifier: Apache-2.0 +// */ +// +//package io.opentelemetry.instrumentation.awssdk.v2_2 +// +//import io.opentelemetry.instrumentation.test.InstrumentationSpecification +//import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes +//import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes +//import io.opentelemetry.semconv.ServerAttributes +//import io.opentelemetry.semconv.HttpAttributes +//import io.opentelemetry.semconv.UrlAttributes +//import org.elasticmq.rest.sqs.SQSRestServerBuilder +//import software.amazon.awssdk.auth.credentials.AwsBasicCredentials +//import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider +//import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration +//import software.amazon.awssdk.regions.Region +//import software.amazon.awssdk.services.sqs.SqsAsyncClient +//import software.amazon.awssdk.services.sqs.SqsBaseClientBuilder +//import software.amazon.awssdk.services.sqs.SqsClient +//import software.amazon.awssdk.services.sqs.model.CreateQueueRequest +//import software.amazon.awssdk.services.sqs.model.MessageAttributeValue +//import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest +//import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest +//import software.amazon.awssdk.services.sqs.model.SendMessageRequest +//import spock.lang.Shared +// +//import static io.opentelemetry.api.trace.SpanKind.CLIENT +//import static io.opentelemetry.api.trace.SpanKind.CONSUMER +//import static io.opentelemetry.api.trace.SpanKind.PRODUCER +// +//abstract class AbstractAws2SqsSuppressReceiveSpansTest2 extends InstrumentationSpecification { +// +// private static final StaticCredentialsProvider CREDENTIALS_PROVIDER = StaticCredentialsProvider +// .create(AwsBasicCredentials.create("my-access-key", "my-secret-key")) +// +// @Shared +// def sqs +// +// @Shared +// int sqsPort +// +// static Map dummyMessageAttributes(count) { +// (0.. e.messageBody("e1").id("i1"), +// // 8 attributes, injection always possible +// e -> e.messageBody("e2").id("i2") +// .messageAttributes(dummyMessageAttributes(8)), +// // 10 attributes, injection with custom propagator never possible +// e -> e.messageBody("e3").id("i3").messageAttributes(dummyMessageAttributes(10))) +// .build() +// +// boolean isSqsAttributeInjectionEnabled() { +// AbstractAws2ClientCoreTest.isSqsAttributeInjectionEnabled() +// } +// +// boolean isXrayInjectionEnabled() { +// true +// } +// +// void configureSdkClient(SqsBaseClientBuilder builder) { +// builder +// .overrideConfiguration(createOverrideConfigurationBuilder().build()) +// .endpointOverride(new URI("http://localhost:" + sqsPort)) +// builder +// .region(Region.AP_NORTHEAST_1) +// .credentialsProvider(CREDENTIALS_PROVIDER) +// } +// +// abstract SqsClient configureSqsClient(SqsClient sqsClient) +// +// abstract SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) +// +// abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() +// +// def setupSpec() { +// sqs = SQSRestServerBuilder.withPort(0).withInterface("localhost").start() +// def server = sqs.waitUntilStarted() +// sqsPort = server.localAddress().port +// println getClass().name + " SQS server started at: localhost:$sqsPort/" +// } +// +// def cleanupSpec() { +// if (sqs != null) { +// sqs.stopAndWait() +// } +// } +// +// void assertSqsTraces(withParent = false) { +// assertTraces(2 + (withParent ? 1 : 0)) { +// trace(0, 1) { +// +// span(0) { +// name "Sqs.CreateQueue" +// kind CLIENT +// hasNoParent() +// attributes { +// "aws.agent" "java-aws-sdk" +// "aws.queue.name" "testSdkSqs" +// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } +// "rpc.system" "aws-api" +// "rpc.service" "Sqs" +// "rpc.method" "CreateQueue" +// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" +// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 +// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } +// "$ServerAttributes.SERVER_ADDRESS" "localhost" +// "$ServerAttributes.SERVER_PORT" sqsPort +// } +// } +// } +// trace(1, 3) { +// span(0) { +// name "testSdkSqs publish" +// kind PRODUCER +// hasNoParent() +// attributes { +// "aws.agent" "java-aws-sdk" +// "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" +// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } +// "rpc.system" "aws-api" +// "rpc.method" "SendMessage" +// "rpc.service" "Sqs" +// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" +// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 +// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } +// "$ServerAttributes.SERVER_ADDRESS" "localhost" +// "$ServerAttributes.SERVER_PORT" sqsPort +// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS +// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" +// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "publish" +// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String +// } +// } +// span(1) { +// name "testSdkSqs process" +// kind CONSUMER +// childOf span(0) +// hasNoLinks() +// attributes { +// "aws.agent" "java-aws-sdk" +// "rpc.method" "ReceiveMessage" +// "rpc.system" "aws-api" +// "rpc.service" "Sqs" +// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" +// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 +// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } +// "$ServerAttributes.SERVER_ADDRESS" "localhost" +// "$ServerAttributes.SERVER_PORT" sqsPort +// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS +// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" +// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" +// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String +// } +// } +// span(2) { +// name "process child" +// childOf span(1) +// attributes { +// } +// } +// } +// if (withParent) { +// /** +// * This span represents HTTP "sending of receive message" operation. It's always single, while there can be multiple CONSUMER spans (one per consumed message). +// * This one could be suppressed (by IF in TracingRequestHandler#beforeRequest but then HTTP instrumentation span would appear +// */ +// trace(2, 2) { +// span(0) { +// name "parent" +// hasNoParent() +// } +// span(1) { +// name "Sqs.ReceiveMessage" +// kind CLIENT +// childOf span(0) +// hasNoLinks() +// attributes { +// "aws.agent" "java-aws-sdk" +// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } +// "rpc.method" "ReceiveMessage" +// "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" +// "rpc.system" "aws-api" +// "rpc.service" "Sqs" +// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" +// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 +// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } +// "$ServerAttributes.SERVER_ADDRESS" "localhost" +// "$ServerAttributes.SERVER_PORT" sqsPort +// } +// } +// } +// } +// } +// } +// +// def "simple sqs producer-consumer services: sync"() { +// setup: +// def builder = SqsClient.builder() +// configureSdkClient(builder) +// def client = configureSqsClient(builder.build()) +// +// client.createQueue(createQueueRequest) +// +// when: +// client.sendMessage(sendMessageRequest) +// +// def resp = client.receiveMessage(receiveMessageRequest) +// +// then: +// resp.messages.size() == 1 +// resp.messages.each {message -> runWithSpan("process child") {}} +// assertSqsTraces() +// } +// +// def "simple sqs producer-consumer services with parent: sync"() { +// setup: +// def builder = SqsClient.builder() +// configureSdkClient(builder) +// def client = configureSqsClient(builder.build()) +// +// client.createQueue(createQueueRequest) +// +// when: +// client.sendMessage(sendMessageRequest) +// +// def resp = runWithSpan("parent") { +// client.receiveMessage(receiveMessageRequest) +// } +// +// then: +// resp.messages.size() == 1 +// resp.messages.each {message -> runWithSpan("process child") {}} +// assertSqsTraces(true) +// } +// +// def "simple sqs producer-consumer services: async"() { +// setup: +// def builder = SqsAsyncClient.builder() +// configureSdkClient(builder) +// def client = configureSqsClient(builder.build()) +// +// client.createQueue(createQueueRequest).get() +// +// when: +// client.sendMessage(sendMessageRequest).get() +// +// def resp = client.receiveMessage(receiveMessageRequest).get() +// +// then: +// resp.messages.size() == 1 +// resp.messages.each {message -> runWithSpan("process child") {}} +// assertSqsTraces() +// } +// +// def "batch sqs producer-consumer services: sync"() { +// setup: +// def builder = SqsClient.builder() +// configureSdkClient(builder) +// def client = configureSqsClient(builder.build()) +// +// client.createQueue(createQueueRequest) +// +// when: +// client.sendMessageBatch(sendMessageBatchRequest) +// +// def resp = client.receiveMessage(receiveMessageBatchRequest) +// def totalAttrs = resp.messages().sum {it.messageAttributes().size() } +// +// then: +// resp.messages().size() == 3 +// +// // +2: 3 messages, 2x traceparent, 1x not injected due to too many attrs +// totalAttrs == 18 + (sqsAttributeInjectionEnabled ? 2 : 0) +// +// assertTraces(xrayInjectionEnabled ? 2 : 3) { +// trace(0, 1) { +// +// span(0) { +// name "Sqs.CreateQueue" +// kind CLIENT +// } +// } +// trace(1, xrayInjectionEnabled ? 4 : 3) { +// span(0) { +// name "testSdkSqs publish" +// kind PRODUCER +// hasNoParent() +// attributes { +// "aws.agent" "java-aws-sdk" +// "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" +// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it.trim() == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } +// "rpc.system" "aws-api" +// "rpc.method" "SendMessageBatch" +// "rpc.service" "Sqs" +// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" +// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 +// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } +// "$ServerAttributes.SERVER_ADDRESS" "localhost" +// "$ServerAttributes.SERVER_PORT" sqsPort +// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS +// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" +// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "publish" +// } +// } +// for (int i: 1..(xrayInjectionEnabled ? 3 : 2)) { +// span(i) { +// name "testSdkSqs process" +// kind CONSUMER +// childOf span(0) +// hasNoLinks() +// +// attributes { +// "aws.agent" "java-aws-sdk" +// "rpc.method" "ReceiveMessage" +// "rpc.system" "aws-api" +// "rpc.service" "Sqs" +// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" +// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 +// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } +// "$ServerAttributes.SERVER_ADDRESS" "localhost" +// "$ServerAttributes.SERVER_PORT" sqsPort +// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS +// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" +// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" +// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String +// } +// } +// } +// } +// if (!xrayInjectionEnabled) { +// trace(2, 1) { +// span(0) { +// name "testSdkSqs process" +// kind CONSUMER +// +// // TODO This is not nice at all, and can also happen if producer is not instrumented +// hasNoParent() +// hasNoLinks() +// +// attributes { +// "aws.agent" "java-aws-sdk" +// "rpc.method" "ReceiveMessage" +// "rpc.system" "aws-api" +// "rpc.service" "Sqs" +// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" +// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 +// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } +// "$ServerAttributes.SERVER_ADDRESS" "localhost" +// "$ServerAttributes.SERVER_PORT" sqsPort +// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS +// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" +// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" +// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String +// } +// } +// } +// } +// } +// } +//} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java new file mode 100644 index 000000000000..f8d839fb98df --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java @@ -0,0 +1,176 @@ +package io.opentelemetry.instrumentation.awssdk.v2_2; + +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import org.apache.pekko.http.scaladsl.Http; +import org.elasticmq.rest.sqs.SQSRestServer; +import org.elasticmq.rest.sqs.SQSRestServerBuilder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.sqs.SqsAsyncClient; +import software.amazon.awssdk.services.sqs.SqsAsyncClientBuilder; +import software.amazon.awssdk.services.sqs.SqsClient; +import software.amazon.awssdk.services.sqs.SqsClientBuilder; +import software.amazon.awssdk.services.sqs.model.CreateQueueRequest; +import software.amazon.awssdk.services.sqs.model.MessageAttributeValue; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest; +import software.amazon.awssdk.services.sqs.model.SendMessageRequest; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public abstract class AbstractAws2SqsBaseTest { + + protected abstract InstrumentationExtension getTesting(); + + protected abstract SqsClient configureSqsClient(SqsClient sqsClient); + + protected abstract SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient); + + protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder(); + + protected static final StaticCredentialsProvider CREDENTIALS_PROVIDER = + StaticCredentialsProvider.create( + AwsBasicCredentials.create("my-access-key", "my-secret-key")); + + protected static int sqsPort; + protected static SQSRestServer sqs; + + static Map dummyMessageAttributes(int count) { + Map map = new HashMap<>(); + for (int i = 0; i < count; i++) { + map.put( + "a" + i, MessageAttributeValue.builder().stringValue("v" + i).dataType("String").build()); + } + return map; + } + + private final String queueUrl = "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"; + + ReceiveMessageRequest receiveMessageRequest = + ReceiveMessageRequest.builder().queueUrl(queueUrl).build(); + + ReceiveMessageRequest receiveMessageBatchRequest = + ReceiveMessageRequest.builder() + .queueUrl(queueUrl) + .maxNumberOfMessages(3) + .messageAttributeNames("All") + .waitTimeSeconds(5) + .build(); + + CreateQueueRequest createQueueRequest = + CreateQueueRequest.builder().queueName("testSdkSqs").build(); + + SendMessageRequest sendMessageRequest = + SendMessageRequest.builder().queueUrl(queueUrl).messageBody("{\"type\": \"hello\"}").build(); + + @SuppressWarnings("unchecked") + SendMessageBatchRequest sendMessageBatchRequest = + SendMessageBatchRequest.builder() + .queueUrl(queueUrl) + .entries( + e -> e.messageBody("e1").id("i1"), + // 8 attributes, injection always possible + e -> e.messageBody("e2").id("i2").messageAttributes(dummyMessageAttributes(8)), + // 10 attributes, injection with custom propagator never possible + e -> e.messageBody("e3").id("i3").messageAttributes(dummyMessageAttributes(10))) + .build(); + + boolean isXrayInjectionEnabled() { + return true; + } + + protected void configureSdkClient(SqsClientBuilder builder) throws URISyntaxException { + builder + .overrideConfiguration(createOverrideConfigurationBuilder().build()) + .endpointOverride(new URI("http://localhost:" + sqsPort)); + builder.region(Region.AP_NORTHEAST_1).credentialsProvider(CREDENTIALS_PROVIDER); + } + + void configureSdkClient(SqsAsyncClientBuilder builder) throws URISyntaxException { + builder + .overrideConfiguration(createOverrideConfigurationBuilder().build()) + .endpointOverride(new URI("http://localhost:" + sqsPort)); + builder.region(Region.AP_NORTHEAST_1).credentialsProvider(CREDENTIALS_PROVIDER); + } + + protected abstract void assertSqsTraces(Boolean withParent, Boolean captureHeaders); + + @BeforeAll + static void setUp() { + sqs = SQSRestServerBuilder.withPort(0).withInterface("localhost").start(); + Http.ServerBinding server = sqs.waitUntilStarted(); + sqsPort = server.localAddress().getPort(); + } + + @AfterAll + static void cleanUp() { + if (sqs != null) { + sqs.stopAndWait(); + } + } + + @Test + void testSimpleSqsProducerConsumerServicesSync() throws URISyntaxException { + SqsClientBuilder builder = SqsClient.builder(); + configureSdkClient(builder); + SqsClient client = configureSqsClient(builder.build()); + + client.createQueue(createQueueRequest); + + client.sendMessage(sendMessageRequest); + + ReceiveMessageResponse response = client.receiveMessage(receiveMessageRequest); + + assertThat(response.messages().size()).isEqualTo(1); + + response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); + assertSqsTraces(false, false); + } + + @Test + void testSimpleSqsProducerConsumerServicesWithParentSync() throws URISyntaxException { + SqsClientBuilder builder = SqsClient.builder(); + configureSdkClient(builder); + SqsClient client = configureSqsClient(builder.build()); + + client.createQueue(createQueueRequest); + client.sendMessage(sendMessageRequest); + + ReceiveMessageResponse response = + getTesting().runWithSpan("parent", () -> client.receiveMessage(receiveMessageRequest)); + + assertThat(response.messages().size()).isEqualTo(1); + + response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); + assertSqsTraces(true, false); + } + + @SuppressWarnings("InterruptedExceptionSwallowed") + @Test + void testSimpleSqsProducerConsumerServicesAsync() throws Exception { + SqsAsyncClientBuilder builder = SqsAsyncClient.builder(); + configureSdkClient(builder); + SqsAsyncClient client = configureSqsClient(builder.build()); + + client.createQueue(createQueueRequest).get(); + client.sendMessage(sendMessageRequest).get(); + + ReceiveMessageResponse response = client.receiveMessage(receiveMessageRequest).get(); + + assertThat(response.messages().size()).isEqualTo(1); + + response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); + assertSqsTraces(false, false); + } + +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java new file mode 100644 index 000000000000..e9bfc02ab352 --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java @@ -0,0 +1,298 @@ +package io.opentelemetry.instrumentation.awssdk.v2_2; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +import io.opentelemetry.sdk.testing.assertj.TraceAssert; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.sqs.SqsClient; +import software.amazon.awssdk.services.sqs.SqsClientBuilder; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; + +import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; +import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD; +import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE; +import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS; +import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT; +import static io.opentelemetry.semconv.UrlAttributes.URL_FULL; +import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_REQUEST_ID; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS; +import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD; +import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE; +import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; + +public abstract class AbstractAws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsBaseTest { + + boolean isSqsAttributeInjectionEnabled() { + // See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor + return ConfigPropertiesUtil.getBoolean("otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false); + } + + @Override + @SuppressWarnings("deprecation") // using deprecated semconv + protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { + List> traceAsserts = + new ArrayList<>( + Arrays.asList( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("Sqs.CreateQueue") + .hasKind(SpanKind.CLIENT) + .hasNoParent() + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(stringKey("aws.queue.name"), "testSdkSqs"), + satisfies( + AWS_REQUEST_ID, + val -> + val.satisfiesAnyOf( + v -> + assertThat(v) + .isEqualTo( + "00000000-0000-0000-0000-000000000000"), + v -> assertThat(v).isEqualTo("UNKNOWN"))), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "CreateQueue"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort))), + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("testSdkSqs publish") + .hasKind(SpanKind.PRODUCER) + .hasNoParent() + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo( + stringKey("aws.queue.url"), + "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), + satisfies( + AWS_REQUEST_ID, + val -> + val.satisfiesAnyOf( + v -> + assertThat(v) + .isEqualTo( + "00000000-0000-0000-0000-000000000000"), + v -> assertThat(v).isEqualTo("UNKNOWN"))), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "SendMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "publish"), + satisfies( + MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))), + span -> + span.hasName("testSdkSqs process") + .hasKind(SpanKind.CONSUMER) + .hasParent(trace.getSpan(0)) + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "process"), + satisfies( + MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class)) + ), + span -> span.hasName("process child") + .hasParent(trace.getSpan(1)).hasAttributes(Attributes.empty())))); + + if (withParent) { + /* + * This span represents HTTP "sending of receive message" operation. It's always single, + * while there can be multiple CONSUMER spans (one per consumed message). + * This one could be suppressed (by IF in TracingRequestHandler#beforeRequest but then + * HTTP instrumentation span would appear) + */ + traceAsserts.add( + trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasNoParent(), + span -> span.hasName("Sqs.ReceiveMessage") + .hasKind(SpanKind.CLIENT) + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo( + stringKey("aws.queue.url"), + "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), + satisfies( + AWS_REQUEST_ID, + val -> + val.satisfiesAnyOf( + v -> + assertThat(v) + .isEqualTo( + "00000000-0000-0000-0000-000000000000"), + v -> assertThat(v).isEqualTo("UNKNOWN"))), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort)))); + } + + getTesting().waitAndAssertTraces(traceAsserts); + } + + + @Test + @SuppressWarnings("deprecation") // using deprecated semconv + void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { + SqsClientBuilder builder = SqsClient.builder(); + configureSdkClient(builder); + SqsClient client = configureSqsClient(builder.build()); + + client.createQueue(createQueueRequest); + client.sendMessageBatch(sendMessageBatchRequest); + + ReceiveMessageResponse response = client.receiveMessage(receiveMessageBatchRequest); + + int totalAttrs = + response.messages().stream().mapToInt(message -> message.messageAttributes().size()).sum(); + + assertThat(response.messages().size()).isEqualTo(3); + + // +2: 3 messages, 2x traceparent, 1x not injected due to too many attrs + assertThat(totalAttrs).isEqualTo(18 + (isSqsAttributeInjectionEnabled() ? 2 : 0)); + + List> traceAsserts = + new ArrayList<>( + Arrays.asList( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("Sqs.CreateQueue").hasKind(SpanKind.CLIENT)), + trace -> { + List> spanAsserts = new ArrayList<>( + singletonList( + span -> + span.hasName("testSdkSqs publish") + .hasKind(SpanKind.PRODUCER) + .hasNoParent() + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo( + stringKey("aws.queue.url"), + "http://localhost:" + sqsPort + + "/000000000000/testSdkSqs"), + satisfies( + AWS_REQUEST_ID, + val -> + val.satisfiesAnyOf( + v -> + assertThat(v.trim()) + .isEqualTo( + "00000000-0000-0000-0000-000000000000"), + v -> assertThat(v.trim()).isEqualTo("UNKNOWN"))), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "SendMessageBatch"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(URL_FULL, + v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "publish")))); + + int iterationNumber = isXrayInjectionEnabled() ? 3 : 2; + for (int i = 1; i <= iterationNumber; i++) { + spanAsserts.add( + span -> span.hasName("testSdkSqs process") + .hasKind(SpanKind.CONSUMER) + .hasParent(trace.getSpan(0)) + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, + v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "process"), + satisfies( + MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class)))); + } + trace.hasSpansSatisfyingExactly(spanAsserts); + } + )); + + if (!isXrayInjectionEnabled()) { + traceAsserts.add( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("testSdkSqs process") + .hasKind(SpanKind.CONSUMER) + // TODO This is not nice at all, and can also happen if producer is not instrumented + .hasNoParent() + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, + v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "process"), + satisfies( + MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))))); + } + getTesting().waitAndAssertTraces(traceAsserts); + } +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java index e8085e14eccf..351f4b4c29e6 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java @@ -14,114 +14,43 @@ import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS; import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT; import static io.opentelemetry.semconv.UrlAttributes.URL_FULL; +import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_REQUEST_ID; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_BATCH_MESSAGE_COUNT; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS; import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD; import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE; import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM; +import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; -import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.sdk.trace.data.SpanData; -import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes; -import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes; import io.opentelemetry.testing.internal.armeria.internal.shaded.guava.collect.ImmutableList; -import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -import org.apache.pekko.http.scaladsl.Http; -import org.elasticmq.rest.sqs.SQSRestServer; -import org.elasticmq.rest.sqs.SQSRestServerBuilder; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.sqs.SqsAsyncClient; -import software.amazon.awssdk.services.sqs.SqsAsyncClientBuilder; import software.amazon.awssdk.services.sqs.SqsClient; import software.amazon.awssdk.services.sqs.SqsClientBuilder; -import software.amazon.awssdk.services.sqs.model.CreateQueueRequest; import software.amazon.awssdk.services.sqs.model.MessageAttributeValue; import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest; import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; -import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest; import software.amazon.awssdk.services.sqs.model.SendMessageRequest; @SuppressWarnings("deprecation") // using deprecated semconv -public abstract class AbstractAws2SqsTracingTest { - - protected abstract InstrumentationExtension getTesting(); - - protected abstract SqsClient configureSqsClient(SqsClient sqsClient); - - protected abstract SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient); - - protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder(); - - private static final StaticCredentialsProvider CREDENTIALS_PROVIDER = - StaticCredentialsProvider.create( - AwsBasicCredentials.create("my-access-key", "my-secret-key")); - - private static int sqsPort; - private static SQSRestServer sqs; - - static Map dummyMessageAttributes(int count) { - Map map = new HashMap<>(); - for (int i = 0; i < count; i++) { - map.put( - "a" + i, MessageAttributeValue.builder().stringValue("v" + i).dataType("String").build()); - } - return map; - } - - private final String queueUrl = "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"; - - ReceiveMessageRequest receiveMessageRequest = - ReceiveMessageRequest.builder().queueUrl(queueUrl).build(); - - ReceiveMessageRequest receiveMessageBatchRequest = - ReceiveMessageRequest.builder() - .queueUrl(queueUrl) - .maxNumberOfMessages(3) - .messageAttributeNames("All") - .waitTimeSeconds(5) - .build(); - - CreateQueueRequest createQueueRequest = - CreateQueueRequest.builder().queueName("testSdkSqs").build(); - - SendMessageRequest sendMessageRequest = - SendMessageRequest.builder().queueUrl(queueUrl).messageBody("{\"type\": \"hello\"}").build(); - - @SuppressWarnings("unchecked") - SendMessageBatchRequest sendMessageBatchRequest = - SendMessageBatchRequest.builder() - .queueUrl(queueUrl) - .entries( - e -> e.messageBody("e1").id("i1"), - // 8 attributes, injection always possible - e -> e.messageBody("e2").id("i2").messageAttributes(dummyMessageAttributes(8)), - // 10 attributes, injection with custom propagator never possible - e -> e.messageBody("e3").id("i3").messageAttributes(dummyMessageAttributes(10))) - .build(); +public abstract class AbstractAws2SqsTracingTest extends AbstractAws2SqsBaseTest { boolean isSqsAttributeInjectionEnabled() { // See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor @@ -129,39 +58,8 @@ boolean isSqsAttributeInjectionEnabled() { "otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false); } - boolean isXrayInjectionEnabled() { - return true; - } - - void configureSdkClient(SqsClientBuilder builder) throws URISyntaxException { - builder - .overrideConfiguration(createOverrideConfigurationBuilder().build()) - .endpointOverride(new URI("http://localhost:" + sqsPort)); - builder.region(Region.AP_NORTHEAST_1).credentialsProvider(CREDENTIALS_PROVIDER); - } - - void configureSdkClient(SqsAsyncClientBuilder builder) throws URISyntaxException { - builder - .overrideConfiguration(createOverrideConfigurationBuilder().build()) - .endpointOverride(new URI("http://localhost:" + sqsPort)); - builder.region(Region.AP_NORTHEAST_1).credentialsProvider(CREDENTIALS_PROVIDER); - } - - @BeforeAll - static void setUp() { - sqs = SQSRestServerBuilder.withPort(0).withInterface("localhost").start(); - Http.ServerBinding server = sqs.waitUntilStarted(); - sqsPort = server.localAddress().getPort(); - } - - @AfterAll - static void cleanUp() { - if (sqs != null) { - sqs.stopAndWait(); - } - } - - void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { + @Override + protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { int offset = withParent ? 2 : 0; AtomicReference publishSpan = new AtomicReference<>(); @@ -177,7 +75,7 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { equalTo(stringKey("aws.agent"), "java-aws-sdk"), equalTo(stringKey("aws.queue.name"), "testSdkSqs"), satisfies( - AwsIncubatingAttributes.AWS_REQUEST_ID, + AWS_REQUEST_ID, val -> val.satisfiesAnyOf( v -> @@ -206,7 +104,7 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { stringKey("aws.queue.url"), "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), satisfies( - AwsIncubatingAttributes.AWS_REQUEST_ID, + AWS_REQUEST_ID, val -> val.satisfiesAnyOf( v -> @@ -223,10 +121,7 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), equalTo(SERVER_ADDRESS, "localhost"), equalTo(SERVER_PORT, sqsPort), - equalTo( - MESSAGING_SYSTEM, - MessagingIncubatingAttributes.MessagingSystemIncubatingValues - .AWS_SQS), + equalTo(MESSAGING_SYSTEM, AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "publish"), satisfies( @@ -266,7 +161,7 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { stringKey("aws.queue.url"), "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), satisfies( - AwsIncubatingAttributes.AWS_REQUEST_ID, + AWS_REQUEST_ID, val -> val.satisfiesAnyOf( v -> @@ -303,8 +198,7 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { equalTo(SERVER_PORT, sqsPort), equalTo( MESSAGING_SYSTEM, - MessagingIncubatingAttributes - .MessagingSystemIncubatingValues.AWS_SQS), + AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "receive"), equalTo(MESSAGING_BATCH_MESSAGE_COUNT, 1))); @@ -341,10 +235,7 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), equalTo(SERVER_ADDRESS, "localhost"), equalTo(SERVER_PORT, sqsPort), - equalTo( - MESSAGING_SYSTEM, - MessagingIncubatingAttributes - .MessagingSystemIncubatingValues.AWS_SQS), + equalTo(MESSAGING_SYSTEM, AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "process"), satisfies( @@ -354,7 +245,7 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { attributes.add( satisfies( stringArrayKey("messaging.header.test_message_header"), - v -> v.isEqualTo(ImmutableList.of("test")))); + v -> v.isEqualTo(singletonList("test")))); } span.hasName("testSdkSqs process") @@ -378,24 +269,6 @@ void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { }); } - @Test - void testSimpleSqsProducerConsumerServicesSync() throws URISyntaxException { - SqsClientBuilder builder = SqsClient.builder(); - configureSdkClient(builder); - SqsClient client = configureSqsClient(builder.build()); - - client.createQueue(createQueueRequest); - - client.sendMessage(sendMessageRequest); - - ReceiveMessageResponse response = client.receiveMessage(receiveMessageRequest); - - assertThat(response.messages().size()).isEqualTo(1); - - response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); - assertSqsTraces(false, false); - } - @Test void testCaptureMessageHeaderAsAttributeSpan() throws URISyntaxException { SqsClientBuilder builder = SqsClient.builder(); @@ -423,42 +296,6 @@ void testCaptureMessageHeaderAsAttributeSpan() throws URISyntaxException { assertSqsTraces(false, true); } - @Test - void testSimpleSqsProducerConsumerServicesWithParentSync() throws URISyntaxException { - SqsClientBuilder builder = SqsClient.builder(); - configureSdkClient(builder); - SqsClient client = configureSqsClient(builder.build()); - - client.createQueue(createQueueRequest); - client.sendMessage(sendMessageRequest); - - ReceiveMessageResponse response = - getTesting().runWithSpan("parent", () -> client.receiveMessage(receiveMessageRequest)); - - assertThat(response.messages().size()).isEqualTo(1); - - response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); - assertSqsTraces(true, false); - } - - @SuppressWarnings("InterruptedExceptionSwallowed") - @Test - void testSimpleSqsProducerConsumerServicesAsync() throws Exception { - SqsAsyncClientBuilder builder = SqsAsyncClient.builder(); - configureSdkClient(builder); - SqsAsyncClient client = configureSqsClient(builder.build()); - - client.createQueue(createQueueRequest).get(); - client.sendMessage(sendMessageRequest).get(); - - ReceiveMessageResponse response = client.receiveMessage(receiveMessageRequest).get(); - - assertThat(response.messages().size()).isEqualTo(1); - - response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); - assertSqsTraces(false, false); - } - @Test void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { SqsClientBuilder builder = SqsClient.builder(); @@ -499,7 +336,7 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { stringKey("aws.queue.url"), "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), satisfies( - AwsIncubatingAttributes.AWS_REQUEST_ID, + AWS_REQUEST_ID, val -> val.satisfiesAnyOf( v -> @@ -515,10 +352,7 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), equalTo(SERVER_ADDRESS, "localhost"), equalTo(SERVER_PORT, sqsPort), - equalTo( - MESSAGING_SYSTEM, - MessagingIncubatingAttributes.MessagingSystemIncubatingValues - .AWS_SQS), + equalTo(MESSAGING_SYSTEM, AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "publish"))); }, @@ -540,10 +374,7 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), equalTo(SERVER_ADDRESS, "localhost"), equalTo(SERVER_PORT, sqsPort), - equalTo( - MESSAGING_SYSTEM, - MessagingIncubatingAttributes.MessagingSystemIncubatingValues - .AWS_SQS), + equalTo(MESSAGING_SYSTEM, AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "receive"), equalTo(MESSAGING_BATCH_MESSAGE_COUNT, 3))); @@ -585,10 +416,7 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { v -> v.startsWith("http://localhost:" + sqsPort)), equalTo(SERVER_ADDRESS, "localhost"), equalTo(SERVER_PORT, sqsPort), - equalTo( - MESSAGING_SYSTEM, - MessagingIncubatingAttributes - .MessagingSystemIncubatingValues.AWS_SQS), + equalTo(MESSAGING_SYSTEM, AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "process"), satisfies( From 883a16302a15eb7e40cc0268298c53ae7b3541b7 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 14 Dec 2024 16:53:49 -0500 Subject: [PATCH 02/11] converted tests green --- .../Aws2SqsSuppressReceiveSpansTest.groovy | 29 -- .../v2_2/Aws2SqsSuppressReceiveSpansTest.java | 5 + ...ressReceiveSpansDefaultPropagatorTest.java | 34 +- .../v2_2/Aws2SqsSuppressReceiveSpansTest.java | 25 +- ...ansW3CPropagatorAndXrayPropagatorTest.java | 29 +- ...SuppressReceiveSpansW3CPropagatorTest.java | 14 +- ...ractAws2SqsSuppressReceiveSpansTest.groovy | 393 ------------------ .../awssdk/v2_2/AbstractAws2SqsBaseTest.java | 28 +- ...stractAws2SqsSuppressReceiveSpansTest.java | 275 ++++++------ .../v2_2/AbstractAws2SqsTracingTest.java | 47 +-- 10 files changed, 224 insertions(+), 655 deletions(-) delete mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy delete mode 100644 instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy deleted file mode 100644 index 9aa812f746a7..000000000000 --- a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/groovy/Aws2SqsSuppressReceiveSpansTest.groovy +++ /dev/null @@ -1,29 +0,0 @@ -///* -// * Copyright The OpenTelemetry Authors -// * SPDX-License-Identifier: Apache-2.0 -// */ -// -//import io.opentelemetry.instrumentation.awssdk.v2_2.AbstractAws2SqsSuppressReceiveSpansTest -//import io.opentelemetry.instrumentation.test.AgentTestTrait -//import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration -//import software.amazon.awssdk.services.sqs.SqsAsyncClient -//import software.amazon.awssdk.services.sqs.SqsClient -// -//class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest implements AgentTestTrait { -// -// -// @Override -// ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { -// return ClientOverrideConfiguration.builder() -// } -// -// @Override -// SqsClient configureSqsClient(SqsClient sqsClient) { -// return sqsClient -// } -// -// @Override -// SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { -// return sqsClient -// } -//} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java index e68eee5afa2a..e230874a3e20 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.awssdk.v2_2; import io.opentelemetry.instrumentation.awssdk.v2_2.AbstractAws2SqsSuppressReceiveSpansTest; diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java index 067d6008f871..7204ec331758 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java @@ -1,26 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.awssdk.v2_2; -import org.junit.jupiter.api.BeforeAll; +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URISyntaxException; import org.junit.jupiter.api.Test; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.sqs.SqsClient; import software.amazon.awssdk.services.sqs.SqsClientBuilder; import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; -import java.net.URISyntaxException; - -import static org.assertj.core.api.Assertions.assertThat; class Aws2SqsSuppressReceiveSpansDefaultPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { - @BeforeAll - static void setup() { - AwsSdkTelemetryBuilder telemetryBuilder = AwsSdkTelemetry.builder(testing.getOpenTelemetry()) - .setCaptureExperimentalSpanAttributes(true); - configure(telemetryBuilder); - telemetry = telemetryBuilder.build(); - } - - static void configure(AwsSdkTelemetryBuilder telemetryBuilder) {} + @Override + protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) {} @Override boolean isSqsAttributeInjectionEnabled() { @@ -31,10 +28,11 @@ boolean isSqsAttributeInjectionEnabled() { void testDuplicateTracingInterceptor() throws URISyntaxException { SqsClientBuilder builder = SqsClient.builder(); configureSdkClient(builder); - ClientOverrideConfiguration overrideConfiguration = ClientOverrideConfiguration.builder() - .addExecutionInterceptor(telemetry.newExecutionInterceptor()) - .addExecutionInterceptor(telemetry.newExecutionInterceptor()) - .build(); + ClientOverrideConfiguration overrideConfiguration = + ClientOverrideConfiguration.builder() + .addExecutionInterceptor(telemetry.newExecutionInterceptor()) + .addExecutionInterceptor(telemetry.newExecutionInterceptor()) + .build(); builder.overrideConfiguration(overrideConfiguration); SqsClient client = configureSqsClient(builder.build()); @@ -45,6 +43,6 @@ void testDuplicateTracingInterceptor() throws URISyntaxException { assertThat(response.messages().size()).isEqualTo(1); response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); - assertSqsTraces(true, false); + assertSqsTraces(false, false); } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java index 275fa2c24f49..54a7906080e1 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java @@ -1,28 +1,45 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.awssdk.v2_2; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.sqs.SqsAsyncClient; import software.amazon.awssdk.services.sqs.SqsClient; -public abstract class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest { +public abstract class Aws2SqsSuppressReceiveSpansTest + extends AbstractAws2SqsSuppressReceiveSpansTest { @RegisterExtension static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); + @BeforeEach + void setup() { + AwsSdkTelemetryBuilder telemetryBuilder = + AwsSdkTelemetry.builder(getTesting().getOpenTelemetry()) + .setCaptureExperimentalSpanAttributes(true); + configure(telemetryBuilder); + telemetry = telemetryBuilder.build(); + } + @Override protected InstrumentationExtension getTesting() { return testing; } - protected static AwsSdkTelemetry telemetry; + protected abstract void configure(AwsSdkTelemetryBuilder telemetryBuilder); + + protected AwsSdkTelemetry telemetry; @Override protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { return ClientOverrideConfiguration.builder() - .addExecutionInterceptor( - telemetry.newExecutionInterceptor()); + .addExecutionInterceptor(telemetry.newExecutionInterceptor()); } @Override diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java index d5043db64433..fdcba28cf539 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java @@ -1,20 +1,21 @@ -package io.opentelemetry.instrumentation.awssdk.v2_2; +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ -import org.junit.jupiter.api.BeforeAll; +package io.opentelemetry.instrumentation.awssdk.v2_2; -/** We want to test the combination of W3C + Xray, as that's what you'll get in prod if you enable W3C. */ -class Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { +/** + * We want to test the combination of W3C + Xray, as that's what you'll get in prod if you enable + * W3C. + */ +class Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest + extends Aws2SqsSuppressReceiveSpansTest { - @BeforeAll - static void setup() { - AwsSdkTelemetryBuilder telemetryBuilder = AwsSdkTelemetry.builder(testing.getOpenTelemetry()) - .setCaptureExperimentalSpanAttributes(true); - configure(telemetryBuilder); - telemetry = telemetryBuilder.build(); - } - - static void configure(AwsSdkTelemetryBuilder telemetryBuilder) { - telemetryBuilder.setUseConfiguredPropagatorForMessaging(isSqsAttributeInjectionEnabled()); // Difference to main test + @Override + protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) { + telemetryBuilder.setUseConfiguredPropagatorForMessaging( + isSqsAttributeInjectionEnabled()); // Difference to main test } @Override diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java index b857886613f8..d370880e73a2 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java @@ -1,10 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.awssdk.v2_2; class Aws2SqsSuppressReceiveSpansW3CPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { @Override - void configure(AwsSdkTelemetryBuilder telemetryBuilder) { - telemetryBuilder.setUseConfiguredPropagatorForMessaging(isSqsAttributeInjectionEnabled()) // Difference to main test - .setUseXrayPropagator(isXrayInjectionEnabled()); // Disable to confirm messaging propagator actually works + protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) { + telemetryBuilder + .setUseConfiguredPropagatorForMessaging( + isSqsAttributeInjectionEnabled()) // Difference to main test + .setUseXrayPropagator( + isXrayInjectionEnabled()); // Disable to confirm messaging propagator actually works } @Override diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy deleted file mode 100644 index 3dc35fb29b4b..000000000000 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy +++ /dev/null @@ -1,393 +0,0 @@ -///* -// * Copyright The OpenTelemetry Authors -// * SPDX-License-Identifier: Apache-2.0 -// */ -// -//package io.opentelemetry.instrumentation.awssdk.v2_2 -// -//import io.opentelemetry.instrumentation.test.InstrumentationSpecification -//import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes -//import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes -//import io.opentelemetry.semconv.ServerAttributes -//import io.opentelemetry.semconv.HttpAttributes -//import io.opentelemetry.semconv.UrlAttributes -//import org.elasticmq.rest.sqs.SQSRestServerBuilder -//import software.amazon.awssdk.auth.credentials.AwsBasicCredentials -//import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider -//import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration -//import software.amazon.awssdk.regions.Region -//import software.amazon.awssdk.services.sqs.SqsAsyncClient -//import software.amazon.awssdk.services.sqs.SqsBaseClientBuilder -//import software.amazon.awssdk.services.sqs.SqsClient -//import software.amazon.awssdk.services.sqs.model.CreateQueueRequest -//import software.amazon.awssdk.services.sqs.model.MessageAttributeValue -//import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest -//import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest -//import software.amazon.awssdk.services.sqs.model.SendMessageRequest -//import spock.lang.Shared -// -//import static io.opentelemetry.api.trace.SpanKind.CLIENT -//import static io.opentelemetry.api.trace.SpanKind.CONSUMER -//import static io.opentelemetry.api.trace.SpanKind.PRODUCER -// -//abstract class AbstractAws2SqsSuppressReceiveSpansTest2 extends InstrumentationSpecification { -// -// private static final StaticCredentialsProvider CREDENTIALS_PROVIDER = StaticCredentialsProvider -// .create(AwsBasicCredentials.create("my-access-key", "my-secret-key")) -// -// @Shared -// def sqs -// -// @Shared -// int sqsPort -// -// static Map dummyMessageAttributes(count) { -// (0.. e.messageBody("e1").id("i1"), -// // 8 attributes, injection always possible -// e -> e.messageBody("e2").id("i2") -// .messageAttributes(dummyMessageAttributes(8)), -// // 10 attributes, injection with custom propagator never possible -// e -> e.messageBody("e3").id("i3").messageAttributes(dummyMessageAttributes(10))) -// .build() -// -// boolean isSqsAttributeInjectionEnabled() { -// AbstractAws2ClientCoreTest.isSqsAttributeInjectionEnabled() -// } -// -// boolean isXrayInjectionEnabled() { -// true -// } -// -// void configureSdkClient(SqsBaseClientBuilder builder) { -// builder -// .overrideConfiguration(createOverrideConfigurationBuilder().build()) -// .endpointOverride(new URI("http://localhost:" + sqsPort)) -// builder -// .region(Region.AP_NORTHEAST_1) -// .credentialsProvider(CREDENTIALS_PROVIDER) -// } -// -// abstract SqsClient configureSqsClient(SqsClient sqsClient) -// -// abstract SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) -// -// abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() -// -// def setupSpec() { -// sqs = SQSRestServerBuilder.withPort(0).withInterface("localhost").start() -// def server = sqs.waitUntilStarted() -// sqsPort = server.localAddress().port -// println getClass().name + " SQS server started at: localhost:$sqsPort/" -// } -// -// def cleanupSpec() { -// if (sqs != null) { -// sqs.stopAndWait() -// } -// } -// -// void assertSqsTraces(withParent = false) { -// assertTraces(2 + (withParent ? 1 : 0)) { -// trace(0, 1) { -// -// span(0) { -// name "Sqs.CreateQueue" -// kind CLIENT -// hasNoParent() -// attributes { -// "aws.agent" "java-aws-sdk" -// "aws.queue.name" "testSdkSqs" -// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } -// "rpc.system" "aws-api" -// "rpc.service" "Sqs" -// "rpc.method" "CreateQueue" -// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" -// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 -// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } -// "$ServerAttributes.SERVER_ADDRESS" "localhost" -// "$ServerAttributes.SERVER_PORT" sqsPort -// } -// } -// } -// trace(1, 3) { -// span(0) { -// name "testSdkSqs publish" -// kind PRODUCER -// hasNoParent() -// attributes { -// "aws.agent" "java-aws-sdk" -// "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" -// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } -// "rpc.system" "aws-api" -// "rpc.method" "SendMessage" -// "rpc.service" "Sqs" -// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" -// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 -// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } -// "$ServerAttributes.SERVER_ADDRESS" "localhost" -// "$ServerAttributes.SERVER_PORT" sqsPort -// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS -// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" -// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "publish" -// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String -// } -// } -// span(1) { -// name "testSdkSqs process" -// kind CONSUMER -// childOf span(0) -// hasNoLinks() -// attributes { -// "aws.agent" "java-aws-sdk" -// "rpc.method" "ReceiveMessage" -// "rpc.system" "aws-api" -// "rpc.service" "Sqs" -// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" -// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 -// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } -// "$ServerAttributes.SERVER_ADDRESS" "localhost" -// "$ServerAttributes.SERVER_PORT" sqsPort -// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS -// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" -// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" -// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String -// } -// } -// span(2) { -// name "process child" -// childOf span(1) -// attributes { -// } -// } -// } -// if (withParent) { -// /** -// * This span represents HTTP "sending of receive message" operation. It's always single, while there can be multiple CONSUMER spans (one per consumed message). -// * This one could be suppressed (by IF in TracingRequestHandler#beforeRequest but then HTTP instrumentation span would appear -// */ -// trace(2, 2) { -// span(0) { -// name "parent" -// hasNoParent() -// } -// span(1) { -// name "Sqs.ReceiveMessage" -// kind CLIENT -// childOf span(0) -// hasNoLinks() -// attributes { -// "aws.agent" "java-aws-sdk" -// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } -// "rpc.method" "ReceiveMessage" -// "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" -// "rpc.system" "aws-api" -// "rpc.service" "Sqs" -// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" -// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 -// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } -// "$ServerAttributes.SERVER_ADDRESS" "localhost" -// "$ServerAttributes.SERVER_PORT" sqsPort -// } -// } -// } -// } -// } -// } -// -// def "simple sqs producer-consumer services: sync"() { -// setup: -// def builder = SqsClient.builder() -// configureSdkClient(builder) -// def client = configureSqsClient(builder.build()) -// -// client.createQueue(createQueueRequest) -// -// when: -// client.sendMessage(sendMessageRequest) -// -// def resp = client.receiveMessage(receiveMessageRequest) -// -// then: -// resp.messages.size() == 1 -// resp.messages.each {message -> runWithSpan("process child") {}} -// assertSqsTraces() -// } -// -// def "simple sqs producer-consumer services with parent: sync"() { -// setup: -// def builder = SqsClient.builder() -// configureSdkClient(builder) -// def client = configureSqsClient(builder.build()) -// -// client.createQueue(createQueueRequest) -// -// when: -// client.sendMessage(sendMessageRequest) -// -// def resp = runWithSpan("parent") { -// client.receiveMessage(receiveMessageRequest) -// } -// -// then: -// resp.messages.size() == 1 -// resp.messages.each {message -> runWithSpan("process child") {}} -// assertSqsTraces(true) -// } -// -// def "simple sqs producer-consumer services: async"() { -// setup: -// def builder = SqsAsyncClient.builder() -// configureSdkClient(builder) -// def client = configureSqsClient(builder.build()) -// -// client.createQueue(createQueueRequest).get() -// -// when: -// client.sendMessage(sendMessageRequest).get() -// -// def resp = client.receiveMessage(receiveMessageRequest).get() -// -// then: -// resp.messages.size() == 1 -// resp.messages.each {message -> runWithSpan("process child") {}} -// assertSqsTraces() -// } -// -// def "batch sqs producer-consumer services: sync"() { -// setup: -// def builder = SqsClient.builder() -// configureSdkClient(builder) -// def client = configureSqsClient(builder.build()) -// -// client.createQueue(createQueueRequest) -// -// when: -// client.sendMessageBatch(sendMessageBatchRequest) -// -// def resp = client.receiveMessage(receiveMessageBatchRequest) -// def totalAttrs = resp.messages().sum {it.messageAttributes().size() } -// -// then: -// resp.messages().size() == 3 -// -// // +2: 3 messages, 2x traceparent, 1x not injected due to too many attrs -// totalAttrs == 18 + (sqsAttributeInjectionEnabled ? 2 : 0) -// -// assertTraces(xrayInjectionEnabled ? 2 : 3) { -// trace(0, 1) { -// -// span(0) { -// name "Sqs.CreateQueue" -// kind CLIENT -// } -// } -// trace(1, xrayInjectionEnabled ? 4 : 3) { -// span(0) { -// name "testSdkSqs publish" -// kind PRODUCER -// hasNoParent() -// attributes { -// "aws.agent" "java-aws-sdk" -// "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" -// "$AwsIncubatingAttributes.AWS_REQUEST_ID" { it.trim() == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" } -// "rpc.system" "aws-api" -// "rpc.method" "SendMessageBatch" -// "rpc.service" "Sqs" -// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" -// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 -// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } -// "$ServerAttributes.SERVER_ADDRESS" "localhost" -// "$ServerAttributes.SERVER_PORT" sqsPort -// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS -// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" -// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "publish" -// } -// } -// for (int i: 1..(xrayInjectionEnabled ? 3 : 2)) { -// span(i) { -// name "testSdkSqs process" -// kind CONSUMER -// childOf span(0) -// hasNoLinks() -// -// attributes { -// "aws.agent" "java-aws-sdk" -// "rpc.method" "ReceiveMessage" -// "rpc.system" "aws-api" -// "rpc.service" "Sqs" -// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" -// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 -// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } -// "$ServerAttributes.SERVER_ADDRESS" "localhost" -// "$ServerAttributes.SERVER_PORT" sqsPort -// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS -// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" -// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" -// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String -// } -// } -// } -// } -// if (!xrayInjectionEnabled) { -// trace(2, 1) { -// span(0) { -// name "testSdkSqs process" -// kind CONSUMER -// -// // TODO This is not nice at all, and can also happen if producer is not instrumented -// hasNoParent() -// hasNoLinks() -// -// attributes { -// "aws.agent" "java-aws-sdk" -// "rpc.method" "ReceiveMessage" -// "rpc.system" "aws-api" -// "rpc.service" "Sqs" -// "$HttpAttributes.HTTP_REQUEST_METHOD" "POST" -// "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 -// "$UrlAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } -// "$ServerAttributes.SERVER_ADDRESS" "localhost" -// "$ServerAttributes.SERVER_PORT" sqsPort -// "$MessagingIncubatingAttributes.MESSAGING_SYSTEM" MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS -// "$MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" -// "$MessagingIncubatingAttributes.MESSAGING_OPERATION" "process" -// "$MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID" String -// } -// } -// } -// } -// } -// } -//} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java index f8d839fb98df..4cd293302557 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java @@ -1,6 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.awssdk.v2_2; +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; import org.apache.pekko.http.scaladsl.Http; import org.elasticmq.rest.sqs.SQSRestServer; import org.elasticmq.rest.sqs.SQSRestServerBuilder; @@ -21,12 +33,6 @@ import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest; import software.amazon.awssdk.services.sqs.model.SendMessageRequest; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; public abstract class AbstractAws2SqsBaseTest { @@ -54,7 +60,7 @@ static Map dummyMessageAttributes(int count) { return map; } - private final String queueUrl = "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"; + protected final String queueUrl = "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"; ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).build(); @@ -103,6 +109,12 @@ void configureSdkClient(SqsAsyncClientBuilder builder) throws URISyntaxException builder.region(Region.AP_NORTHEAST_1).credentialsProvider(CREDENTIALS_PROVIDER); } + boolean isSqsAttributeInjectionEnabled() { + // See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor + return ConfigPropertiesUtil.getBoolean( + "otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false); + } + protected abstract void assertSqsTraces(Boolean withParent, Boolean captureHeaders); @BeforeAll @@ -126,7 +138,6 @@ void testSimpleSqsProducerConsumerServicesSync() throws URISyntaxException { SqsClient client = configureSqsClient(builder.build()); client.createQueue(createQueueRequest); - client.sendMessage(sendMessageRequest); ReceiveMessageResponse response = client.receiveMessage(receiveMessageRequest); @@ -172,5 +183,4 @@ void testSimpleSqsProducerConsumerServicesAsync() throws Exception { response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); assertSqsTraces(false, false); } - } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java index e9bfc02ab352..f3b59ba197b0 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java @@ -1,19 +1,9 @@ -package io.opentelemetry.instrumentation.awssdk.v2_2; +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; -import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; -import io.opentelemetry.sdk.testing.assertj.TraceAssert; -import org.junit.jupiter.api.Test; -import software.amazon.awssdk.services.sqs.SqsClient; -import software.amazon.awssdk.services.sqs.SqsClientBuilder; -import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.function.Consumer; +package io.opentelemetry.instrumentation.awssdk.v2_2; import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; @@ -35,12 +25,21 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; -public abstract class AbstractAws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsBaseTest { +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +import io.opentelemetry.sdk.testing.assertj.TraceAssert; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.sqs.SqsClient; +import software.amazon.awssdk.services.sqs.SqsClientBuilder; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; - boolean isSqsAttributeInjectionEnabled() { - // See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor - return ConfigPropertiesUtil.getBoolean("otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false); - } +public abstract class AbstractAws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsBaseTest { @Override @SuppressWarnings("deprecation") // using deprecated semconv @@ -60,12 +59,8 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { satisfies( AWS_REQUEST_ID, val -> - val.satisfiesAnyOf( - v -> - assertThat(v) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v).isEqualTo("UNKNOWN"))), + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), equalTo(RPC_SYSTEM, "aws-api"), equalTo(RPC_SERVICE, "Sqs"), equalTo(RPC_METHOD, "CreateQueue"), @@ -83,18 +78,12 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { .hasNoParent() .hasAttributesSatisfyingExactly( equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo( - stringKey("aws.queue.url"), - "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), + equalTo(stringKey("aws.queue.url"), queueUrl), satisfies( AWS_REQUEST_ID, val -> - val.satisfiesAnyOf( - v -> - assertThat(v) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v).isEqualTo("UNKNOWN"))), + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), equalTo(RPC_SYSTEM, "aws-api"), equalTo(RPC_SERVICE, "Sqs"), equalTo(RPC_METHOD, "SendMessage"), @@ -129,10 +118,11 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "process"), satisfies( - MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class)) - ), - span -> span.hasName("process child") - .hasParent(trace.getSpan(1)).hasAttributes(Attributes.empty())))); + MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))), + span -> + span.hasName("process child") + .hasParent(trace.getSpan(1)) + .hasAttributes(Attributes.empty())))); if (withParent) { /* @@ -142,40 +132,34 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { * HTTP instrumentation span would appear) */ traceAsserts.add( - trace -> trace.hasSpansSatisfyingExactly( - span -> span.hasName("parent").hasNoParent(), - span -> span.hasName("Sqs.ReceiveMessage") - .hasKind(SpanKind.CLIENT) - .hasTotalRecordedLinks(0) - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo( - stringKey("aws.queue.url"), - "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), - satisfies( - AWS_REQUEST_ID, - val -> - val.satisfiesAnyOf( - v -> - assertThat(v) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v).isEqualTo("UNKNOWN"))), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "ReceiveMessage"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort)))); + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasNoParent(), + span -> + span.hasName("Sqs.ReceiveMessage") + .hasKind(SpanKind.CLIENT) + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(stringKey("aws.queue.url"), queueUrl), + satisfies( + AWS_REQUEST_ID, + val -> + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort)))); } getTesting().waitAndAssertTraces(traceAsserts); } - @Test @SuppressWarnings("deprecation") // using deprecated semconv void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { @@ -191,6 +175,9 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { int totalAttrs = response.messages().stream().mapToInt(message -> message.messageAttributes().size()).sum(); + // generates the process spans + response.messages().forEach(message -> {}); + assertThat(response.messages().size()).isEqualTo(3); // +2: 3 messages, 2x traceparent, 1x not injected due to too many attrs @@ -203,95 +190,87 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { trace.hasSpansSatisfyingExactly( span -> span.hasName("Sqs.CreateQueue").hasKind(SpanKind.CLIENT)), trace -> { - List> spanAsserts = new ArrayList<>( - singletonList( - span -> - span.hasName("testSdkSqs publish") - .hasKind(SpanKind.PRODUCER) - .hasNoParent() - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo( - stringKey("aws.queue.url"), - "http://localhost:" + sqsPort - + "/000000000000/testSdkSqs"), - satisfies( - AWS_REQUEST_ID, - val -> - val.satisfiesAnyOf( - v -> - assertThat(v.trim()) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v.trim()).isEqualTo("UNKNOWN"))), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "SendMessageBatch"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies(URL_FULL, - v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "publish")))); + List> spanAsserts = + new ArrayList<>( + singletonList( + span -> + span.hasName("testSdkSqs publish") + .hasKind(SpanKind.PRODUCER) + .hasNoParent() + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(stringKey("aws.queue.url"), queueUrl), + satisfies( + AWS_REQUEST_ID, + val -> + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "SendMessageBatch"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, + v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "publish")))); - int iterationNumber = isXrayInjectionEnabled() ? 3 : 2; - for (int i = 1; i <= iterationNumber; i++) { + for (int i = 0; i <= (isXrayInjectionEnabled() ? 2 : 1); i++) { spanAsserts.add( - span -> span.hasName("testSdkSqs process") - .hasKind(SpanKind.CONSUMER) - .hasParent(trace.getSpan(0)) - .hasTotalRecordedLinks(0) - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "ReceiveMessage"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, - v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "process"), - satisfies( - MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class)))); + span -> + span.hasName("testSdkSqs process") + .hasKind(SpanKind.CONSUMER) + .hasParent(trace.getSpan(0)) + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies( + URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "process"), + satisfies( + MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class)))); } trace.hasSpansSatisfyingExactly(spanAsserts); - } - )); + })); if (!isXrayInjectionEnabled()) { traceAsserts.add( trace -> trace.hasSpansSatisfyingExactly( - span -> span.hasName("testSdkSqs process") - .hasKind(SpanKind.CONSUMER) - // TODO This is not nice at all, and can also happen if producer is not instrumented - .hasNoParent() - .hasTotalRecordedLinks(0) - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "ReceiveMessage"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, - v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "process"), - satisfies( - MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))))); + span -> + span.hasName("testSdkSqs process") + .hasKind(SpanKind.CONSUMER) + // TODO: This is not good, and can also happen if producer is not + // instrumented + .hasNoParent() + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "process"), + satisfies(MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))))); } getTesting().waitAndAssertTraces(traceAsserts); } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java index 351f4b4c29e6..07d60c6fd52a 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java @@ -29,7 +29,6 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.sdk.trace.data.SpanData; @@ -52,12 +51,6 @@ @SuppressWarnings("deprecation") // using deprecated semconv public abstract class AbstractAws2SqsTracingTest extends AbstractAws2SqsBaseTest { - boolean isSqsAttributeInjectionEnabled() { - // See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor - return ConfigPropertiesUtil.getBoolean( - "otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false); - } - @Override protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { int offset = withParent ? 2 : 0; @@ -77,12 +70,8 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { satisfies( AWS_REQUEST_ID, val -> - val.satisfiesAnyOf( - v -> - assertThat(v) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v).isEqualTo("UNKNOWN"))), + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), equalTo(RPC_SYSTEM, "aws-api"), equalTo(RPC_SERVICE, "Sqs"), equalTo(RPC_METHOD, "CreateQueue"), @@ -106,12 +95,8 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { satisfies( AWS_REQUEST_ID, val -> - val.satisfiesAnyOf( - v -> - assertThat(v) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v).isEqualTo("UNKNOWN"))), + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), equalTo(RPC_SYSTEM, "aws-api"), equalTo(RPC_SERVICE, "Sqs"), equalTo(RPC_METHOD, "SendMessage"), @@ -163,12 +148,8 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { satisfies( AWS_REQUEST_ID, val -> - val.satisfiesAnyOf( - v -> - assertThat(v) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v).isEqualTo("UNKNOWN"))), + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), equalTo(RPC_SYSTEM, "aws-api"), equalTo(RPC_SERVICE, "Sqs"), equalTo(RPC_METHOD, "ReceiveMessage"), @@ -196,9 +177,7 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), equalTo(SERVER_ADDRESS, "localhost"), equalTo(SERVER_PORT, sqsPort), - equalTo( - MESSAGING_SYSTEM, - AWS_SQS), + equalTo(MESSAGING_SYSTEM, AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), equalTo(MESSAGING_OPERATION, "receive"), equalTo(MESSAGING_BATCH_MESSAGE_COUNT, 1))); @@ -332,18 +311,12 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { .hasNoParent() .hasAttributesSatisfyingExactly( equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo( - stringKey("aws.queue.url"), - "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"), + equalTo(stringKey("aws.queue.url"), queueUrl), satisfies( AWS_REQUEST_ID, val -> - val.satisfiesAnyOf( - v -> - assertThat(v.trim()) - .isEqualTo( - "00000000-0000-0000-0000-000000000000"), - v -> assertThat(v.trim()).isEqualTo("UNKNOWN"))), + val.matches( + "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), equalTo(RPC_SYSTEM, "aws-api"), equalTo(RPC_SERVICE, "Sqs"), equalTo(RPC_METHOD, "SendMessageBatch"), From 33a0d15240ad739b6866cbb67130d30fa5991a55 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 14 Dec 2024 17:11:17 -0500 Subject: [PATCH 03/11] refactoring --- .../awssdk/v2_2/AbstractAws2SqsBaseTest.java | 86 ++++++++++++ ...stractAws2SqsSuppressReceiveSpansTest.java | 129 +----------------- .../v2_2/AbstractAws2SqsTracingTest.java | 24 +--- 3 files changed, 93 insertions(+), 146 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java index 4cd293302557..32c389faa054 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java @@ -5,10 +5,30 @@ package io.opentelemetry.instrumentation.awssdk.v2_2; +import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; +import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD; +import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE; +import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS; +import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT; +import static io.opentelemetry.semconv.UrlAttributes.URL_FULL; +import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_REQUEST_ID; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM; +import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS; +import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD; +import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE; +import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM; import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +import io.opentelemetry.sdk.trace.data.SpanData; import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; @@ -183,4 +203,70 @@ void testSimpleSqsProducerConsumerServicesAsync() throws Exception { response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {})); assertSqsTraces(false, false); } + + static SpanDataAssert createQueueSpan(SpanDataAssert span) { + return span.hasName("Sqs.CreateQueue") + .hasKind(SpanKind.CLIENT) + .hasNoParent() + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(stringKey("aws.queue.name"), "testSdkSqs"), + satisfies( + AWS_REQUEST_ID, + val -> val.matches("\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "CreateQueue"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort)); + } + + @SuppressWarnings("deprecation") // using deprecated semconv + static SpanDataAssert processSpan(SpanDataAssert span, SpanData parent) { + return span.hasName("testSdkSqs process") + .hasKind(SpanKind.CONSUMER) + .hasParent(parent) + .hasTotalRecordedLinks(0) + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "ReceiveMessage"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "process"), + satisfies(MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))); + } + + @SuppressWarnings("deprecation") // using deprecated semconv + static SpanDataAssert publishSpan(SpanDataAssert span, String queueUrl) { + return span.hasName("testSdkSqs publish") + .hasKind(SpanKind.PRODUCER) + .hasNoParent() + .hasAttributesSatisfyingExactly( + equalTo(stringKey("aws.agent"), "java-aws-sdk"), + equalTo(stringKey("aws.queue.url"), queueUrl), + satisfies( + AWS_REQUEST_ID, + val -> val.matches("\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), + equalTo(RPC_SYSTEM, "aws-api"), + equalTo(RPC_SERVICE, "Sqs"), + equalTo(RPC_METHOD, "SendMessageBatch"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, sqsPort), + equalTo(MESSAGING_SYSTEM, AWS_SQS), + equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), + equalTo(MESSAGING_OPERATION, "publish")); + } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java index f3b59ba197b0..32dc461fc74a 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java @@ -42,83 +42,15 @@ public abstract class AbstractAws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsBaseTest { @Override - @SuppressWarnings("deprecation") // using deprecated semconv protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { List> traceAsserts = new ArrayList<>( Arrays.asList( + trace -> trace.hasSpansSatisfyingExactly(span -> createQueueSpan(span)), trace -> trace.hasSpansSatisfyingExactly( - span -> - span.hasName("Sqs.CreateQueue") - .hasKind(SpanKind.CLIENT) - .hasNoParent() - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(stringKey("aws.queue.name"), "testSdkSqs"), - satisfies( - AWS_REQUEST_ID, - val -> - val.matches( - "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "CreateQueue"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort))), - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("testSdkSqs publish") - .hasKind(SpanKind.PRODUCER) - .hasNoParent() - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(stringKey("aws.queue.url"), queueUrl), - satisfies( - AWS_REQUEST_ID, - val -> - val.matches( - "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "SendMessage"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "publish"), - satisfies( - MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))), - span -> - span.hasName("testSdkSqs process") - .hasKind(SpanKind.CONSUMER) - .hasParent(trace.getSpan(0)) - .hasTotalRecordedLinks(0) - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "ReceiveMessage"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "process"), - satisfies( - MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class))), + span -> publishSpan(span, queueUrl), + span -> processSpan(span, trace.getSpan(0)), span -> span.hasName("process child") .hasParent(trace.getSpan(1)) @@ -186,62 +118,13 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { List> traceAsserts = new ArrayList<>( Arrays.asList( - trace -> - trace.hasSpansSatisfyingExactly( - span -> span.hasName("Sqs.CreateQueue").hasKind(SpanKind.CLIENT)), + trace -> trace.hasSpansSatisfyingExactly(span -> createQueueSpan(span)), trace -> { List> spanAsserts = - new ArrayList<>( - singletonList( - span -> - span.hasName("testSdkSqs publish") - .hasKind(SpanKind.PRODUCER) - .hasNoParent() - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(stringKey("aws.queue.url"), queueUrl), - satisfies( - AWS_REQUEST_ID, - val -> - val.matches( - "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "SendMessageBatch"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, - v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "publish")))); + new ArrayList<>(singletonList(span -> publishSpan(span, queueUrl))); for (int i = 0; i <= (isXrayInjectionEnabled() ? 2 : 1); i++) { - spanAsserts.add( - span -> - span.hasName("testSdkSqs process") - .hasKind(SpanKind.CONSUMER) - .hasParent(trace.getSpan(0)) - .hasTotalRecordedLinks(0) - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "ReceiveMessage"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "process"), - satisfies( - MESSAGING_MESSAGE_ID, v -> v.isInstanceOf(String.class)))); + spanAsserts.add(span -> processSpan(span, trace.getSpan(0))); } trace.hasSpansSatisfyingExactly(spanAsserts); })); diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java index 07d60c6fd52a..b4dd1898d465 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java @@ -58,29 +58,7 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { getTesting() .waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("Sqs.CreateQueue") - .hasKind(SpanKind.CLIENT) - .hasNoParent() - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(stringKey("aws.queue.name"), "testSdkSqs"), - satisfies( - AWS_REQUEST_ID, - val -> - val.matches( - "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "CreateQueue"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies( - URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort))), + trace -> trace.hasSpansSatisfyingExactly(span -> createQueueSpan(span)), trace -> trace.hasSpansSatisfyingExactly( span -> { From 58b7f0cba594bc31a3cc03bf92ef2a1677f83753 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 14 Dec 2024 17:15:46 -0500 Subject: [PATCH 04/11] refactoring --- .../v2_2/AbstractAws2SqsTracingTest.java | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java index b4dd1898d465..b1fd05cd4694 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java @@ -282,30 +282,7 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { span -> span.hasName("Sqs.CreateQueue").hasKind(SpanKind.CLIENT)), trace -> { publishSpan.set(trace.getSpan(0)); - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("testSdkSqs publish") - .hasKind(SpanKind.PRODUCER) - .hasNoParent() - .hasAttributesSatisfyingExactly( - equalTo(stringKey("aws.agent"), "java-aws-sdk"), - equalTo(stringKey("aws.queue.url"), queueUrl), - satisfies( - AWS_REQUEST_ID, - val -> - val.matches( - "\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), - equalTo(RPC_SYSTEM, "aws-api"), - equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "SendMessageBatch"), - equalTo(HTTP_REQUEST_METHOD, "POST"), - equalTo(HTTP_RESPONSE_STATUS_CODE, 200), - satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), - equalTo(SERVER_ADDRESS, "localhost"), - equalTo(SERVER_PORT, sqsPort), - equalTo(MESSAGING_SYSTEM, AWS_SQS), - equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "publish"))); + trace.hasSpansSatisfyingExactly(span -> publishSpan(span, queueUrl)); }, trace -> { List> spanAsserts = new ArrayList<>(); From 01f17212a32c58f37943097eaa50636655f7e985 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 14 Dec 2024 17:53:12 -0500 Subject: [PATCH 05/11] fix checkstyle --- ...SuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java} | 2 +- ...t.java => Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/{Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java => Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java} (90%) rename instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/{Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java => Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java} (91%) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java similarity index 90% rename from instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java rename to instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java index fdcba28cf539..d9b98bc0c929 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java @@ -9,7 +9,7 @@ * We want to test the combination of W3C + Xray, as that's what you'll get in prod if you enable * W3C. */ -class Aws2SqsSuppressReceiveSpansW3CPropagatorAndXrayPropagatorTest +class Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { @Override diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java similarity index 91% rename from instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java rename to instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java index d370880e73a2..6c0f5c76c1c6 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3CPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.awssdk.v2_2; -class Aws2SqsSuppressReceiveSpansW3CPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { +class Aws2SqsSuppressReceiveSpansW3cPropagatorTest extends Aws2SqsSuppressReceiveSpansTest { @Override protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) { telemetryBuilder From 13ff8a0db49bfc38fe11254ced66d941a6d08b82 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 14 Dec 2024 20:15:37 -0500 Subject: [PATCH 06/11] fix message id assertions --- .../awssdk/v2_2/AbstractAws2SqsBaseTest.java | 12 +++++++++--- .../AbstractAws2SqsSuppressReceiveSpansTest.java | 5 +++-- .../awssdk/v2_2/AbstractAws2SqsTracingTest.java | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java index 32c389faa054..17b105410508 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java @@ -247,7 +247,7 @@ static SpanDataAssert processSpan(SpanDataAssert span, SpanData parent) { } @SuppressWarnings("deprecation") // using deprecated semconv - static SpanDataAssert publishSpan(SpanDataAssert span, String queueUrl) { + static SpanDataAssert publishSpan(SpanDataAssert span, String queueUrl, String rcpMethod) { return span.hasName("testSdkSqs publish") .hasKind(SpanKind.PRODUCER) .hasNoParent() @@ -259,7 +259,7 @@ static SpanDataAssert publishSpan(SpanDataAssert span, String queueUrl) { val -> val.matches("\\s*00000000-0000-0000-0000-000000000000\\s*|UNKNOWN")), equalTo(RPC_SYSTEM, "aws-api"), equalTo(RPC_SERVICE, "Sqs"), - equalTo(RPC_METHOD, "SendMessageBatch"), + equalTo(RPC_METHOD, rcpMethod), equalTo(HTTP_REQUEST_METHOD, "POST"), equalTo(HTTP_RESPONSE_STATUS_CODE, 200), satisfies(URL_FULL, v -> v.startsWith("http://localhost:" + sqsPort)), @@ -267,6 +267,12 @@ static SpanDataAssert publishSpan(SpanDataAssert span, String queueUrl) { equalTo(SERVER_PORT, sqsPort), equalTo(MESSAGING_SYSTEM, AWS_SQS), equalTo(MESSAGING_DESTINATION_NAME, "testSdkSqs"), - equalTo(MESSAGING_OPERATION, "publish")); + equalTo(MESSAGING_OPERATION, "publish"), + satisfies( + MESSAGING_MESSAGE_ID, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isInstanceOf(String.class), + v -> assertThat(v).isNull()))); } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java index 32dc461fc74a..bf5adaa3e49c 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java @@ -49,7 +49,7 @@ protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { trace -> trace.hasSpansSatisfyingExactly(span -> createQueueSpan(span)), trace -> trace.hasSpansSatisfyingExactly( - span -> publishSpan(span, queueUrl), + span -> publishSpan(span, queueUrl, "SendMessage"), span -> processSpan(span, trace.getSpan(0)), span -> span.hasName("process child") @@ -121,7 +121,8 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { trace -> trace.hasSpansSatisfyingExactly(span -> createQueueSpan(span)), trace -> { List> spanAsserts = - new ArrayList<>(singletonList(span -> publishSpan(span, queueUrl))); + new ArrayList<>( + singletonList(span -> publishSpan(span, queueUrl, "SendMessageBatch"))); for (int i = 0; i <= (isXrayInjectionEnabled() ? 2 : 1); i++) { spanAsserts.add(span -> processSpan(span, trace.getSpan(0))); diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java index b1fd05cd4694..b62df08fbd85 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java @@ -282,7 +282,8 @@ void testBatchSqsProducerConsumerServicesSync() throws URISyntaxException { span -> span.hasName("Sqs.CreateQueue").hasKind(SpanKind.CLIENT)), trace -> { publishSpan.set(trace.getSpan(0)); - trace.hasSpansSatisfyingExactly(span -> publishSpan(span, queueUrl)); + trace.hasSpansSatisfyingExactly( + span -> publishSpan(span, queueUrl, "SendMessageBatch")); }, trace -> { List> spanAsserts = new ArrayList<>(); From 4399b8145790b7ef3907a095311eb811432f2478 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 14 Dec 2024 21:01:55 -0500 Subject: [PATCH 07/11] cleanup --- ...SuppressReceiveSpansW3cPropagatorTest.java | 2 +- .../awssdk/v2_2/Aws2SqsW3cPropagatorTest.java | 2 +- .../awssdk/v2_2/AbstractAws2SqsBaseTest.java | 25 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java index 6c0f5c76c1c6..3834378751f6 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java @@ -21,7 +21,7 @@ boolean isSqsAttributeInjectionEnabled() { } @Override - boolean isXrayInjectionEnabled() { + protected boolean isXrayInjectionEnabled() { return false; } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java index 9e8076e5f3a6..28c41de6d49b 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java @@ -22,7 +22,7 @@ boolean isSqsAttributeInjectionEnabled() { } @Override - boolean isXrayInjectionEnabled() { + protected boolean isXrayInjectionEnabled() { return false; } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java index 17b105410508..bd1bb8fa5ee4 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java @@ -55,7 +55,6 @@ import software.amazon.awssdk.services.sqs.model.SendMessageRequest; public abstract class AbstractAws2SqsBaseTest { - protected abstract InstrumentationExtension getTesting(); protected abstract SqsClient configureSqsClient(SqsClient sqsClient); @@ -64,6 +63,8 @@ public abstract class AbstractAws2SqsBaseTest { protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder(); + protected abstract void assertSqsTraces(Boolean withParent, Boolean captureHeaders); + protected static final StaticCredentialsProvider CREDENTIALS_PROVIDER = StaticCredentialsProvider.create( AwsBasicCredentials.create("my-access-key", "my-secret-key")); @@ -71,6 +72,8 @@ public abstract class AbstractAws2SqsBaseTest { protected static int sqsPort; protected static SQSRestServer sqs; + protected final String queueUrl = "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"; + static Map dummyMessageAttributes(int count) { Map map = new HashMap<>(); for (int i = 0; i < count; i++) { @@ -80,12 +83,10 @@ static Map dummyMessageAttributes(int count) { return map; } - protected final String queueUrl = "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"; - - ReceiveMessageRequest receiveMessageRequest = + protected ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).build(); - ReceiveMessageRequest receiveMessageBatchRequest = + protected ReceiveMessageRequest receiveMessageBatchRequest = ReceiveMessageRequest.builder() .queueUrl(queueUrl) .maxNumberOfMessages(3) @@ -93,14 +94,14 @@ static Map dummyMessageAttributes(int count) { .waitTimeSeconds(5) .build(); - CreateQueueRequest createQueueRequest = + protected CreateQueueRequest createQueueRequest = CreateQueueRequest.builder().queueName("testSdkSqs").build(); - SendMessageRequest sendMessageRequest = + protected SendMessageRequest sendMessageRequest = SendMessageRequest.builder().queueUrl(queueUrl).messageBody("{\"type\": \"hello\"}").build(); @SuppressWarnings("unchecked") - SendMessageBatchRequest sendMessageBatchRequest = + protected SendMessageBatchRequest sendMessageBatchRequest = SendMessageBatchRequest.builder() .queueUrl(queueUrl) .entries( @@ -111,7 +112,7 @@ static Map dummyMessageAttributes(int count) { e -> e.messageBody("e3").id("i3").messageAttributes(dummyMessageAttributes(10))) .build(); - boolean isXrayInjectionEnabled() { + protected boolean isXrayInjectionEnabled() { return true; } @@ -122,21 +123,19 @@ protected void configureSdkClient(SqsClientBuilder builder) throws URISyntaxExce builder.region(Region.AP_NORTHEAST_1).credentialsProvider(CREDENTIALS_PROVIDER); } - void configureSdkClient(SqsAsyncClientBuilder builder) throws URISyntaxException { + protected void configureSdkClient(SqsAsyncClientBuilder builder) throws URISyntaxException { builder .overrideConfiguration(createOverrideConfigurationBuilder().build()) .endpointOverride(new URI("http://localhost:" + sqsPort)); builder.region(Region.AP_NORTHEAST_1).credentialsProvider(CREDENTIALS_PROVIDER); } - boolean isSqsAttributeInjectionEnabled() { + protected boolean isSqsAttributeInjectionEnabled() { // See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor return ConfigPropertiesUtil.getBoolean( "otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false); } - protected abstract void assertSqsTraces(Boolean withParent, Boolean captureHeaders); - @BeforeAll static void setUp() { sqs = SQSRestServerBuilder.withPort(0).withInterface("localhost").start(); From 3a2201f6082381d3853dc7c428e07e08aecf5b80 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sun, 15 Dec 2024 06:25:15 -0500 Subject: [PATCH 08/11] fix --- .../awssdk/v2_2/Aws2SqsDefaultPropagatorTest.java | 2 +- .../v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java | 2 +- ...sSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java | 2 +- .../v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java | 2 +- .../awssdk/v2_2/Aws2SqsW3cPropagatorAndXrayPropagatorTest.java | 2 +- .../instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsDefaultPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsDefaultPropagatorTest.java index 9006104b2f7b..ab0d782b85ee 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsDefaultPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsDefaultPropagatorTest.java @@ -20,7 +20,7 @@ class Aws2SqsDefaultPropagatorTest extends Aws2SqsTracingTest { void configure(AwsSdkTelemetryBuilder telemetryBuilder) {} @Override - boolean isSqsAttributeInjectionEnabled() { + protected boolean isSqsAttributeInjectionEnabled() { return false; } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java index 7204ec331758..860766e31e41 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansDefaultPropagatorTest.java @@ -20,7 +20,7 @@ class Aws2SqsSuppressReceiveSpansDefaultPropagatorTest extends Aws2SqsSuppressRe protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) {} @Override - boolean isSqsAttributeInjectionEnabled() { + protected boolean isSqsAttributeInjectionEnabled() { return false; } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java index d9b98bc0c929..5289e31a5496 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest.java @@ -19,7 +19,7 @@ protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) { } @Override - boolean isSqsAttributeInjectionEnabled() { + protected boolean isSqsAttributeInjectionEnabled() { return true; } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java index 3834378751f6..1c479a4ab0e1 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansW3cPropagatorTest.java @@ -16,7 +16,7 @@ protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) { } @Override - boolean isSqsAttributeInjectionEnabled() { + protected boolean isSqsAttributeInjectionEnabled() { return true; } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorAndXrayPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorAndXrayPropagatorTest.java index a0d2da870136..7286442e97b2 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorAndXrayPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorAndXrayPropagatorTest.java @@ -13,7 +13,7 @@ void configure(AwsSdkTelemetryBuilder telemetryBuilder) { } @Override - boolean isSqsAttributeInjectionEnabled() { + protected boolean isSqsAttributeInjectionEnabled() { return true; } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java index 28c41de6d49b..3a8636b58fb5 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsW3cPropagatorTest.java @@ -17,7 +17,7 @@ void configure(AwsSdkTelemetryBuilder telemetryBuilder) { } @Override - boolean isSqsAttributeInjectionEnabled() { + protected boolean isSqsAttributeInjectionEnabled() { return true; } From b35e7744a0fee023410c1ba2b6c3fff47a9be103 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Tue, 17 Dec 2024 19:35:50 -0500 Subject: [PATCH 09/11] use primitive boolean --- .../instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java | 2 +- .../awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java | 2 +- .../instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java index bd1bb8fa5ee4..56f25129822d 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java @@ -63,7 +63,7 @@ public abstract class AbstractAws2SqsBaseTest { protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder(); - protected abstract void assertSqsTraces(Boolean withParent, Boolean captureHeaders); + protected abstract void assertSqsTraces(boolean withParent, boolean captureHeaders); protected static final StaticCredentialsProvider CREDENTIALS_PROVIDER = StaticCredentialsProvider.create( diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java index bf5adaa3e49c..4d0a9be89c3f 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.java @@ -42,7 +42,7 @@ public abstract class AbstractAws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsBaseTest { @Override - protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { + protected void assertSqsTraces(boolean withParent, boolean captureHeaders) { List> traceAsserts = new ArrayList<>( Arrays.asList( diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java index b62df08fbd85..6fa897d46292 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.java @@ -52,7 +52,7 @@ public abstract class AbstractAws2SqsTracingTest extends AbstractAws2SqsBaseTest { @Override - protected void assertSqsTraces(Boolean withParent, Boolean captureHeaders) { + protected void assertSqsTraces(boolean withParent, boolean captureHeaders) { int offset = withParent ? 2 : 0; AtomicReference publishSpan = new AtomicReference<>(); From b6f8661870d535f7ea9aae418521c33d925e6abe Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Wed, 18 Dec 2024 05:52:42 -0500 Subject: [PATCH 10/11] field declarations before methods --- .../v2_2/Aws2SqsSuppressReceiveSpansTest.java | 28 ++++++------- .../awssdk/v2_2/AbstractAws2SqsBaseTest.java | 40 +++++++++---------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java index 54a7906080e1..0312d3673e21 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java @@ -15,18 +15,11 @@ public abstract class Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest { + protected AwsSdkTelemetry telemetry; + @RegisterExtension static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); - @BeforeEach - void setup() { - AwsSdkTelemetryBuilder telemetryBuilder = - AwsSdkTelemetry.builder(getTesting().getOpenTelemetry()) - .setCaptureExperimentalSpanAttributes(true); - configure(telemetryBuilder); - telemetry = telemetryBuilder.build(); - } - @Override protected InstrumentationExtension getTesting() { return testing; @@ -34,7 +27,10 @@ protected InstrumentationExtension getTesting() { protected abstract void configure(AwsSdkTelemetryBuilder telemetryBuilder); - protected AwsSdkTelemetry telemetry; + @Override + protected SqsClient configureSqsClient(SqsClient sqsClient) { + return telemetry.wrap(sqsClient); + } @Override protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { @@ -43,12 +39,16 @@ protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder } @Override - protected SqsClient configureSqsClient(SqsClient sqsClient) { + protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { return telemetry.wrap(sqsClient); } - @Override - protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { - return telemetry.wrap(sqsClient); + @BeforeEach + void setup() { + AwsSdkTelemetryBuilder telemetryBuilder = + AwsSdkTelemetry.builder(getTesting().getOpenTelemetry()) + .setCaptureExperimentalSpanAttributes(true); + configure(telemetryBuilder); + telemetry = telemetryBuilder.build(); } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java index 56f25129822d..902bfdc0d4ec 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java @@ -55,34 +55,13 @@ import software.amazon.awssdk.services.sqs.model.SendMessageRequest; public abstract class AbstractAws2SqsBaseTest { - protected abstract InstrumentationExtension getTesting(); - - protected abstract SqsClient configureSqsClient(SqsClient sqsClient); - - protected abstract SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient); - - protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder(); - - protected abstract void assertSqsTraces(boolean withParent, boolean captureHeaders); - protected static final StaticCredentialsProvider CREDENTIALS_PROVIDER = StaticCredentialsProvider.create( AwsBasicCredentials.create("my-access-key", "my-secret-key")); - protected static int sqsPort; protected static SQSRestServer sqs; - protected final String queueUrl = "http://localhost:" + sqsPort + "/000000000000/testSdkSqs"; - static Map dummyMessageAttributes(int count) { - Map map = new HashMap<>(); - for (int i = 0; i < count; i++) { - map.put( - "a" + i, MessageAttributeValue.builder().stringValue("v" + i).dataType("String").build()); - } - return map; - } - protected ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).build(); @@ -112,6 +91,25 @@ static Map dummyMessageAttributes(int count) { e -> e.messageBody("e3").id("i3").messageAttributes(dummyMessageAttributes(10))) .build(); + protected abstract InstrumentationExtension getTesting(); + + protected abstract SqsClient configureSqsClient(SqsClient sqsClient); + + protected abstract SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient); + + protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder(); + + protected abstract void assertSqsTraces(boolean withParent, boolean captureHeaders); + + static Map dummyMessageAttributes(int count) { + Map map = new HashMap<>(); + for (int i = 0; i < count; i++) { + map.put( + "a" + i, MessageAttributeValue.builder().stringValue("v" + i).dataType("String").build()); + } + return map; + } + protected boolean isXrayInjectionEnabled() { return true; } From ed9128a336ad36ef1d6f3a414d6bccbd08201353 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Wed, 18 Dec 2024 06:35:32 -0500 Subject: [PATCH 11/11] fix overload grouping --- .../awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java index 0312d3673e21..6afa0eb26066 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/test/java/io/opentelemetry/instrumentation/awssdk/v2_2/Aws2SqsSuppressReceiveSpansTest.java @@ -25,23 +25,23 @@ protected InstrumentationExtension getTesting() { return testing; } - protected abstract void configure(AwsSdkTelemetryBuilder telemetryBuilder); - @Override protected SqsClient configureSqsClient(SqsClient sqsClient) { return telemetry.wrap(sqsClient); } + @Override + protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { + return telemetry.wrap(sqsClient); + } + @Override protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() { return ClientOverrideConfiguration.builder() .addExecutionInterceptor(telemetry.newExecutionInterceptor()); } - @Override - protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) { - return telemetry.wrap(sqsClient); - } + protected abstract void configure(AwsSdkTelemetryBuilder telemetryBuilder); @BeforeEach void setup() {