|
38 | 38 | import java.lang.reflect.InvocationTargetException; |
39 | 39 | import java.lang.reflect.Method; |
40 | 40 | import java.net.URI; |
| 41 | +import java.nio.charset.Charset; |
41 | 42 | import java.nio.charset.StandardCharsets; |
42 | 43 | import java.time.Duration; |
43 | 44 | import java.util.ArrayList; |
|
76 | 77 | import software.amazon.awssdk.services.s3.S3ClientBuilder; |
77 | 78 | import software.amazon.awssdk.services.s3.model.CreateBucketRequest; |
78 | 79 | import software.amazon.awssdk.services.s3.model.GetObjectRequest; |
| 80 | +import software.amazon.awssdk.services.sns.SnsAsyncClient; |
| 81 | +import software.amazon.awssdk.services.sns.SnsAsyncClientBuilder; |
79 | 82 | import software.amazon.awssdk.services.sns.SnsClient; |
80 | 83 | import software.amazon.awssdk.services.sns.SnsClientBuilder; |
81 | 84 | import software.amazon.awssdk.services.sns.model.PublishRequest; |
@@ -122,6 +125,23 @@ private void clientAssertions( |
122 | 125 | assertThat(request.request().headers().get("X-Amzn-Trace-Id")).isNotNull(); |
123 | 126 | assertThat(request.request().headers().get("traceparent")).isNull(); |
124 | 127 |
|
| 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 | + |
125 | 145 | List<AttributeAssertion> attributes = |
126 | 146 | new ArrayList<>( |
127 | 147 | asList( |
@@ -504,6 +524,34 @@ void testSnsSendOperationRequestWithBuilder(Function<SnsClient, Object> call) { |
504 | 524 | clientAssertions("Sns", "Publish", "POST", response, "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0"); |
505 | 525 | } |
506 | 526 |
|
| 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 | + |
507 | 555 | @Test |
508 | 556 | void testEc2SendOperationRequestWithBuilder() throws Exception { |
509 | 557 | Ec2ClientBuilder builder = Ec2Client.builder(); |
@@ -584,6 +632,9 @@ void testRdsAsyncSendOperationRequestWithBuilder() { |
584 | 632 | "Rds", "DeleteOptionGroup", "POST", response, "0ac9cda2-bbf4-11d3-f92b-31fa5e8dbc99"); |
585 | 633 | } |
586 | 634 |
|
| 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. |
587 | 638 | @Test |
588 | 639 | void testTimeoutAndRetryErrorsAreNotCaptured() throws Exception { |
589 | 640 | // One retry so two requests. |
|
0 commit comments