From fceec97f7c2c1f6948179db00c652fe3039d743d Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Wed, 20 Nov 2024 02:11:17 -0500 Subject: [PATCH 01/11] Added dynamodb instrumenter for aws v1_11 sdk --- .../v1_11/AwsSdkInstrumenterFactory.java | 13 +++++++ .../awssdk/v1_11/AwsSdkTelemetry.java | 5 ++- .../v1_11/DynamoAttributesExtractor.java | 37 +++++++++++++++++++ .../awssdk/v1_11/TracingRequestHandler.java | 21 ++++++++--- 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java index 4f196a39ba7d..5cbd8353b093 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java @@ -103,6 +103,7 @@ private AttributesExtractor messagingAttr .build(); } + Instrumenter> consumerReceiveInstrumenter() { MessageOperation operation = MessageOperation.RECEIVE; SqsReceiveRequestAttributesGetter getter = SqsReceiveRequestAttributesGetter.INSTANCE; @@ -186,6 +187,18 @@ Instrumenter, Response> producerInstrumenter() { true); } + Instrumenter, Response> dynamoInstrumenter() { + DynamoAttributesExtractor dynamoAttributesExtractor = new DynamoAttributesExtractor(); + + return createInstrumenter( + openTelemetry, + spanName, + SpanKindExtractor.alwaysClient(), + attributesExtractors(), + singletonList(dynamoAttributesExtractor), + true); + } + private static Instrumenter createInstrumenter( OpenTelemetry openTelemetry, SpanNameExtractor spanNameExtractor, diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java index a5b7df063be3..02a883d47659 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java @@ -49,6 +49,7 @@ public static AwsSdkTelemetryBuilder builder(OpenTelemetry openTelemetry) { private final Instrumenter> consumerReceiveInstrumenter; private final Instrumenter> consumerProcessInstrumenter; private final Instrumenter, Response> producerInstrumenter; + private final Instrumenter, Response> dynamoInstrumenter; AwsSdkTelemetry( OpenTelemetry openTelemetry, @@ -65,6 +66,7 @@ public static AwsSdkTelemetryBuilder builder(OpenTelemetry openTelemetry) { consumerReceiveInstrumenter = instrumenterFactory.consumerReceiveInstrumenter(); consumerProcessInstrumenter = instrumenterFactory.consumerProcessInstrumenter(); producerInstrumenter = instrumenterFactory.producerInstrumenter(); + dynamoInstrumenter = instrumenterFactory.dynamoInstrumenter(); } /** @@ -76,6 +78,7 @@ public RequestHandler2 newRequestHandler() { requestInstrumenter, consumerReceiveInstrumenter, consumerProcessInstrumenter, - producerInstrumenter); + producerInstrumenter, + dynamoInstrumenter); } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java new file mode 100644 index 000000000000..51e80493b6ac --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java @@ -0,0 +1,37 @@ +package io.opentelemetry.instrumentation.awssdk.v1_11; + +import com.amazonaws.Request; +import com.amazonaws.Response; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil; +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + +public class DynamoAttributesExtractor implements AttributesExtractor, Response> { + + private static final AttributeKey DB_SYSTEM = + AttributeKey.stringKey("db.system"); + private static final AttributeKey> AWS_TABLE_NAMES = + AttributeKey.stringArrayKey("aws.dynamodb.table_names"); + + private static final String DYNAMODB = "dynamodb"; + + @Override + public void onStart(AttributesBuilder attributes, Context parentContext, Request request) { + AttributesExtractorUtil.internalSet(attributes,DB_SYSTEM,DYNAMODB); + String tableName = RequestAccess.getTableName(request.getOriginalRequest()); + AttributesExtractorUtil.internalSet(attributes,AWS_TABLE_NAMES, Collections.singletonList(tableName)); + } + + @Override + public void onEnd( + AttributesBuilder attributes, + Context context, + Request request, + @Nullable Response response, + @Nullable Throwable error) {} +} 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 1cf74e6147c5..cd47d476d6f7 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 @@ -31,21 +31,26 @@ final class TracingRequestHandler extends RequestHandler2 { ContextKey.named(TracingRequestHandler.class.getName() + ".Timer"); private static final ContextKey REQUEST_SPAN_SUPPRESSED_KEY = 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 final Instrumenter, Response> requestInstrumenter; private final Instrumenter> consumerReceiveInstrumenter; private final Instrumenter> consumerProcessInstrumenter; private final Instrumenter, Response> producerInstrumenter; + private final Instrumenter, Response> dynamoInstrumenter; TracingRequestHandler( Instrumenter, Response> requestInstrumenter, Instrumenter> consumerReceiveInstrumenter, Instrumenter> consumerProcessInstrumenter, - Instrumenter, Response> producerInstrumenter) { + Instrumenter, Response> producerInstrumenter, + Instrumenter, Response> dynamoInstrumenter) { this.requestInstrumenter = requestInstrumenter; this.consumerReceiveInstrumenter = consumerReceiveInstrumenter; this.consumerProcessInstrumenter = consumerProcessInstrumenter; this.producerInstrumenter = producerInstrumenter; + this.dynamoInstrumenter = dynamoInstrumenter; } @Override @@ -53,6 +58,7 @@ public void beforeRequest(Request request) { // GeneratePresignedUrlRequest doesn't result in actual request, beforeRequest is the only // method called for it. Span created here would never be ended and scope would be leaked when // running with java agent. + System.out.println(request.getOriginalRequest().getClass().getName()); if ("com.amazonaws.services.s3.model.GeneratePresignedUrlRequest" .equals(request.getOriginalRequest().getClass().getName())) { return; @@ -151,14 +157,17 @@ private void finish(Request request, Response response, @Nullable Throwabl } return; } - instrumenter.end(context, request, response, error); } private Instrumenter, Response> getInstrumenter(Request request) { - boolean isSqsProducer = - "com.amazonaws.services.sqs.model.SendMessageRequest" - .equals(request.getOriginalRequest().getClass().getName()); - return isSqsProducer ? producerInstrumenter : requestInstrumenter; + String className = request.getOriginalRequest().getClass().getName(); + if (className.startsWith(DYNAMODBV2)) { + return dynamoInstrumenter; + } + else if (className.equals(SEND_MESSAGE_REQUEST)) { + return producerInstrumenter; + } + return requestInstrumenter; } } From 647d4337402ab1c1e60e1ccae4f7ad9db975062d Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Wed, 20 Nov 2024 02:16:39 -0500 Subject: [PATCH 02/11] format nit --- .../awssdk/v1_11/AwsSdkInstrumenterFactory.java | 1 - .../instrumentation/awssdk/v1_11/TracingRequestHandler.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java index 5cbd8353b093..bf98024eca94 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java @@ -103,7 +103,6 @@ private AttributesExtractor messagingAttr .build(); } - Instrumenter> consumerReceiveInstrumenter() { MessageOperation operation = MessageOperation.RECEIVE; SqsReceiveRequestAttributesGetter getter = SqsReceiveRequestAttributesGetter.INSTANCE; 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 cd47d476d6f7..6da7a10251c0 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 @@ -164,8 +164,7 @@ private Instrumenter, Response> getInstrumenter(Request request String className = request.getOriginalRequest().getClass().getName(); if (className.startsWith(DYNAMODBV2)) { return dynamoInstrumenter; - } - else if (className.equals(SEND_MESSAGE_REQUEST)) { + } else if (className.equals(SEND_MESSAGE_REQUEST)) { return producerInstrumenter; } return requestInstrumenter; From fd2f6941485a2b329fd2dd79969f57852288bed5 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Wed, 20 Nov 2024 09:53:04 -0500 Subject: [PATCH 03/11] spotless run --- .../awssdk/v1_11/DynamoAttributesExtractor.java | 17 +++++++++++------ .../awssdk/v1_11/TracingRequestHandler.java | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java index 51e80493b6ac..fc3dd53e6a6c 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.awssdk.v1_11; import com.amazonaws.Request; @@ -7,14 +12,13 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil; -import javax.annotation.Nullable; import java.util.Collections; import java.util.List; +import javax.annotation.Nullable; public class DynamoAttributesExtractor implements AttributesExtractor, Response> { - private static final AttributeKey DB_SYSTEM = - AttributeKey.stringKey("db.system"); + private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); private static final AttributeKey> AWS_TABLE_NAMES = AttributeKey.stringArrayKey("aws.dynamodb.table_names"); @@ -22,10 +26,11 @@ public class DynamoAttributesExtractor implements AttributesExtractor @Override public void onStart(AttributesBuilder attributes, Context parentContext, Request request) { - AttributesExtractorUtil.internalSet(attributes,DB_SYSTEM,DYNAMODB); + AttributesExtractorUtil.internalSet(attributes, DB_SYSTEM, DYNAMODB); String tableName = RequestAccess.getTableName(request.getOriginalRequest()); - AttributesExtractorUtil.internalSet(attributes,AWS_TABLE_NAMES, Collections.singletonList(tableName)); - } + AttributesExtractorUtil.internalSet( + attributes, AWS_TABLE_NAMES, Collections.singletonList(tableName)); + } @Override public void onEnd( 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 6da7a10251c0..ad769a273ea4 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 @@ -31,7 +31,8 @@ final class TracingRequestHandler extends RequestHandler2 { ContextKey.named(TracingRequestHandler.class.getName() + ".Timer"); private static final ContextKey REQUEST_SPAN_SUPPRESSED_KEY = ContextKey.named(TracingRequestHandler.class.getName() + ".RequestSpanSuppressed"); - private static final String SEND_MESSAGE_REQUEST = "com.amazonaws.services.sqs.model.SendMessageRequest"; + private static final String SEND_MESSAGE_REQUEST = + "com.amazonaws.services.sqs.model.SendMessageRequest"; private static final String DYNAMODBV2 = "com.amazonaws.services.dynamodbv2.model"; private final Instrumenter, Response> requestInstrumenter; @@ -58,7 +59,6 @@ public void beforeRequest(Request request) { // GeneratePresignedUrlRequest doesn't result in actual request, beforeRequest is the only // method called for it. Span created here would never be ended and scope would be leaked when // running with java agent. - System.out.println(request.getOriginalRequest().getClass().getName()); if ("com.amazonaws.services.s3.model.GeneratePresignedUrlRequest" .equals(request.getOriginalRequest().getClass().getName())) { return; From 3c0acace96e83e2e6e5f9f1a32f248b814be704a Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 21 Nov 2024 03:46:48 -0500 Subject: [PATCH 04/11] Updated v1_11 tests to account for dynamodb --- .../v1_11/AbstractBaseAwsClientTest.java | 12 +++- .../v1_11/AbstractDynamoDbClientTest.java | 17 ++++- .../awssdk/v1_11/AbstractEc2ClientTest.java | 2 +- .../v1_11/AbstractKinesisClientTest.java | 11 +++- .../awssdk/v1_11/AbstractRdsClientTest.java | 2 +- .../awssdk/v1_11/AbstractS3ClientTest.java | 10 +-- .../awssdk/v1_11/AbstractSnsClientTest.java | 9 +-- .../awssdk/v1_11/AttributeKeyPair.java | 63 +++++++++++++++++++ 8 files changed, 107 insertions(+), 19 deletions(-) create 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/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 c76bffa37562..8860d2d87c0c 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,13 +28,13 @@ 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; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -75,7 +75,7 @@ public void assertRequestWithMockedResponse( String service, String operation, String method, - Map additionalAttributes) + List> additionalAttributes) throws Exception { assertThat(response).isNotNull(); @@ -114,7 +114,13 @@ public void assertRequestWithMockedResponse( } additionalAttributes.forEach( - (k, v) -> attributes.add(equalTo(stringKey(k), v))); + (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())); + } + }); 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 ba62420ae920..5b334340d8e3 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 @@ -8,11 +8,16 @@ import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; -import com.google.common.collect.ImmutableMap; 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 org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringArrayKeyPair; +import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; public abstract class AbstractDynamoDbClientTest extends AbstractBaseAwsClientTest { @@ -34,6 +39,14 @@ public void sendRequestWithMockedResponse() throws Exception { server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "")); + List tableList = Collections.singletonList("sometable"); + + List> additionalAttributes = Arrays.asList( + createStringKeyPair("aws.table.name", "sometable"), + createStringKeyPair("db.system", "dynamodb"), + createStringArrayKeyPair("aws.dynamodb.table_names", tableList) + ); + Object response = client.createTable(new CreateTableRequest("sometable", null)); assertRequestWithMockedResponse( response, @@ -41,6 +54,6 @@ public void sendRequestWithMockedResponse() throws Exception { "DynamoDBv2", "CreateTable", "POST", - ImmutableMap.of("aws.table.name", "sometable")); + additionalAttributes); } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractEc2ClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractEc2ClientTest.java index 7ba705fa20ec..2f980d096ad5 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractEc2ClientTest.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractEc2ClientTest.java @@ -41,6 +41,6 @@ public void sendRequestWithMockedResponse() throws Exception { Object response = client.allocateAddress(); assertRequestWithMockedResponse( - response, client, "EC2", "AllocateAddress", "POST", Collections.emptyMap()); + response, client, "EC2", "AllocateAddress", "POST", Collections.emptyList()); } } 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 372780343fc1..f56f51fdeb8c 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 @@ -8,17 +8,20 @@ import com.amazonaws.services.kinesis.AmazonKinesis; import com.amazonaws.services.kinesis.AmazonKinesisClientBuilder; import com.amazonaws.services.kinesis.model.DeleteStreamRequest; -import com.google.common.collect.ImmutableMap; + 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.Map; +import java.util.Arrays; +import java.util.List; import java.util.function.Function; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; + public abstract class AbstractKinesisClientTest extends AbstractBaseAwsClientTest { public abstract AmazonKinesisClientBuilder configureClient(AmazonKinesisClientBuilder client); @@ -42,7 +45,9 @@ public void testSendRequestWithMockedResponse( server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "")); - Map additionalAttributes = ImmutableMap.of("aws.stream.name", "somestream"); + List> additionalAttributes = Arrays.asList( + createStringKeyPair("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/AbstractRdsClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractRdsClientTest.java index 040812e57024..ffae0443ce29 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractRdsClientTest.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractRdsClientTest.java @@ -42,6 +42,6 @@ public void sendRequestWithMockedResponse() throws Exception { Object response = client.deleteOptionGroup(new DeleteOptionGroupRequest()); assertRequestWithMockedResponse( - response, client, "RDS", "DeleteOptionGroup", "POST", Collections.emptyMap()); + response, client, "RDS", "DeleteOptionGroup", "POST", Collections.emptyList()); } } 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 37333d093464..7d901158ff1b 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,6 +7,7 @@ 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; @@ -27,14 +28,13 @@ import com.amazonaws.retry.PredefinedRetryPolicies; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import com.google.common.collect.ImmutableMap; import io.opentelemetry.api.trace.Span; import io.opentelemetry.sdk.trace.data.StatusData; 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.time.Duration; -import java.util.Map; +import java.util.List; import java.util.function.Function; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -60,7 +60,7 @@ public void testSendRequestWithMockedResponse( String operation, String method, Function call, - Map additionalAttributes) + List> additionalAttributes) throws Exception { AmazonS3 client = @@ -82,12 +82,12 @@ private static Stream provideArguments() { "CreateBucket", "PUT", (Function) c -> c.createBucket("testbucket"), - ImmutableMap.of("aws.bucket.name", "testbucket")), + createStringKeyPair("aws.bucket.name", "testbucket")), Arguments.of( "GetObject", "GET", (Function) c -> c.getObject("someBucket", "someKey"), - ImmutableMap.of("aws.bucket.name", "someBucket"))); + createStringKeyPair("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 4a728f645c55..d4b89c0313d5 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,17 @@ package io.opentelemetry.instrumentation.awssdk.v1_11; +import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME; import com.amazonaws.services.sns.AmazonSNS; import com.amazonaws.services.sns.AmazonSNSClientBuilder; import com.amazonaws.services.sns.model.PublishRequest; -import com.google.common.collect.ImmutableMap; 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.Map; +import java.util.Arrays; +import java.util.List; import java.util.function.Function; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; @@ -52,8 +53,8 @@ public void testSendRequestWithMockedResponse(Function call) server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body)); - Map additionalAttributes = - ImmutableMap.of(MESSAGING_DESTINATION_NAME.toString(), "somearn"); + List> additionalAttributes = Arrays.asList( + createStringKeyPair(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 new file mode 100644 index 000000000000..77865185e9a1 --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AttributeKeyPair.java @@ -0,0 +1,63 @@ +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; + } +} From 70daf4ebe6a7b4701e2c0b8209f416c956abc255 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 21 Nov 2024 10:33:12 -0500 Subject: [PATCH 05/11] spotless run --- .../v1_11/AbstractBaseAwsClientTest.java | 3 ++- .../v1_11/AbstractDynamoDbClientTest.java | 25 ++++++++----------- .../v1_11/AbstractKinesisClientTest.java | 10 +++----- .../awssdk/v1_11/AbstractSnsClientTest.java | 4 +-- .../awssdk/v1_11/AttributeKeyPair.java | 20 +++++++++------ 5 files changed, 31 insertions(+), 31 deletions(-) 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 8860d2d87c0c..3ee1dfb01aef 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 @@ -118,7 +118,8 @@ public void assertRequestWithMockedResponse( 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.add( + equalTo(att.getStringArrayKey(), att.getStringArrayVal())); } }); 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 5b334340d8e3..ccd1499be2bf 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,19 +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 com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; 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 org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; - -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringArrayKeyPair; -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; +import org.junit.jupiter.api.Test; public abstract class AbstractDynamoDbClientTest extends AbstractBaseAwsClientTest { @@ -41,19 +41,14 @@ public void sendRequestWithMockedResponse() throws Exception { List tableList = Collections.singletonList("sometable"); - List> additionalAttributes = Arrays.asList( - createStringKeyPair("aws.table.name", "sometable"), - createStringKeyPair("db.system", "dynamodb"), - createStringArrayKeyPair("aws.dynamodb.table_names", tableList) - ); + List> additionalAttributes = + Arrays.asList( + createStringKeyPair("aws.table.name", "sometable"), + createStringKeyPair("db.system", "dynamodb"), + createStringArrayKeyPair("aws.dynamodb.table_names", tableList)); Object response = client.createTable(new CreateTableRequest("sometable", null)); assertRequestWithMockedResponse( - response, - client, - "DynamoDBv2", - "CreateTable", - "POST", - additionalAttributes); + response, client, "DynamoDBv2", "CreateTable", "POST", additionalAttributes); } } 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 f56f51fdeb8c..ed7420cdc618 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,10 +5,11 @@ package io.opentelemetry.instrumentation.awssdk.v1_11; +import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; + import com.amazonaws.services.kinesis.AmazonKinesis; import com.amazonaws.services.kinesis.AmazonKinesisClientBuilder; import com.amazonaws.services.kinesis.model.DeleteStreamRequest; - import io.opentelemetry.testing.internal.armeria.common.HttpResponse; import io.opentelemetry.testing.internal.armeria.common.HttpStatus; import io.opentelemetry.testing.internal.armeria.common.MediaType; @@ -20,8 +21,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import static io.opentelemetry.instrumentation.awssdk.v1_11.AttributeKeyPair.createStringKeyPair; - public abstract class AbstractKinesisClientTest extends AbstractBaseAwsClientTest { public abstract AmazonKinesisClientBuilder configureClient(AmazonKinesisClientBuilder client); @@ -45,9 +44,8 @@ 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 = + Arrays.asList(createStringKeyPair("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/AbstractSnsClientTest.java b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSnsClientTest.java index d4b89c0313d5..229a10614d62 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 @@ -53,8 +53,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 = + Arrays.asList(createStringKeyPair(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 index 77865185e9a1..f4fec0e4aabe 100644 --- 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 @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.awssdk.v1_11; import groovyjarjarantlr4.v4.runtime.misc.Nullable; @@ -19,7 +24,8 @@ public static AttributeKeyPair createStringKeyPair(String keyString, Str return new AttributeKeyPair<>(AttributeKey.stringKey(keyString), val); } - public static AttributeKeyPair> createStringArrayKeyPair(String keyString, List val) { + public static AttributeKeyPair> createStringArrayKeyPair( + String keyString, List val) { return new AttributeKeyPair<>(AttributeKey.stringArrayKey(keyString), val); } @@ -29,7 +35,7 @@ public AttributeType getType() { @SuppressWarnings("unchecked") public AttributeKey getStringKey() { - if (key.getType() != AttributeType.STRING){ + if (key.getType() != AttributeType.STRING) { return null; } return (AttributeKey) key; @@ -45,8 +51,8 @@ public AttributeKey> getStringArrayKey() { } @SuppressWarnings("unchecked") - public String getStringVal(){ - if (key.getType() != AttributeType.STRING){ + public String getStringVal() { + if (key.getType() != AttributeType.STRING) { return null; } return (String) value; @@ -54,10 +60,10 @@ public String getStringVal(){ @SuppressWarnings("unchecked") @Nullable - public List getStringArrayVal(){ - if (key.getType() != AttributeType.STRING_ARRAY){ + public List getStringArrayVal() { + if (key.getType() != AttributeType.STRING_ARRAY) { return null; } - return (List)value; + return (List) value; } } From 61c014cfc00118d9d91854775dd990ea2431fbbb Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 21 Nov 2024 11:43:56 -0500 Subject: [PATCH 06/11] update S3ClientTest --- .../instrumentation/awssdk/v1_11/AbstractS3ClientTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 7d901158ff1b..182f7def0d42 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 @@ -34,6 +34,7 @@ import io.opentelemetry.testing.internal.armeria.common.HttpStatus; import io.opentelemetry.testing.internal.armeria.common.MediaType; import java.time.Duration; +import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; @@ -82,12 +83,12 @@ private static Stream provideArguments() { "CreateBucket", "PUT", (Function) c -> c.createBucket("testbucket"), - createStringKeyPair("aws.bucket.name", "testbucket")), + Collections.singletonList(createStringKeyPair("aws.bucket.name", "testbucket"))), Arguments.of( "GetObject", "GET", (Function) c -> c.getObject("someBucket", "someKey"), - createStringKeyPair("aws.bucket.name", "somebucket"))); + Collections.singletonList(createStringKeyPair("aws.bucket.name", "someBucket")))); } @Test From 1b0a198fee8161f1977682cca07b900cb07833d0 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Fri, 22 Nov 2024 10:31:11 -0500 Subject: [PATCH 07/11] naming nits --- .../awssdk/v1_11/AwsSdkInstrumenterFactory.java | 6 +++--- .../instrumentation/awssdk/v1_11/AwsSdkTelemetry.java | 6 +++--- ...tesExtractor.java => DynamoDbAttributesExtractor.java} | 2 +- .../awssdk/v1_11/TracingRequestHandler.java | 8 ++++---- .../awssdk/v1_11/AbstractS3ClientTest.java | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) rename instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/{DynamoAttributesExtractor.java => DynamoDbAttributesExtractor.java} (93%) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java index bf98024eca94..e2ca18d98715 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java @@ -186,15 +186,15 @@ Instrumenter, Response> producerInstrumenter() { true); } - Instrumenter, Response> dynamoInstrumenter() { - DynamoAttributesExtractor dynamoAttributesExtractor = new DynamoAttributesExtractor(); + Instrumenter, Response> dynamoDbInstrumenter() { + DynamoDbAttributesExtractor dynamoDbAttributesExtractor = new DynamoDbAttributesExtractor(); return createInstrumenter( openTelemetry, spanName, SpanKindExtractor.alwaysClient(), attributesExtractors(), - singletonList(dynamoAttributesExtractor), + singletonList(dynamoDbAttributesExtractor), true); } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java index 02a883d47659..157872a016e5 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java @@ -49,7 +49,7 @@ public static AwsSdkTelemetryBuilder builder(OpenTelemetry openTelemetry) { private final Instrumenter> consumerReceiveInstrumenter; private final Instrumenter> consumerProcessInstrumenter; private final Instrumenter, Response> producerInstrumenter; - private final Instrumenter, Response> dynamoInstrumenter; + private final Instrumenter, Response> dynamoDbInstrumenter; AwsSdkTelemetry( OpenTelemetry openTelemetry, @@ -66,7 +66,7 @@ public static AwsSdkTelemetryBuilder builder(OpenTelemetry openTelemetry) { consumerReceiveInstrumenter = instrumenterFactory.consumerReceiveInstrumenter(); consumerProcessInstrumenter = instrumenterFactory.consumerProcessInstrumenter(); producerInstrumenter = instrumenterFactory.producerInstrumenter(); - dynamoInstrumenter = instrumenterFactory.dynamoInstrumenter(); + dynamoDbInstrumenter = instrumenterFactory.dynamoDbInstrumenter(); } /** @@ -79,6 +79,6 @@ public RequestHandler2 newRequestHandler() { consumerReceiveInstrumenter, consumerProcessInstrumenter, producerInstrumenter, - dynamoInstrumenter); + dynamoDbInstrumenter); } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java similarity index 93% rename from instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java rename to instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java index fc3dd53e6a6c..22c0d88937b5 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java @@ -16,7 +16,7 @@ import java.util.List; import javax.annotation.Nullable; -public class DynamoAttributesExtractor implements AttributesExtractor, Response> { +public class DynamoDbAttributesExtractor implements AttributesExtractor, Response> { private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); private static final AttributeKey> AWS_TABLE_NAMES = 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 ad769a273ea4..ffbb87d20d93 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 @@ -39,19 +39,19 @@ final class TracingRequestHandler extends RequestHandler2 { private final Instrumenter> consumerReceiveInstrumenter; private final Instrumenter> consumerProcessInstrumenter; private final Instrumenter, Response> producerInstrumenter; - private final Instrumenter, Response> dynamoInstrumenter; + private final Instrumenter, Response> dynamoDbInstrumenter; TracingRequestHandler( Instrumenter, Response> requestInstrumenter, Instrumenter> consumerReceiveInstrumenter, Instrumenter> consumerProcessInstrumenter, Instrumenter, Response> producerInstrumenter, - Instrumenter, Response> dynamoInstrumenter) { + Instrumenter, Response> dynamoDbInstrumenter) { this.requestInstrumenter = requestInstrumenter; this.consumerReceiveInstrumenter = consumerReceiveInstrumenter; this.consumerProcessInstrumenter = consumerProcessInstrumenter; this.producerInstrumenter = producerInstrumenter; - this.dynamoInstrumenter = dynamoInstrumenter; + this.dynamoDbInstrumenter = dynamoDbInstrumenter; } @Override @@ -163,7 +163,7 @@ private void finish(Request request, Response response, @Nullable Throwabl private Instrumenter, Response> getInstrumenter(Request request) { String className = request.getOriginalRequest().getClass().getName(); if (className.startsWith(DYNAMODBV2)) { - return dynamoInstrumenter; + return dynamoDbInstrumenter; } else if (className.equals(SEND_MESSAGE_REQUEST)) { return producerInstrumenter; } 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 182f7def0d42..d95d3f59a204 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 @@ -18,6 +18,7 @@ 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 static org.assertj.core.api.Assertions.catchThrowable; @@ -34,7 +35,6 @@ import io.opentelemetry.testing.internal.armeria.common.HttpStatus; import io.opentelemetry.testing.internal.armeria.common.MediaType; import java.time.Duration; -import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; @@ -83,12 +83,12 @@ private static Stream provideArguments() { "CreateBucket", "PUT", (Function) c -> c.createBucket("testbucket"), - Collections.singletonList(createStringKeyPair("aws.bucket.name", "testbucket"))), + singletonList(createStringKeyPair("aws.bucket.name", "testbucket"))), Arguments.of( "GetObject", "GET", (Function) c -> c.getObject("someBucket", "someKey"), - Collections.singletonList(createStringKeyPair("aws.bucket.name", "someBucket")))); + singletonList(createStringKeyPair("aws.bucket.name", "someBucket")))); } @Test From 09e823a6dfcaa8d4f2252fe721302d141ffe2611 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Fri, 22 Nov 2024 15:15:50 -0500 Subject: [PATCH 08/11] 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; - } -} From d2b7fedb2523f4c52590e4109050c19686bf9f0c Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Fri, 22 Nov 2024 19:00:34 -0500 Subject: [PATCH 09/11] addressed comments --- .../awssdk/v1_11/DynamoDbAttributesExtractor.java | 4 ++-- .../instrumentation/awssdk/v1_11/AbstractSnsClientTest.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java index 22c0d88937b5..fdb77cdf788e 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java @@ -19,7 +19,7 @@ public class DynamoDbAttributesExtractor implements AttributesExtractor, Response> { private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); - private static final AttributeKey> AWS_TABLE_NAMES = + private static final AttributeKey> AWS_DYNAMODB_TABLE_NAMES = AttributeKey.stringArrayKey("aws.dynamodb.table_names"); private static final String DYNAMODB = "dynamodb"; @@ -29,7 +29,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, Request AttributesExtractorUtil.internalSet(attributes, DB_SYSTEM, DYNAMODB); String tableName = RequestAccess.getTableName(request.getOriginalRequest()); AttributesExtractorUtil.internalSet( - attributes, AWS_TABLE_NAMES, Collections.singletonList(tableName)); + attributes, AWS_DYNAMODB_TABLE_NAMES, Collections.singletonList(tableName)); } @Override 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 2c80e3165542..3f272ba47713 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,7 +5,6 @@ package io.opentelemetry.instrumentation.awssdk.v1_11; -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; @@ -56,7 +55,7 @@ public void testSendRequestWithMockedResponse(Function call) server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body)); List additionalAttributes = - singletonList(equalTo(stringKey(MESSAGING_DESTINATION_NAME.toString()), "somearn")); + singletonList(equalTo(MESSAGING_DESTINATION_NAME, "somearn")); Object response = call.apply(client); assertRequestWithMockedResponse( From b86f2de384b9a019be542294d6ec19596e6c12ed Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Wed, 27 Nov 2024 15:31:21 -0500 Subject: [PATCH 10/11] addressed nit comments --- .../awssdk/v1_11/DynamoDbAttributesExtractor.java | 1 + .../awssdk/v1_11/TracingRequestHandler.java | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java index fdb77cdf788e..db0a1832e162 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java @@ -18,6 +18,7 @@ public class DynamoDbAttributesExtractor implements AttributesExtractor, Response> { + // copied from DbIncubatingAttributes.DbSystemIncubatingValues private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); private static final AttributeKey> AWS_DYNAMODB_TABLE_NAMES = AttributeKey.stringArrayKey("aws.dynamodb.table_names"); 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 407593a079d0..49b9c5a626f4 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 @@ -31,9 +31,9 @@ final class TracingRequestHandler extends RequestHandler2 { ContextKey.named(TracingRequestHandler.class.getName() + ".Timer"); private static final ContextKey REQUEST_SPAN_SUPPRESSED_KEY = ContextKey.named(TracingRequestHandler.class.getName() + ".RequestSpanSuppressed"); - private static final String SEND_MESSAGE_REQUEST = + private static final String SEND_MESSAGE_REQUEST_CLASS = "com.amazonaws.services.sqs.model.SendMessageRequest"; - private static final String DYNAMODBV2 = "com.amazonaws.services.dynamodbv2.model."; + private static final String DYNAMODBV2_CLASS_PREFIX = "com.amazonaws.services.dynamodbv2.model."; private final Instrumenter, Response> requestInstrumenter; private final Instrumenter> consumerReceiveInstrumenter; @@ -162,10 +162,10 @@ private void finish(Request request, Response response, @Nullable Throwabl private Instrumenter, Response> getInstrumenter(Request request) { String className = request.getOriginalRequest().getClass().getName(); - if (className.startsWith(DYNAMODBV2)) { + if (className.startsWith(DYNAMODBV2_CLASS_PREFIX)) { return dynamoDbInstrumenter; } - if (className.equals(SEND_MESSAGE_REQUEST)) { + if (className.equals(SEND_MESSAGE_REQUEST_CLASS)) { return producerInstrumenter; } return requestInstrumenter; From 1a93d0d6c7c831efb479cbec2447f29721d191e6 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 28 Nov 2024 16:47:46 +0200 Subject: [PATCH 11/11] review --- .../awssdk/v1_11/DynamoDbAttributesExtractor.java | 4 +++- .../awssdk/v1_11/AbstractDynamoDbClientTest.java | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java index db0a1832e162..664c512db720 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java @@ -18,11 +18,13 @@ public class DynamoDbAttributesExtractor implements AttributesExtractor, Response> { - // copied from DbIncubatingAttributes.DbSystemIncubatingValues + // copied from DbIncubatingAttributes private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); + // copied from AwsIncubatingAttributes private static final AttributeKey> AWS_DYNAMODB_TABLE_NAMES = AttributeKey.stringArrayKey("aws.dynamodb.table_names"); + // copied from DbIncubatingAttributes.DbSystemIncubatingValues private static final String DYNAMODB = "dynamodb"; @Override 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 98ecc951ae52..441a4a3a0b59 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,9 +5,11 @@ package io.opentelemetry.instrumentation.awssdk.v1_11; -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 io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_DYNAMODB_TABLE_NAMES; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemIncubatingValues.DYNAMODB; import static java.util.Collections.singletonList; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; @@ -44,8 +46,8 @@ public void sendRequestWithMockedResponse() throws Exception { List additionalAttributes = Arrays.asList( equalTo(stringKey("aws.table.name"), "sometable"), - equalTo(stringKey("db.system"), "dynamodb"), - equalTo(stringArrayKey("aws.dynamodb.table_names"), singletonList("sometable"))); + equalTo(DB_SYSTEM, DYNAMODB), + equalTo(AWS_DYNAMODB_TABLE_NAMES, singletonList("sometable"))); Object response = client.createTable(new CreateTableRequest("sometable", null)); assertRequestWithMockedResponse(