From 09e823a6dfcaa8d4f2252fe721302d141ffe2611 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Fri, 22 Nov 2024 15:15:50 -0500 Subject: [PATCH] addressed comments --- .../awssdk/v1_11/TracingRequestHandler.java | 5 +- .../v1_11/AbstractBaseAwsClientTest.java | 13 +--- .../v1_11/AbstractDynamoDbClientTest.java | 18 ++--- .../v1_11/AbstractKinesisClientTest.java | 11 +-- .../awssdk/v1_11/AbstractS3ClientTest.java | 8 +-- .../awssdk/v1_11/AbstractSnsClientTest.java | 10 +-- .../awssdk/v1_11/AttributeKeyPair.java | 69 ------------------- 7 files changed, 31 insertions(+), 103 deletions(-) delete mode 100644 instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AttributeKeyPair.java diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java index ffbb87d20d93..407593a079d0 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java @@ -33,7 +33,7 @@ final class TracingRequestHandler extends RequestHandler2 { ContextKey.named(TracingRequestHandler.class.getName() + ".RequestSpanSuppressed"); private static final String SEND_MESSAGE_REQUEST = "com.amazonaws.services.sqs.model.SendMessageRequest"; - private static final String DYNAMODBV2 = "com.amazonaws.services.dynamodbv2.model"; + private static final String DYNAMODBV2 = "com.amazonaws.services.dynamodbv2.model."; private final Instrumenter, Response> requestInstrumenter; private final Instrumenter> consumerReceiveInstrumenter; @@ -164,7 +164,8 @@ private Instrumenter, Response> getInstrumenter(Request request String className = request.getOriginalRequest().getClass().getName(); if (className.startsWith(DYNAMODBV2)) { return dynamoDbInstrumenter; - } else if (className.equals(SEND_MESSAGE_REQUEST)) { + } + if (className.equals(SEND_MESSAGE_REQUEST)) { return producerInstrumenter; } return requestInstrumenter; diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractBaseAwsClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractBaseAwsClientTest.java index 3ee1dfb01aef..10ff869d2334 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractBaseAwsClientTest.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractBaseAwsClientTest.java @@ -28,7 +28,6 @@ import com.amazonaws.auth.AnonymousAWSCredentials; import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.handlers.RequestHandler2; -import io.opentelemetry.api.common.AttributeType; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.testing.internal.armeria.testing.junit5.server.mock.MockWebServerExtension; @@ -75,7 +74,7 @@ public void assertRequestWithMockedResponse( String service, String operation, String method, - List> additionalAttributes) + List additionalAttributes) throws Exception { assertThat(response).isNotNull(); @@ -113,15 +112,7 @@ public void assertRequestWithMockedResponse( stringKey("aws.request_id"), v -> v.isInstanceOf(String.class))); } - additionalAttributes.forEach( - (att) -> { - if (att.getType() == AttributeType.STRING) { - attributes.add(equalTo(att.getStringKey(), att.getStringVal())); - } else if (att.getType() == AttributeType.STRING_ARRAY) { - attributes.add( - equalTo(att.getStringArrayKey(), att.getStringArrayVal())); - } - }); + attributes.addAll(additionalAttributes); span.hasName(service + "." + operation) .hasKind(operation.equals("SendMessage") ? PRODUCER : CLIENT) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractDynamoDbClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractDynamoDbClientTest.java index ccd1499be2bf..98ecc951ae52 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractDynamoDbClientTest.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractDynamoDbClientTest.java @@ -5,17 +5,19 @@ package io.opentelemetry.instrumentation.awssdk.v1_11; -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringArrayKeyPair; -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; +import static io.opentelemetry.api.common.AttributeKey.stringArrayKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static java.util.Collections.singletonList; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; +import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.testing.internal.armeria.common.HttpResponse; import io.opentelemetry.testing.internal.armeria.common.HttpStatus; import io.opentelemetry.testing.internal.armeria.common.MediaType; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; @@ -39,13 +41,11 @@ public void sendRequestWithMockedResponse() throws Exception { server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "")); - List tableList = Collections.singletonList("sometable"); - - List> additionalAttributes = + List additionalAttributes = Arrays.asList( - createStringKeyPair("aws.table.name", "sometable"), - createStringKeyPair("db.system", "dynamodb"), - createStringArrayKeyPair("aws.dynamodb.table_names", tableList)); + equalTo(stringKey("aws.table.name"), "sometable"), + equalTo(stringKey("db.system"), "dynamodb"), + equalTo(stringArrayKey("aws.dynamodb.table_names"), singletonList("sometable"))); Object response = client.createTable(new CreateTableRequest("sometable", null)); assertRequestWithMockedResponse( diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractKinesisClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractKinesisClientTest.java index ed7420cdc618..ee6d1b750187 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractKinesisClientTest.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractKinesisClientTest.java @@ -5,15 +5,17 @@ package io.opentelemetry.instrumentation.awssdk.v1_11; -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; +import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static java.util.Collections.singletonList; import com.amazonaws.services.kinesis.AmazonKinesis; import com.amazonaws.services.kinesis.AmazonKinesisClientBuilder; import com.amazonaws.services.kinesis.model.DeleteStreamRequest; +import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.testing.internal.armeria.common.HttpResponse; import io.opentelemetry.testing.internal.armeria.common.HttpStatus; import io.opentelemetry.testing.internal.armeria.common.MediaType; -import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; @@ -44,8 +46,9 @@ public void testSendRequestWithMockedResponse( server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "")); - List> additionalAttributes = - Arrays.asList(createStringKeyPair("aws.stream.name", "somestream")); + List additionalAttributes = + singletonList(equalTo(stringKey("aws.stream.name"), "somestream")); + Object response = call.apply(client); assertRequestWithMockedResponse( response, client, "Kinesis", operation, "POST", additionalAttributes); diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractS3ClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractS3ClientTest.java index d95d3f59a204..574165992ff4 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractS3ClientTest.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractS3ClientTest.java @@ -7,7 +7,6 @@ import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.trace.SpanKind.CLIENT; -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; import static io.opentelemetry.instrumentation.test.utils.PortUtils.UNUSABLE_PORT; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE; @@ -30,6 +29,7 @@ import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import io.opentelemetry.api.trace.Span; +import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.testing.internal.armeria.common.HttpResponse; import io.opentelemetry.testing.internal.armeria.common.HttpStatus; @@ -61,7 +61,7 @@ public void testSendRequestWithMockedResponse( String operation, String method, Function call, - List> additionalAttributes) + List additionalAttributes) throws Exception { AmazonS3 client = @@ -83,12 +83,12 @@ private static Stream provideArguments() { "CreateBucket", "PUT", (Function) c -> c.createBucket("testbucket"), - singletonList(createStringKeyPair("aws.bucket.name", "testbucket"))), + singletonList(equalTo(stringKey("aws.bucket.name"), "testbucket"))), Arguments.of( "GetObject", "GET", (Function) c -> c.getObject("someBucket", "someKey"), - singletonList(createStringKeyPair("aws.bucket.name", "someBucket")))); + singletonList(equalTo(stringKey("aws.bucket.name"), "someBucket")))); } @Test diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSnsClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSnsClientTest.java index 229a10614d62..2c80e3165542 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSnsClientTest.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSnsClientTest.java @@ -5,16 +5,18 @@ package io.opentelemetry.instrumentation.awssdk.v1_11; -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; +import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME; +import static java.util.Collections.singletonList; import com.amazonaws.services.sns.AmazonSNS; import com.amazonaws.services.sns.AmazonSNSClientBuilder; import com.amazonaws.services.sns.model.PublishRequest; +import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.testing.internal.armeria.common.HttpResponse; import io.opentelemetry.testing.internal.armeria.common.HttpStatus; import io.opentelemetry.testing.internal.armeria.common.MediaType; -import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; @@ -53,8 +55,8 @@ public void testSendRequestWithMockedResponse(Function call) server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body)); - List> additionalAttributes = - Arrays.asList(createStringKeyPair(MESSAGING_DESTINATION_NAME.toString(), "somearn")); + List additionalAttributes = + singletonList(equalTo(stringKey(MESSAGING_DESTINATION_NAME.toString()), "somearn")); Object response = call.apply(client); assertRequestWithMockedResponse( diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AttributeKeyPair.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AttributeKeyPair.java deleted file mode 100644 index f4fec0e4aabe..000000000000 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AttributeKeyPair.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.awssdk.v1_11; - -import groovyjarjarantlr4.v4.runtime.misc.Nullable; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.AttributeType; -import java.util.List; - -public class AttributeKeyPair { - - private final AttributeKey key; - private final T value; - - AttributeKeyPair(AttributeKey key, T value) { - this.key = key; - this.value = value; - } - - public static AttributeKeyPair createStringKeyPair(String keyString, String val) { - return new AttributeKeyPair<>(AttributeKey.stringKey(keyString), val); - } - - public static AttributeKeyPair> createStringArrayKeyPair( - String keyString, List val) { - return new AttributeKeyPair<>(AttributeKey.stringArrayKey(keyString), val); - } - - public AttributeType getType() { - return key.getType(); - } - - @SuppressWarnings("unchecked") - public AttributeKey getStringKey() { - if (key.getType() != AttributeType.STRING) { - return null; - } - return (AttributeKey) key; - } - - @SuppressWarnings("unchecked") - @Nullable - public AttributeKey> getStringArrayKey() { - if (key.getType() != AttributeType.STRING_ARRAY) { - return null; - } - return (AttributeKey>) key; - } - - @SuppressWarnings("unchecked") - public String getStringVal() { - if (key.getType() != AttributeType.STRING) { - return null; - } - return (String) value; - } - - @SuppressWarnings("unchecked") - @Nullable - public List getStringArrayVal() { - if (key.getType() != AttributeType.STRING_ARRAY) { - return null; - } - return (List) value; - } -}