diff --git a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/amazonaws/services/sqs/AmazonSQS_Instrumentation.java b/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/amazonaws/services/sqs/AmazonSQS_Instrumentation.java index 00013ef752..455890b263 100644 --- a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/amazonaws/services/sqs/AmazonSQS_Instrumentation.java +++ b/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/amazonaws/services/sqs/AmazonSQS_Instrumentation.java @@ -10,7 +10,6 @@ import com.amazonaws.services.sqs.model.ReceiveMessageRequest; import com.amazonaws.services.sqs.model.ReceiveMessageResult; import com.amazonaws.services.sqs.model.SendMessageBatchRequest; -import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry; import com.amazonaws.services.sqs.model.SendMessageBatchResult; import com.amazonaws.services.sqs.model.SendMessageRequest; import com.amazonaws.services.sqs.model.SendMessageResult; @@ -21,24 +20,13 @@ import com.newrelic.api.agent.weaver.MatchType; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; -import com.newrelic.utils.SQSBatchRequestHeaders; -import com.newrelic.utils.SQSRequestHeaders; import com.newrelic.utils.SqsV1Util; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - @Weave(type = MatchType.Interface, originalName = "com.amazonaws.services.sqs.AmazonSQS") public class AmazonSQS_Instrumentation { @Trace public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) { - for (SendMessageBatchRequestEntry request : sendMessageBatchRequest.getEntries()) { - SQSBatchRequestHeaders headers = new SQSBatchRequestHeaders(request); - NewRelic.getAgent().getTransaction().insertDistributedTraceHeaders(headers); - } - MessageProduceParameters messageProduceParameters = SqsV1Util.generateExternalProduceMetrics(sendMessageBatchRequest.getQueueUrl()); NewRelic.getAgent().getTracedMethod().reportAsExternal(messageProduceParameters); return Weaver.callOriginal(); @@ -46,9 +34,6 @@ public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessa @Trace public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { - SQSRequestHeaders headers = new SQSRequestHeaders(sendMessageRequest); - NewRelic.getAgent().getTransaction().insertDistributedTraceHeaders(headers); - MessageProduceParameters messageProduceParameters = SqsV1Util.generateExternalProduceMetrics(sendMessageRequest.getQueueUrl()); NewRelic.getAgent().getTracedMethod().reportAsExternal(messageProduceParameters); return Weaver.callOriginal(); @@ -56,10 +41,6 @@ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { @Trace public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) { - List updatedMessageAttrNames = new ArrayList<>(receiveMessageRequest.getMessageAttributeNames()); - Collections.addAll(updatedMessageAttrNames, SqsV1Util.DT_HEADERS); - receiveMessageRequest.setMessageAttributeNames(updatedMessageAttrNames); - MessageConsumeParameters messageConsumeParameters = SqsV1Util.generateExternalConsumeMetrics(receiveMessageRequest.getQueueUrl()); NewRelic.getAgent().getTracedMethod().reportAsExternal(messageConsumeParameters); return Weaver.callOriginal(); diff --git a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSBatchRequestHeaders.java b/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSBatchRequestHeaders.java deleted file mode 100644 index ba37cbb16c..0000000000 --- a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSBatchRequestHeaders.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.newrelic.utils; - -import com.amazonaws.services.sqs.model.MessageAttributeValue; -import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry; -import com.newrelic.api.agent.HeaderType; -import com.newrelic.api.agent.Headers; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class SQSBatchRequestHeaders implements Headers { - private final SendMessageBatchRequestEntry requestEntry; - - public SQSBatchRequestHeaders(SendMessageBatchRequestEntry re) { - requestEntry = re; - } - - @Override - public HeaderType getHeaderType() { - return HeaderType.MESSAGE; - } - - @Override - public String getHeader(String name) { - Map attributes = requestEntry.getMessageAttributes(); - if (attributes != null) { - MessageAttributeValue value = attributes.get(name); - if (value != null) { - String dataType = value.getDataType(); - if (dataType.equalsIgnoreCase("String")) { - String stringValue = value.getStringValue(); - if (stringValue != null) { - return stringValue; - } - } - } - } - return null; - } - - @Override - public Collection getHeaders(String name) { - List list = new ArrayList(); - String value = getHeader(name); - if (value != null && !value.isEmpty()) { - list.add(value); - } - return list; - } - - @Override - public void setHeader(String name, String value) { - if (requestEntry != null) { - requestEntry.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); - } - } - - @Override - public void addHeader(String name, String value) { - if (requestEntry != null) { - requestEntry.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); - } - } - - @Override - public Collection getHeaderNames() { - if (requestEntry != null) { - Map attributes = requestEntry.getMessageAttributes(); - if (attributes != null) { - return attributes.keySet(); - } - } - return Collections.emptyList(); - } - - @Override - public boolean containsHeader(String name) { - return getHeaderNames().contains(name); - } -} diff --git a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSRequestHeaders.java b/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSRequestHeaders.java deleted file mode 100644 index a0326c9a3f..0000000000 --- a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSRequestHeaders.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.newrelic.utils; - -import com.amazonaws.services.sqs.model.MessageAttributeValue; -import com.amazonaws.services.sqs.model.SendMessageRequest; -import com.newrelic.api.agent.HeaderType; -import com.newrelic.api.agent.Headers; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -public class SQSRequestHeaders implements Headers { - private final SendMessageRequest request; - - public SQSRequestHeaders(SendMessageRequest req) { - request = req; - } - - @Override - public HeaderType getHeaderType() { - return HeaderType.MESSAGE; - } - - @Override - public String getHeader(String name) { - Map messageAttributes = request.getMessageAttributes(); - if (messageAttributes != null) { - MessageAttributeValue value = messageAttributes.get(name); - if (value != null && value.getDataType().equalsIgnoreCase("string")) { - return value.getStringValue(); - } - } - Map customRequestHeaders = request.getCustomRequestHeaders(); - if (customRequestHeaders != null) { - return customRequestHeaders.get(name); - } - return null; - } - - @Override - public Collection getHeaders(String name) { - String value = getHeader(name); - if (value != null) { - return Collections.singletonList(value); - } - return Collections.emptyList(); - } - - @Override - public void setHeader(String name, String value) { - if (request != null) { - Map existingAttributes = request.getMessageAttributes(); - if (!existingAttributes.containsKey(name)) { - request.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); - } - } - } - - @Override - public void addHeader(String name, String value) { - if (request != null) { - Map existingAttributes = request.getMessageAttributes(); - if (!existingAttributes.containsKey(name)) { - request.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); - } - } - } - - @Override - public Collection getHeaderNames() { - Map messageAttributes = request.getMessageAttributes(); - return messageAttributes.keySet(); - } - - @Override - public boolean containsHeader(String name) { - return getHeaderNames().contains(name); - } -} diff --git a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SqsV1Util.java b/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SqsV1Util.java index d56d89cc7a..d0eb651739 100644 --- a/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SqsV1Util.java +++ b/instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SqsV1Util.java @@ -18,7 +18,6 @@ public class SqsV1Util { public static final String LIBRARY = "SQS"; public static final String OTEL_LIBRARY = "aws_sqs"; - public static final String[] DT_HEADERS = new String[] {"newrelic","NEWRELIC","NewRelic","tracestate","TraceState","TRACESTATE"}; public static MessageProduceParameters generateExternalProduceMetrics(String queueUrl) { DestinationData destinationData = DestinationData.parse(queueUrl); diff --git a/instrumentation/aws-java-sdk-sqs-1.10.44/src/test/java/com/amazonaws/services/sqs/SqsClientTest.java b/instrumentation/aws-java-sdk-sqs-1.10.44/src/test/java/com/amazonaws/services/sqs/SqsClientTest.java index dfa49b4116..9c5d97498f 100644 --- a/instrumentation/aws-java-sdk-sqs-1.10.44/src/test/java/com/amazonaws/services/sqs/SqsClientTest.java +++ b/instrumentation/aws-java-sdk-sqs-1.10.44/src/test/java/com/amazonaws/services/sqs/SqsClientTest.java @@ -77,11 +77,6 @@ public void testSendMessage() { Introspector introspector = InstrumentationTestRunner.getIntrospector(); SendMessageRequest request = sendMessageRequest(); - Set dtHeaders = new HashSet<>(Arrays.asList(SqsV1Util.DT_HEADERS)); - boolean containsDtHeaders = request.getMessageAttributes().entrySet().stream().anyMatch(e -> - dtHeaders.contains(e.getKey()) && e.getValue() != null && !e.getValue().getStringValue().isEmpty()); - assertTrue("Message request must contain headers", containsDtHeaders); - assertEquals(1, introspector.getFinishedTransactionCount(10000)); String txName = introspector.getTransactionNames().iterator().next(); @@ -94,14 +89,6 @@ public void testSendMessageBatch() { SendMessageBatchRequest request = sendMessageBatch(); assertEquals(1, introspector.getFinishedTransactionCount(10000)); - Set dtHeaders = new HashSet<>(Arrays.asList(SqsV1Util.DT_HEADERS)); - assertFalse("Batch request must contain at least one entry", request.getEntries().isEmpty()); - for (SendMessageBatchRequestEntry entry: request.getEntries()) { - boolean containsDtHeaders = entry.getMessageAttributes().entrySet().stream().anyMatch(e -> - dtHeaders.contains(e.getKey()) && e.getValue() != null && !e.getValue().getStringValue().isEmpty()); - assertTrue("Message entry must contain headers", containsDtHeaders); - } - String txName = introspector.getTransactionNames().iterator().next(); checkScopedMetricCount(txName, "MessageBroker/SQS/Queue/Produce/Named/" + QUEUE_NAME, 1); }