Skip to content

Commit

Permalink
Merge pull request #2217 from newrelic/sqs-v1-dt-undo
Browse files Browse the repository at this point in the history
undo adding DT for SQS sdk v1
  • Loading branch information
obenkenobi authored Jan 23, 2025
2 parents e5bc12c + 250eeed commit e8715f2
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,45 +20,27 @@
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();
}

@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();
}

@Trace
public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) {
List<String> 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();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ public void testSendMessage() {
Introspector introspector = InstrumentationTestRunner.getIntrospector();
SendMessageRequest request = sendMessageRequest();

Set<String> 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();
Expand All @@ -94,14 +89,6 @@ public void testSendMessageBatch() {
SendMessageBatchRequest request = sendMessageBatch();
assertEquals(1, introspector.getFinishedTransactionCount(10000));

Set<String> 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);
}
Expand Down

0 comments on commit e8715f2

Please sign in to comment.