Skip to content

Commit

Permalink
addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
akats7 committed Nov 22, 2024
1 parent 1b0a198 commit 09e823a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Request<?>, Response<?>> requestInstrumenter;
private final Instrumenter<SqsReceiveRequest, Response<?>> consumerReceiveInstrumenter;
Expand Down Expand Up @@ -164,7 +164,8 @@ private Instrumenter<Request<?>, 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +74,7 @@ public void assertRequestWithMockedResponse(
String service,
String operation,
String method,
List<AttributeKeyPair<?>> additionalAttributes)
List<AttributeAssertion> additionalAttributes)
throws Exception {

assertThat(response).isNotNull();
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,13 +41,11 @@ public void sendRequestWithMockedResponse() throws Exception {

server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, ""));

List<String> tableList = Collections.singletonList("sometable");

List<AttributeKeyPair<?>> additionalAttributes =
List<AttributeAssertion> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,8 +46,9 @@ public void testSendRequestWithMockedResponse(

server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, ""));

List<AttributeKeyPair<?>> additionalAttributes =
Arrays.asList(createStringKeyPair("aws.stream.name", "somestream"));
List<AttributeAssertion> additionalAttributes =
singletonList(equalTo(stringKey("aws.stream.name"), "somestream"));

Object response = call.apply(client);
assertRequestWithMockedResponse(
response, client, "Kinesis", operation, "POST", additionalAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void testSendRequestWithMockedResponse(
String operation,
String method,
Function<AmazonS3, Object> call,
List<AttributeKeyPair<?>> additionalAttributes)
List<AttributeAssertion> additionalAttributes)
throws Exception {

AmazonS3 client =
Expand All @@ -83,12 +83,12 @@ private static Stream<Arguments> provideArguments() {
"CreateBucket",
"PUT",
(Function<AmazonS3, Object>) c -> c.createBucket("testbucket"),
singletonList(createStringKeyPair("aws.bucket.name", "testbucket"))),
singletonList(equalTo(stringKey("aws.bucket.name"), "testbucket"))),
Arguments.of(
"GetObject",
"GET",
(Function<AmazonS3, Object>) c -> c.getObject("someBucket", "someKey"),
singletonList(createStringKeyPair("aws.bucket.name", "someBucket"))));
singletonList(equalTo(stringKey("aws.bucket.name"), "someBucket"))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,8 +55,8 @@ public void testSendRequestWithMockedResponse(Function<AmazonSNS, Object> call)

server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body));

List<AttributeKeyPair<?>> additionalAttributes =
Arrays.asList(createStringKeyPair(MESSAGING_DESTINATION_NAME.toString(), "somearn"));
List<AttributeAssertion> additionalAttributes =
singletonList(equalTo(stringKey(MESSAGING_DESTINATION_NAME.toString()), "somearn"));

Object response = call.apply(client);
assertRequestWithMockedResponse(
Expand Down

This file was deleted.

0 comments on commit 09e823a

Please sign in to comment.