Skip to content

Commit 6f658fe

Browse files
committed
Add test
1 parent fa94628 commit 6f658fe

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

dd-java-agent/instrumentation/aws-java-sqs-1.0/src/main/java/datadog/trace/instrumentation/aws/v1/sqs/MessageExtractAdapter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import datadog.trace.api.Config;
88
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation;
99
import datadog.trace.bootstrap.instrumentation.messaging.DatadogAttributeParser;
10-
11-
import java.nio.ByteBuffer;
1210
import java.io.IOException;
11+
import java.nio.ByteBuffer;
1312
import java.util.Base64;
1413
import java.util.Map;
1514
import org.slf4j.Logger;
@@ -46,7 +45,8 @@ public void forEachKey(Message carrier, AgentPropagation.KeyClassifier classifie
4645
}
4746
}
4847

49-
public void forEachKeyInBody(String body, AgentPropagation.KeyClassifier classifier) throws IOException {
48+
public void forEachKeyInBody(String body, AgentPropagation.KeyClassifier classifier)
49+
throws IOException {
5050
ObjectMapper objectMapper = new ObjectMapper();
5151

5252
// Parse the JSON string into a JsonNode

dd-java-agent/instrumentation/aws-java-sqs-1.0/src/test/groovy/SqsClientTest.groovy

+48
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ abstract class SqsClientTest extends VersionedNamingTestBase {
4444
// Set a service name that gets sorted early with SORT_BY_NAMES
4545
injectSysConfig(GeneralConfig.SERVICE_NAME, "A-service")
4646
injectSysConfig(GeneralConfig.DATA_STREAMS_ENABLED, isDataStreamsEnabled().toString())
47+
injectSysConfig("sqs.body.propagation.enabled", "true")
4748
}
4849

4950
@Shared
@@ -511,6 +512,22 @@ class SqsClientV0DataStreamsTest extends SqsClientTest {
511512
}
512513

513514
class SqsClientV1DataStreamsForkedTest extends SqsClientTest {
515+
private static final String MESSAGE_WITH_ATTRIBUTES = "{\n" +
516+
" \"Type\" : \"Notification\",\n" +
517+
" \"MessageId\" : \"cb337e2a-1c06-5629-86f5-21fba14fb492\",\n" +
518+
" \"TopicArn\" : \"arn:aws:sns:us-east-1:223300679234:dsm-dev-sns-topic\",\n" +
519+
" \"Message\" : \"Some message\",\n" +
520+
" \"Timestamp\" : \"2024-12-10T03:52:41.662Z\",\n" +
521+
" \"SignatureVersion\" : \"1\",\n" +
522+
" \"Signature\" : \"ZsEewd5gNR8jLC08TenLDp5rhdBtGIdAzWk7j6fzDyUzb/t56R9SBPrNJtjsPO8Ep8v/iGs/wSFUrnm+Zh3N1duc3alR1bKTAbDlzbEBxaHsGcNwzMz14JF7bKLE+3nPIi0/kT8EuIiRevGqPtCG/NEe9oW2dOyvYZvt+L7GC0AS9L0yJp8Ag7NkgNvYbIqPeKcjj8S7WRiV95Useg0P46e5pn5FXmNKPlpIqYN28jnrTZHWUDTiO5RE7lfFcdH2tBaYSR9F/PwA1Mga5NrTxlZp/yDoOlOUFj5zXAtDDpjNTcR48jAu66Mpi1wom7Si7vc3ZsYzN2Z2ig/aUJLaNA==\",\n" +
523+
" \"SigningCertURL\" : \"https://sns.us-east-1.amazonaws.com/SimpleNotificationService-some-pem.pem\",\n" +
524+
" \"UnsubscribeURL\" : \"https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:7270067952343:dsm-dev-sns-topic:0d82adcc-5b42-4035-81c4-22ccd126fc41\",\n" +
525+
" \"MessageAttributes\" : {\n" +
526+
" \"_datadog\" : {\"Type\":\"Binary\",\"Value\":\"eyJ4LWRhdGFkb2ctdHJhY2UtaWQiOiI1ODExMzQ0MDA5MDA2NDM1Njk0IiwieC1kYXRhZG9nLXBhcmVudC1pZCI6Ijc3MjQzODMxMjg4OTMyNDAxNDAiLCJ4LWRhdGFkb2ctc2FtcGxpbmctcHJpb3JpdHkiOiIwIiwieC1kYXRhZG9nLXRhZ3MiOiJfZGQucC50aWQ9Njc1N2JiMDkwMDAwMDAwMCIsInRyYWNlcGFyZW50IjoiMDAtNjc1N2JiMDkwMDAwMDAwMDUwYTYwYTk2MWM2YzRkNmUtNmIzMjg1ODdiYWIzYjM0Yy0wMCIsInRyYWNlc3RhdGUiOiJkZD1zOjA7cDo2YjMyODU4N2JhYjNiMzRjO3QudGlkOjY3NTdiYjA5MDAwMDAwMDAiLCJkZC1wYXRod2F5LWN0eC1iYXNlNjQiOiJkdzdKcjU0VERkcjA5cFRyOVdUMDlwVHI5V1E9In0=\"}\n" +
527+
" }\n" +
528+
"}"
529+
530+
514531
@Override
515532
String expectedOperation(String awsService, String awsOperation) {
516533
if (awsService == "SQS") {
@@ -537,6 +554,37 @@ class SqsClientV1DataStreamsForkedTest extends SqsClientTest {
537554
int version() {
538555
1
539556
}
557+
558+
def "Data streams context extracted from message body"() {
559+
setup:
560+
def client = AmazonSQSClientBuilder.standard()
561+
.withEndpointConfiguration(endpoint)
562+
.withCredentials(credentialsProvider)
563+
.build()
564+
def queueUrl = client.createQueue('somequeue').queueUrl
565+
TEST_WRITER.clear()
566+
567+
when:
568+
injectSysConfig(GeneralConfig.DATA_STREAMS_ENABLED, "false")
569+
client.sendMessage(queueUrl, MESSAGE_WITH_ATTRIBUTES)
570+
injectSysConfig(GeneralConfig.DATA_STREAMS_ENABLED, "true")
571+
def messages = client.receiveMessage(queueUrl).messages
572+
messages.forEach {/* consume to create message spans */ }
573+
574+
TEST_DATA_STREAMS_WRITER.waitForGroups(1)
575+
576+
then:
577+
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == -2734507826469073289 }
578+
579+
verifyAll(first) {
580+
edgeTags == ["direction:in", "topic:somequeue", "type:sqs"]
581+
edgeTags.size() == 3
582+
}
583+
584+
cleanup:
585+
client.shutdown()
586+
}
587+
540588
}
541589

542590

dd-trace-api/src/main/java/datadog/trace/api/config/TraceInstrumentationConfig.java

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public final class TraceInstrumentationConfig {
158158
public static final String JAX_RS_ADDITIONAL_ANNOTATIONS = "trace.jax-rs.additional.annotations";
159159
/** If set, the instrumentation will set its resource name on the local root too. */
160160
public static final String AXIS_PROMOTE_RESOURCE_NAME = "trace.axis.promote.resource-name";
161+
161162
public static final String SQS_BODY_PROPAGATION_ENABLED = "sqs.body.propagation.enabled";
162163

163164
private TraceInstrumentationConfig() {}

0 commit comments

Comments
 (0)