From 0b5615f9e636dc698aac1f896c7299ab7350d90c Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Wed, 15 Nov 2023 22:46:12 +0200 Subject: [PATCH] Capture message id in aws1 sqs instrumentation (#9841) --- .../javaagent/src/test/groovy/S3TracingTest.groovy | 2 ++ .../javaagent/src/test/groovy/SnsTracingTest.groovy | 1 + .../instrumentation/awssdk/v1_11/SqsAccess.java | 5 +++++ .../instrumentation/awssdk/v1_11/SqsAttributesGetter.java | 2 +- .../instrumentation/awssdk/v1_11/SqsImpl.java | 8 ++++++++ .../instrumentation/awssdk/v1_11/SqsMessage.java | 2 ++ .../instrumentation/awssdk/v1_11/SqsMessageImpl.java | 5 +++++ .../awssdk/v1_11/SqsProcessRequestAttributesGetter.java | 2 +- .../v1_11/AbstractSqsSuppressReceiveSpansTest.groovy | 4 ++++ .../awssdk/v1_11/AbstractSqsTracingTest.groovy | 4 ++++ .../apachecamel/aws/AwsSpanAssertions.java | 4 ++++ 11 files changed, 37 insertions(+), 2 deletions(-) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy index e1caeb5174..987a50ed95 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy @@ -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 } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy index 32ce42e1f2..97749cf085 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy @@ -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) { diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAccess.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAccess.java index c077dbd8c6..1b1104f669 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAccess.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAccess.java @@ -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; + } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAttributesGetter.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAttributesGetter.java index 012fa8d0e7..0a22f79c3d 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAttributesGetter.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsAttributesGetter.java @@ -54,7 +54,7 @@ enum SqsAttributesGetter implements MessagingAttributesGetter, Respon @Override @Nullable public String getMessageId(Request request, @Nullable Response response) { - return null; + return SqsAccess.getMessageId(response); } @Override diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsImpl.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsImpl.java index fdecfbe215..a3e2d0e770 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsImpl.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsImpl.java @@ -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; + } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessage.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessage.java index 8da1924f88..637c68eadb 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessage.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessage.java @@ -16,4 +16,6 @@ interface SqsMessage { Map getAttributes(); String getMessageAttribute(String name); + + String getMessageId(); } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessageImpl.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessageImpl.java index 5b9c993f5b..548e108a76 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessageImpl.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsMessageImpl.java @@ -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(); + } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsProcessRequestAttributesGetter.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsProcessRequestAttributesGetter.java index 24bfc3c345..d8de1710c6 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsProcessRequestAttributesGetter.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/SqsProcessRequestAttributesGetter.java @@ -53,7 +53,7 @@ enum SqsProcessRequestAttributesGetter @Override @Nullable public String getMessageId(SqsProcessRequest request, @Nullable Void response) { - return null; + return request.getMessage().getMessageId(); } @Override diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy index 782412c5ad..07c041e52d 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy @@ -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) { diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy index 2ea007fa08..eff15ed53f 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy @@ -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) { diff --git a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java index ff7ecc69e4..4a9d920f0b 100644 --- a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java +++ b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java @@ -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())); } }