-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Add AWS_SNS_TOPIC_ARN semantic convention support for AWS SNS SDK #14035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import static io.opentelemetry.semconv.UrlAttributes.URL_FULL; | ||
| import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_REQUEST_ID; | ||
| import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_SECRETSMANAGER_SECRET_ARN; | ||
| import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_SNS_TOPIC_ARN; | ||
| import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_STEP_FUNCTIONS_ACTIVITY_ARN; | ||
| import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_STEP_FUNCTIONS_STATE_MACHINE_ARN; | ||
| import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME; | ||
|
|
@@ -98,7 +99,12 @@ | |
| import software.amazon.awssdk.services.sns.SnsAsyncClientBuilder; | ||
| import software.amazon.awssdk.services.sns.SnsClient; | ||
| import software.amazon.awssdk.services.sns.SnsClientBuilder; | ||
| import software.amazon.awssdk.services.sns.model.CreateTopicRequest; | ||
| import software.amazon.awssdk.services.sns.model.CreateTopicResponse; | ||
| import software.amazon.awssdk.services.sns.model.PublishRequest; | ||
| import software.amazon.awssdk.services.sns.model.PublishResponse; | ||
| import software.amazon.awssdk.services.sns.model.SubscribeRequest; | ||
| import software.amazon.awssdk.services.sns.model.SubscribeResponse; | ||
| import software.amazon.awssdk.services.sqs.SqsAsyncClient; | ||
| import software.amazon.awssdk.services.sqs.SqsAsyncClientBuilder; | ||
| import software.amazon.awssdk.services.sqs.SqsClient; | ||
|
|
@@ -139,6 +145,36 @@ public abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest | |
| + " \"CreatedDate\": \"1.523477145713E9\"" | ||
| + "}"; | ||
|
|
||
| private static final String snsPublishResponseBody = | ||
| "<PublishResponse xmlns=\"https://sns.amazonaws.com/doc/2010-03-31/\">" | ||
| + " <PublishResult>" | ||
| + " <MessageId>567910cd-659e-55d4-8ccb-5aaf14679dc0</MessageId>" | ||
| + " </PublishResult>" | ||
| + " <ResponseMetadata>" | ||
| + " <RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId>" | ||
| + " </ResponseMetadata>" | ||
| + "</PublishResponse>"; | ||
|
|
||
| private static final String snsSubscribeResponseBody = | ||
| "<SubscribeResponse xmlns=\"https://sns.amazonaws.com/doc/2010-03-31/\">" | ||
| + " <SubscribeResult>" | ||
| + " <SubscriptionArn>arn:aws:sns:us-west-2:123456789012:MyTopic:abc123</SubscriptionArn>" | ||
| + " </SubscribeResult>" | ||
| + " <ResponseMetadata>" | ||
| + " <RequestId>0ac9cda2-abcd-11d3-f92b-31fa5e8dbc67</RequestId>" | ||
| + " </ResponseMetadata>" | ||
| + " </SubscribeResponse>"; | ||
|
|
||
| private static final String snsCreateTopicResponseBody = | ||
| "<CreateTopicResponse xmlns=\"https://sns.amazonaws.com/doc/2010-03-31/\">" | ||
| + " <CreateTopicResult>" | ||
| + " <TopicArn>arn:aws:sns:us-east-1:123456789012:sns-topic-name-foo</TopicArn>" | ||
| + " </CreateTopicResult>" | ||
| + " <ResponseMetadata>" | ||
| + " <RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId>" | ||
| + " </ResponseMetadata>" | ||
| + "</CreateTopicResponse>"; | ||
|
|
||
| private static void assumeSupportedConfig(String operation) { | ||
| Assumptions.assumeFalse( | ||
| operation.equals("SendMessage") && isSqsAttributeInjectionEnabled(), | ||
|
|
@@ -223,7 +259,22 @@ private void clientAssertions( | |
| } | ||
|
|
||
| if (service.equals("Sns")) { | ||
| attributes.add(equalTo(MESSAGING_DESTINATION_NAME, "somearn")); | ||
| switch (operation) { | ||
| case "CreateTopic": | ||
| attributes.add( | ||
| equalTo(AWS_SNS_TOPIC_ARN, "arn:aws:sns:us-east-1:123456789012:sns-topic-name-foo")); | ||
| break; | ||
| case "Publish": | ||
| attributes.add(equalTo(MESSAGING_DESTINATION_NAME, "sns-target-arn")); | ||
| break; | ||
| case "Subscribe": | ||
| attributes.add(equalTo(MESSAGING_DESTINATION_NAME, "sns-topic-arn")); | ||
| attributes.add(equalTo(AWS_SNS_TOPIC_ARN, "sns-topic-arn")); | ||
| break; | ||
| default: | ||
| attributes.add(equalTo(AWS_SNS_TOPIC_ARN, "Bug-Unknown-Operation-ARN")); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (service.equals("Sqs") && operation.equals("CreateQueue")) { | ||
|
|
@@ -516,22 +567,43 @@ private static Stream<Arguments> provideSnsArguments() { | |
| c -> | ||
| c.publish( | ||
| PublishRequest.builder() | ||
| .message("somemessage") | ||
| .topicArn("somearn") | ||
| .build())), | ||
| .message("sns-msg-foo") | ||
| .targetArn("sns-target-arn") | ||
| .build()), | ||
| "Publish", | ||
| "POST", | ||
| snsPublishResponseBody, | ||
| "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0"), | ||
| Arguments.of( | ||
| (Function<SnsClient, Object>) | ||
| c -> | ||
| c.publish( | ||
| PublishRequest.builder() | ||
| .message("somemessage") | ||
| .targetArn("somearn") | ||
| .build()))); | ||
| c.subscribe( | ||
| SubscribeRequest.builder() | ||
| .topicArn("sns-topic-arn") | ||
| .protocol("email") | ||
| .endpoint("[email protected]") | ||
| .build()), | ||
| "Subscribe", | ||
| "POST", | ||
| snsSubscribeResponseBody, | ||
| "0ac9cda2-abcd-11d3-f92b-31fa5e8dbc67"), | ||
| Arguments.of( | ||
| (Function<SnsClient, Object>) | ||
| c -> c.createTopic(CreateTopicRequest.builder().name("sns-topic-name-foo").build()), | ||
| "CreateTopic", | ||
| "POST", | ||
| snsCreateTopicResponseBody, | ||
| "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0")); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("provideSnsArguments") | ||
| void testSnsSendOperationRequestWithBuilder(Function<SnsClient, Object> call) { | ||
| void testSnsSendOperationRequestWithBuilder( | ||
| Function<SnsClient, Object> call, | ||
| String operation, | ||
| String method, | ||
| String responseBody, | ||
| String requestId) { | ||
| SnsClientBuilder builder = SnsClient.builder(); | ||
| configureSdkClient(builder); | ||
| SnsClient client = | ||
|
|
@@ -541,28 +613,25 @@ void testSnsSendOperationRequestWithBuilder(Function<SnsClient, Object> call) { | |
| .credentialsProvider(CREDENTIALS_PROVIDER) | ||
| .build(); | ||
|
|
||
| String body = | ||
| "<PublishResponse xmlns=\"https://sns.amazonaws.com/doc/2010-03-31/\">" | ||
| + " <PublishResult>" | ||
| + " <MessageId>567910cd-659e-55d4-8ccb-5aaf14679dc0</MessageId>" | ||
| + " </PublishResult>" | ||
| + " <ResponseMetadata>" | ||
| + " <RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId>" | ||
| + " </ResponseMetadata>" | ||
| + "</PublishResponse>"; | ||
|
|
||
| server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body)); | ||
| server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, responseBody)); | ||
| Object response = call.apply(client); | ||
|
|
||
| assertThat(response.getClass().getSimpleName()) | ||
| .satisfiesAnyOf( | ||
| v -> assertThat(v).startsWith("Publish"), | ||
| v -> assertThat(response).isInstanceOf(ResponseInputStream.class)); | ||
| clientAssertions("Sns", "Publish", "POST", response, "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0"); | ||
| v -> assertThat(response).isInstanceOf(CreateTopicResponse.class), | ||
| v -> assertThat(response).isInstanceOf(PublishResponse.class), | ||
| v -> assertThat(response).isInstanceOf(SubscribeResponse.class)); | ||
| clientAssertions("Sns", operation, method, response, requestId); | ||
| } | ||
|
|
||
| @Test | ||
| void testSnsAsyncSendOperationRequestWithBuilder() { | ||
| @ParameterizedTest | ||
| @MethodSource("provideSnsArguments") | ||
| void testSnsAsyncSendOperationRequestWithBuilder( | ||
| Function<SnsClient, Object> call, | ||
| String operation, | ||
| String method, | ||
| String responseBody, | ||
| String requestId) { | ||
| SnsAsyncClientBuilder builder = SnsAsyncClient.builder(); | ||
| configureSdkClient(builder); | ||
| SnsAsyncClient client = | ||
|
|
@@ -572,20 +641,15 @@ void testSnsAsyncSendOperationRequestWithBuilder() { | |
| .credentialsProvider(CREDENTIALS_PROVIDER) | ||
| .build(); | ||
|
|
||
| String body = | ||
| "<PublishResponse xmlns=\"https://sns.amazonaws.com/doc/2010-03-31/\">" | ||
| + " <PublishResult>" | ||
| + " <MessageId>94f20ce6-13c5-43a0-9a9e-ca52d816e90b</MessageId>" | ||
| + " </PublishResult>" | ||
| + " <ResponseMetadata>" | ||
| + " <RequestId>f187a3c1-376f-11df-8963-01868b7c937a</RequestId>" | ||
| + " </ResponseMetadata>" | ||
| + "</PublishResponse>"; | ||
|
|
||
| server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body)); | ||
| Object response = client.publish(r -> r.message("hello").topicArn("somearn")); | ||
| server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, responseBody)); | ||
| Object response = call.apply(wrapClient(SnsClient.class, SnsAsyncClient.class, client)); | ||
|
|
||
| clientAssertions("Sns", "Publish", "POST", response, "f187a3c1-376f-11df-8963-01868b7c937a"); | ||
| assertThat(response.getClass().getSimpleName()) | ||
| .satisfiesAnyOf( | ||
| v -> assertThat(response).isInstanceOf(CreateTopicResponse.class), | ||
| v -> assertThat(response).isInstanceOf(PublishResponse.class), | ||
| v -> assertThat(response).isInstanceOf(SubscribeResponse.class)); | ||
| clientAssertions("Sns", operation, method, response, requestId); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I can tell you could have kept the original parameterized tests and just added the
additionalAttributesas another parameterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good feedback. Thank you @laurit.