Skip to content

Commit

Permalink
Capture message id in aws1 sqs instrumentation (#9841)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Nov 15, 2023
1 parent 37d1035 commit 0b5615f
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "s3ToSqsTestQueue"
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
}
}
span(2) {
Expand Down Expand Up @@ -583,6 +584,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "s3ToSnsToSqsTestQueue"
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "snsToSqsTestQueue"
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
}
}
span(2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ static boolean beforeMarshalling(AmazonWebServiceRequest request) {
static String getMessageAttribute(Request<?> request, String name) {
return enabled ? SqsImpl.getMessageAttribute(request, name) : null;
}

@NoMuzzle
static String getMessageId(Response<?> response) {
return enabled ? SqsImpl.getMessageId(response) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Long getMessagePayloadCompressedSize(Request<?> request) {
@Override
@Nullable
public String getMessageId(Request<?> request, @Nullable Response<?> response) {
return null;
return SqsAccess.getMessageId(response);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.amazonaws.services.sqs.model.ReceiveMessageRequest;
import com.amazonaws.services.sqs.model.ReceiveMessageResult;
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.amazonaws.services.sqs.model.SendMessageResult;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil;
Expand Down Expand Up @@ -134,4 +135,11 @@ static String getMessageAttribute(Request<?> request, String name) {
}
return null;
}

static String getMessageId(Response<?> response) {
if (response.getAwsResponse() instanceof SendMessageResult) {
return ((SendMessageResult) response.getAwsResponse()).getMessageId();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ interface SqsMessage {
Map<String, String> getAttributes();

String getMessageAttribute(String name);

String getMessageId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public String getMessageAttribute(String name) {
MessageAttributeValue value = message.getMessageAttributes().get(name);
return value != null ? value.getStringValue() : null;
}

@Override
public String getMessageId() {
return message.getMessageId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Long getMessagePayloadCompressedSize(SqsProcessRequest request) {
@Override
@Nullable
public String getMessageId(SqsProcessRequest request, @Nullable Void response) {
return null;
return request.getMessage().getMessageId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
Expand All @@ -129,6 +130,7 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
}
}
span(2) {
Expand Down Expand Up @@ -199,6 +201,7 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
Expand All @@ -222,6 +225,7 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
}
}
span(2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
Expand Down Expand Up @@ -175,6 +176,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
if (testCaptureHeaders) {
"messaging.header.test_message_header" { it == ["test"] }
}
Expand Down Expand Up @@ -252,6 +254,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
Expand Down Expand Up @@ -343,6 +346,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
}
}
span(4) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ static SpanDataAssert sqs(
attributeAssertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, "receive"));
} else if (spanName.endsWith("process")) {
attributeAssertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, "process"));
attributeAssertions.add(
satisfies(SemanticAttributes.MESSAGING_MESSAGE_ID, val -> assertThat(val).isNotNull()));
} else if (spanName.endsWith("publish")) {
attributeAssertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, "publish"));
attributeAssertions.add(
satisfies(SemanticAttributes.MESSAGING_MESSAGE_ID, val -> assertThat(val).isNotNull()));
}
}

Expand Down

0 comments on commit 0b5615f

Please sign in to comment.