Skip to content

Commit

Permalink
Static import semconv constants in tests (#12920)
Browse files Browse the repository at this point in the history
Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
  • Loading branch information
trask and laurit authored Dec 20, 2024
1 parent ae3c778 commit cf0f530
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand All @@ -37,7 +38,6 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.test.utils.PortUtils;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import org.elasticmq.rest.sqs.SQSRestServer;
import org.elasticmq.rest.sqs.SQSRestServerBuilder;
Expand Down Expand Up @@ -107,9 +107,7 @@ void testSimpleSqsProducerConsumerServices() {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.endpoint"), "http://localhost:" + sqsPort),
equalTo(stringKey("aws.queue.name"), "testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "CreateQueue"),
Expand All @@ -131,9 +129,7 @@ void testSimpleSqsProducerConsumerServices() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "SendMessage"),
Expand Down Expand Up @@ -161,9 +157,7 @@ void testSimpleSqsProducerConsumerServices() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand Down Expand Up @@ -219,9 +213,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.endpoint"), "http://localhost:" + sqsPort),
equalTo(stringKey("aws.queue.name"), "testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "CreateQueue"),
Expand All @@ -243,9 +235,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "SendMessage"),
Expand Down Expand Up @@ -273,9 +263,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand Down Expand Up @@ -314,9 +302,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -44,7 +45,6 @@
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 java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -141,9 +141,7 @@ void testSimpleSqsProducerConsumerServicesCaptureHeaders(boolean testCaptureHead
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.endpoint"), "http://localhost:" + sqsPort),
equalTo(stringKey("aws.queue.name"), "testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "CreateQueue"),
Expand All @@ -164,9 +162,7 @@ void testSimpleSqsProducerConsumerServicesCaptureHeaders(boolean testCaptureHead
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "SendMessage"),
Expand Down Expand Up @@ -208,9 +204,7 @@ void testSimpleSqsProducerConsumerServicesCaptureHeaders(boolean testCaptureHead
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand Down Expand Up @@ -249,9 +243,7 @@ void testSimpleSqsProducerConsumerServicesCaptureHeaders(boolean testCaptureHead
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand Down Expand Up @@ -319,9 +311,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.endpoint"), "http://localhost:" + sqsPort),
equalTo(stringKey("aws.queue.name"), "testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "CreateQueue"),
Expand All @@ -343,9 +333,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "SendMessage"),
Expand Down Expand Up @@ -388,8 +376,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
+ sqsPort
+ "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand All @@ -413,8 +400,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
+ sqsPort
+ "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand Down Expand Up @@ -448,8 +434,7 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
+ sqsPort
+ "/000000000000/testSdkSqs"),
satisfies(
AwsIncubatingAttributes.AWS_REQUEST_ID,
val -> val.isInstanceOf(String.class)),
AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "AmazonSQS"),
equalTo(RPC_METHOD, "ReceiveMessage"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.incubating.AwsIncubatingAttributes.AWS_REQUEST_ID;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
Expand All @@ -22,7 +23,6 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.semconv.incubating.AwsIncubatingAttributes;
import io.opentelemetry.testing.internal.armeria.common.HttpResponse;
import io.opentelemetry.testing.internal.armeria.common.HttpStatus;
import io.opentelemetry.testing.internal.armeria.common.MediaType;
Expand Down Expand Up @@ -182,7 +182,7 @@ public void testSendDynamoDbRequestWithRetries() {
equalTo(RPC_SERVICE, service),
equalTo(RPC_METHOD, operation),
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(AwsIncubatingAttributes.AWS_REQUEST_ID, requestId),
equalTo(AWS_REQUEST_ID, requestId),
equalTo(stringKey("aws.table.name"), "sometable"),
equalTo(DB_SYSTEM, "dynamodb"),
equalTo(maybeStable(DB_OPERATION), operation));
Expand Down
Loading

0 comments on commit cf0f530

Please sign in to comment.