Skip to content

Commit 639fc25

Browse files
committed
forgot sns async
1 parent 17efec7 commit 639fc25

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.lang.reflect.InvocationTargetException;
3939
import java.lang.reflect.Method;
4040
import java.net.URI;
41+
import java.nio.charset.Charset;
4142
import java.nio.charset.StandardCharsets;
4243
import java.time.Duration;
4344
import java.util.ArrayList;
@@ -76,6 +77,8 @@
7677
import software.amazon.awssdk.services.s3.S3ClientBuilder;
7778
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
7879
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
80+
import software.amazon.awssdk.services.sns.SnsAsyncClient;
81+
import software.amazon.awssdk.services.sns.SnsAsyncClientBuilder;
7982
import software.amazon.awssdk.services.sns.SnsClient;
8083
import software.amazon.awssdk.services.sns.SnsClientBuilder;
8184
import software.amazon.awssdk.services.sns.model.PublishRequest;
@@ -122,6 +125,23 @@ private void clientAssertions(
122125
assertThat(request.request().headers().get("X-Amzn-Trace-Id")).isNotNull();
123126
assertThat(request.request().headers().get("traceparent")).isNull();
124127

128+
if (service.equals("SNS") && operation.equals("Publish")) {
129+
String content = request.request().content(Charset.defaultCharset());
130+
boolean containsId =
131+
content.contains(
132+
getTesting().spans().get(0).getTraceId()
133+
+ "-"
134+
+ getTesting().spans().get(0).getSpanId());
135+
boolean containsTp = content.contains("=traceparent");
136+
if (isSqsAttributeInjectionEnabled()) {
137+
assertThat(containsId).isTrue();
138+
assertThat(containsTp).isTrue();
139+
} else {
140+
assertThat(containsId).isFalse();
141+
assertThat(containsTp).isFalse();
142+
}
143+
}
144+
125145
List<AttributeAssertion> attributes =
126146
new ArrayList<>(
127147
asList(
@@ -504,6 +524,34 @@ void testSnsSendOperationRequestWithBuilder(Function<SnsClient, Object> call) {
504524
clientAssertions("Sns", "Publish", "POST", response, "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0");
505525
}
506526

527+
@ParameterizedTest
528+
@MethodSource("provideSnsArguments")
529+
void testSnsAsyncSendOperationRequestWithBuilder() {
530+
SnsAsyncClientBuilder builder = SnsAsyncClient.builder();
531+
configureSdkClient(builder);
532+
SnsAsyncClient client =
533+
builder
534+
.endpointOverride(clientUri)
535+
.region(Region.AP_NORTHEAST_1)
536+
.credentialsProvider(CREDENTIALS_PROVIDER)
537+
.build();
538+
539+
String body =
540+
"<PublishResponse xmlns=\"https://sns.amazonaws.com/doc/2010-03-31/\">"
541+
+ " <PublishResult>"
542+
+ " <MessageId>94f20ce6-13c5-43a0-9a9e-ca52d816e90b</MessageId>"
543+
+ " </PublishResult>"
544+
+ " <ResponseMetadata>"
545+
+ " <RequestId>f187a3c1-376f-11df-8963-01868b7c937a</RequestId>"
546+
+ " </ResponseMetadata>"
547+
+ "</PublishResponse>";
548+
549+
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body));
550+
Object response = client.publish(r -> r.message("hello").topicArn("somearn"));
551+
552+
clientAssertions("Sns", "Publish", "POST", response, "f187a3c1-376f-11df-8963-01868b7c937a");
553+
}
554+
507555
@Test
508556
void testEc2SendOperationRequestWithBuilder() throws Exception {
509557
Ec2ClientBuilder builder = Ec2Client.builder();
@@ -584,6 +632,9 @@ void testRdsAsyncSendOperationRequestWithBuilder() {
584632
"Rds", "DeleteOptionGroup", "POST", response, "0ac9cda2-bbf4-11d3-f92b-31fa5e8dbc99");
585633
}
586634

635+
// TODO: Without AOP instrumentation of the HTTP client, we cannot model retries as
636+
// spans because of https://github.com/aws/aws-sdk-java-v2/issues/1741. We should at least tweak
637+
// the instrumentation to add Events for retries instead.
587638
@Test
588639
void testTimeoutAndRetryErrorsAreNotCaptured() throws Exception {
589640
// One retry so two requests.

0 commit comments

Comments
 (0)