Capture message id in aws1 sqs instrumentation (#9841)

This commit is contained in:
Lauri Tulmin 2023-11-15 22:46:12 +02:00 committed by GitHub
parent 37d1035430
commit 0b5615f9e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 2 deletions

View File

@ -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) {
@ -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 }
}

View File

@ -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) {

View File

@ -37,4 +37,9 @@ final class SqsAccess {
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;
}
}

View File

@ -54,7 +54,7 @@ enum SqsAttributesGetter implements MessagingAttributesGetter<Request<?>, Respon
@Override
@Nullable
public String getMessageId(Request<?> request, @Nullable Response<?> response) {
return null;
return SqsAccess.getMessageId(response);
}
@Override

View File

@ -13,6 +13,7 @@ import com.amazonaws.services.sqs.model.MessageAttributeValue;
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;
@ -134,4 +135,11 @@ final class SqsImpl {
}
return null;
}
static String getMessageId(Response<?> response) {
if (response.getAwsResponse() instanceof SendMessageResult) {
return ((SendMessageResult) response.getAwsResponse()).getMessageId();
}
return null;
}
}

View File

@ -16,4 +16,6 @@ interface SqsMessage {
Map<String, String> getAttributes();
String getMessageAttribute(String name);
String getMessageId();
}

View File

@ -41,4 +41,9 @@ final class SqsMessageImpl implements SqsMessage {
MessageAttributeValue value = message.getMessageAttributes().get(name);
return value != null ? value.getStringValue() : null;
}
@Override
public String getMessageId() {
return message.getMessageId();
}
}

View File

@ -53,7 +53,7 @@ enum SqsProcessRequestAttributesGetter
@Override
@Nullable
public String getMessageId(SqsProcessRequest request, @Nullable Void response) {
return null;
return request.getMessage().getMessageId();
}
@Override

View File

@ -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
@ -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) {
@ -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
@ -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) {

View File

@ -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
@ -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"] }
}
@ -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
@ -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) {

View File

@ -111,8 +111,12 @@ class AwsSpanAssertions {
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()));
}
}