Skip to content

Commit 562b65d

Browse files
committed
Both topicArn and targetArn are optional for SNS publish requests; avoid NPE when only a phone number is provided
1 parent db5dfb4 commit 562b65d

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

  • dd-java-agent/instrumentation

dd-java-agent/instrumentation/aws-java-sns-1.0/src/main/java/datadog/trace/instrumentation/aws/v1/sns/SnsInterceptor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ public AmazonWebServiceRequest beforeMarshalling(AmazonWebServiceRequest request
5858
// the limit still applies here
5959
if (messageAttributes.size() < 10) {
6060
// Extract the topic name from the ARN for DSM
61-
String topicName =
62-
pRequest.getTopicArn() == null ? pRequest.getTargetArn() : pRequest.getTopicArn();
61+
String topicName = pRequest.getTopicArn();
62+
if (null == topicName) {
63+
topicName = pRequest.getTargetArn();
64+
if (null == topicName) {
65+
return request; // request is to phone number, ignore for DSM
66+
}
67+
}
68+
6369
topicName = topicName.substring(topicName.lastIndexOf(':') + 1);
6470

6571
HashMap<String, MessageAttributeValue> modifiedMessageAttributes =

dd-java-agent/instrumentation/aws-java-sns-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/sns/SnsInterceptor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ public SdkRequest modifyRequest(
5959
// the limit still applies here
6060
if (request.messageAttributes().size() < 10) {
6161
// Get topic name for DSM
62-
String snsTopicArn = request.topicArn() == null ? request.targetArn() : request.topicArn();
62+
String snsTopicArn = request.topicArn();
63+
if (null == snsTopicArn) {
64+
snsTopicArn = request.targetArn();
65+
if (null == snsTopicArn) {
66+
return request; // request is to phone number, ignore for DSM
67+
}
68+
}
69+
6370
String snsTopicName = snsTopicArn.substring(snsTopicArn.lastIndexOf(':') + 1);
6471
Map<String, MessageAttributeValue> modifiedMessageAttributes =
6572
new HashMap<>(request.messageAttributes());

0 commit comments

Comments
 (0)