diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SnsCamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SnsCamelTest.groovy deleted file mode 100644 index 55ad4ac9876a..000000000000 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SnsCamelTest.groovy +++ /dev/null @@ -1,696 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.apachecamel - -import static io.opentelemetry.api.trace.SpanKind.CLIENT -import static io.opentelemetry.api.trace.SpanKind.CONSUMER -import static io.opentelemetry.api.trace.SpanKind.INTERNAL - -import com.amazonaws.services.sns.AmazonSNSClient -import com.amazonaws.services.sns.model.CreateTopicResult -import com.amazonaws.services.sqs.AmazonSQSClient -import com.amazonaws.services.sqs.model.GetQueueAttributesRequest -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import org.apache.camel.CamelContext -import org.apache.camel.ProducerTemplate -import org.springframework.boot.SpringApplication -import org.springframework.context.ConfigurableApplicationContext -import spock.lang.Ignore -import spock.lang.Shared - -@Ignore("Does not work with localstack - X-Ray features needed") -class SnsCamelTest extends AgentInstrumentationSpecification { - - @Shared - ConfigurableApplicationContext server - @Shared - AmazonSQSClient sqsClient - @Shared - AmazonSNSClient snsClient - @Shared - CamelContext camelContext - - def setupSpec() { - def app = new SpringApplication(SnsConfig) - server = app.run() - camelContext = server.getBean(CamelContext) - sqsClient = server.getBean("sqsClient") - snsClient = server.getBean("snsClient") - } - - def getQueueArn(String queueUrl) { - return sqsClient.getQueueAttributes( - new GetQueueAttributesRequest(queueUrl) - .withAttributeNames("QueueArn")).getAttributes() - .get("QueueArn") - } - - def setQueuePolicy(String queueUrl, String queueArn) { - sqsClient.setQueueAttributes(queueUrl, Collections.singletonMap("Policy", String.format(SQS_POLICY, queueArn))) - } - - private static final String SQS_POLICY = "{" + - " \"Statement\": [" + - " {" + - " \"Effect\": \"Allow\"," + - " \"Principal\": \"*\"," + - " \"Action\": \"sqs:SendMessage\"," + - " \"Resource\": \"%s\"" + - " }]" + - "}" - - def createAndSubscribeTopic(String topicName, String queueArn) { - CreateTopicResult ctr = snsClient.createTopic(topicName) - snsClient.subscribe(ctr.getTopicArn(), "sqs", queueArn) - return ctr.getTopicArn() - } - - def "AWS SDK SNS producer - camel SQS consumer"() { - setup: - String topicName = "snsCamelTest" - String queueName = "snsCamelTest" - - String queueUrl = sqsClient.createQueue(queueName).getQueueUrl() - String queueArn = getQueueArn(queueUrl) - setQueuePolicy(queueUrl, queueArn) - String topicArn = createAndSubscribeTopic(topicName, queueArn) - - when: - snsClient.publish(topicArn, "Hello there!") - - then: - assertTraces(12) { - trace(0, 1) { - - span(0) { - name "SQS.CreateQueue" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "CreateQueue" - "aws.queue.name" queueName - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(1, 1) { - - span(0) { - name "SQS.GetQueueAttributes" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "GetQueueAttributes" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(2, 1) { - - span(0) { - name "SQS.SetQueueAttributes" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "SetQueueAttributes" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(3, 1) { - - span(0) { - name "SNS.CreateTopic" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "CreateTopic" - "aws.service" "AmazonSNS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(4, 1) { - - span(0) { - name "SNS.Subscribe" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "Subscribe" - "aws.service" "AmazonSNS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(5, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(6, 3) { - span(0) { - name "SNS.Publish" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "Publish" - "aws.service" "AmazonSNS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - span(1) { - name "SQS.ReceiveMessage" - kind CONSUMER - childOf span(0) - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "http.user_agent" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - span(2) { - name "snsCamelTest" - kind INTERNAL - childOf span(0) - attributes { - "apache-camel.uri" "aws-sqs://${queueName}?amazonSQSClient=%23sqsClient" - "messaging.destination" queueName - "messaging.message_id" String - } - } - } - trace(7, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(8, 1) { - span(0) { - name "SQS.DeleteMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "DeleteMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(9, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(10, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(11, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - } - } - - def "camel SNS producer - camel SQS consumer"() { - setup: - String topicName = "snsCamelTest" - String queueName = "snsCamelTest" - - String queueUrl = sqsClient.createQueue(queueName).getQueueUrl() - String queueArn = getQueueArn(queueUrl) - setQueuePolicy(queueUrl, queueArn) - createAndSubscribeTopic(topicName, queueArn) - - ProducerTemplate template = camelContext.createProducerTemplate() - - when: - template.sendBody("direct:input", "{\"type\": \"hello\"}") - - then: - assertTraces(12) { - trace(0, 1) { - - span(0) { - name "SQS.CreateQueue" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "CreateQueue" - "aws.queue.name" queueName - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(1, 1) { - - span(0) { - name "SQS.GetQueueAttributes" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "GetQueueAttributes" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(2, 1) { - - span(0) { - name "SQS.SetQueueAttributes" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "SetQueueAttributes" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(3, 1) { - - span(0) { - name "SNS.CreateTopic" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "CreateTopic" - "aws.service" "AmazonSNS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(4, 1) { - - span(0) { - name "SNS.Subscribe" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "Subscribe" - "aws.service" "AmazonSNS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" {it == null || Number} - } - } - } - trace(5, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(6, 5) { - - span(0) { - name "input" - kind INTERNAL - hasNoParent() - attributes { - "apache-camel.uri" "direct://input" - } - } - span(1) { - name topicName - kind INTERNAL - childOf span(0) - attributes { - "apache-camel.uri" "aws-sns://${topicName}?amazonSNSClient=%23snsClient" - "messaging.destination" topicName - } - } - span(2) { - name "SNS.Publish" - kind CLIENT - childOf span(1) - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "Publish" - "aws.service" "AmazonSNS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - span(3) { - name "SQS.ReceiveMessage" - kind CONSUMER - childOf span(2) - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "http.user_agent" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - span(4) { - name "snsCamelTest" - kind INTERNAL - childOf span(2) - attributes { - "apache-camel.uri" "aws-sqs://${queueName}?amazonSQSClient=%23sqsClient" - "messaging.destination" queueName - "messaging.message_id" String - } - } - } - trace(7, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(8, 1) { - span(0) { - name "SQS.DeleteMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "DeleteMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(9, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(10, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - trace(11, 1) { - span(0) { - name "SQS.ReceiveMessage" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ReceiveMessage" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" - "http.flavor" "1.1" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" {it == null || Number} - "net.transport" "IP.TCP" - } - } - } - } - } - -} - diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SnsConfig.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SnsConfig.groovy deleted file mode 100644 index 1935827d2039..000000000000 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SnsConfig.groovy +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.apachecamel - -import com.amazonaws.services.sns.AmazonSNSAsyncClient -import com.amazonaws.services.sns.AmazonSNSClient -import com.amazonaws.services.sqs.AmazonSQSAsyncClient -import com.amazonaws.services.sqs.AmazonSQSClient -import org.apache.camel.LoggingLevel -import org.apache.camel.builder.RouteBuilder -import org.springframework.boot.SpringBootConfiguration -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.Bean -import org.testcontainers.containers.localstack.LocalStackContainer -import org.testcontainers.utility.DockerImageName - -@SpringBootConfiguration -@EnableAutoConfiguration -class SnsConfig { - - @Bean - LocalStackContainer localstack() { - LocalStackContainer localstack = new LocalStackContainer(DockerImageName.parse("localstack/localstack:latest")) - .withServices(LocalStackContainer.Service.SQS, LocalStackContainer.Service.SNS) - localstack.start() - return localstack - } - - @Bean - RouteBuilder sqsCamelOnlyConsumerRoute() { - return new RouteBuilder() { - - @Override - void configure() throws Exception { - from("aws-sqs://snsCamelTest?amazonSQSClient=#sqsClient") - .log(LoggingLevel.INFO, "test", "RECEIVER got body : \${body}") - .log(LoggingLevel.INFO, "test", "RECEIVER got headers : \${headers}") - } - } - } - - @Bean - RouteBuilder snsProducerRoute() { - return new RouteBuilder() { - - @Override - void configure() throws Exception { - from("direct:input") - .log(LoggingLevel.INFO, "test", "SENDING body: \${body}") - .log(LoggingLevel.INFO, "test", "SENDING headers: \${headers}") - .to("aws-sns://snsCamelTest?amazonSNSClient=#snsClient") - } - } - } - - @Bean - AmazonSQSClient sqsClient(LocalStackContainer localstack) { - return AmazonSQSAsyncClient.asyncBuilder() - .withEndpointConfiguration(localstack.getEndpointConfiguration(LocalStackContainer.Service.SQS)) - .withCredentials(localstack.getDefaultCredentialsProvider()) - .build() - } - - @Bean - AmazonSNSClient snsClient(LocalStackContainer localstack) { - return AmazonSNSAsyncClient.asyncBuilder() - .withEndpointConfiguration(localstack.getEndpointConfiguration(LocalStackContainer.Service.SNS)) - .withCredentials(localstack.getDefaultCredentialsProvider()) - .build() - } -} diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/AwsConnector.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsConnector.groovy similarity index 84% rename from instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/AwsConnector.groovy rename to instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsConnector.groovy index 249a782f8325..3905cd7edfb5 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/AwsConnector.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsConnector.groovy @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.apachecamel +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws import com.amazonaws.services.s3.AmazonS3Client import com.amazonaws.services.s3.model.BucketNotificationConfiguration @@ -12,7 +12,6 @@ import com.amazonaws.services.s3.model.QueueConfiguration import com.amazonaws.services.s3.model.S3Event import com.amazonaws.services.s3.model.S3ObjectSummary import com.amazonaws.services.s3.model.SetBucketNotificationConfigurationRequest -import com.amazonaws.services.s3.model.TopicConfiguration import com.amazonaws.services.sns.AmazonSNSAsyncClient import com.amazonaws.services.sns.model.CreateTopicResult import com.amazonaws.services.sns.model.SetTopicAttributesRequest @@ -23,7 +22,6 @@ import com.amazonaws.services.sqs.model.ReceiveMessageRequest class AwsConnector { - private AmazonSQSAsyncClient sqsClient private AmazonS3Client s3Client private AmazonSNSAsyncClient snsClient @@ -33,16 +31,26 @@ class AwsConnector { awsConnector.sqsClient = AmazonSQSAsyncClient.asyncBuilder() .build() - awsConnector.s3Client = AmazonS3Client.builder() .build() - awsConnector.snsClient = AmazonSNSAsyncClient.asyncBuilder() .build() return awsConnector } + AmazonSQSAsyncClient getSqsClient() { + return sqsClient + } + + AmazonS3Client getS3Client() { + return s3Client + } + + AmazonSNSAsyncClient getSnsClient() { + return snsClient + } + def createQueue(String queueName) { println "Create queue ${queueName}" return sqsClient.createQueue(queueName).getQueueUrl() @@ -110,15 +118,6 @@ class AwsConnector { bucketName, notificationConfiguration)) } - def enableS3ToSnsNotifications(String bucketName, String snsTopicArn) { - println "Enable notification for bucket ${bucketName} to topic ${snsTopicArn}" - BucketNotificationConfiguration notificationConfiguration = new BucketNotificationConfiguration() - notificationConfiguration.addConfiguration("snsTopicConfig", - new TopicConfiguration(snsTopicArn, EnumSet.of(S3Event.ObjectCreatedByPut))) - s3Client.setBucketNotificationConfiguration(new SetBucketNotificationConfigurationRequest( - bucketName, notificationConfiguration)) - } - def createTopicAndSubscribeQueue(String topicName, String queueArn) { println "Create topic ${topicName} and subscribe to queue ${queueArn}" CreateTopicResult ctr = snsClient.createTopic(topicName) @@ -136,11 +135,6 @@ class AwsConnector { sqsClient.purgeQueue(new PurgeQueueRequest(queueUrl)) } - def putSampleData(String bucketName) { - println "Put sample data to bucket ${bucketName}" - s3Client.putObject(bucketName, "otelTestKey", "otelTestData") - } - def publishSampleNotification(String topicArn) { snsClient.publish(topicArn, "Hello There") } diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpan.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpan.groovy new file mode 100644 index 000000000000..e01c7179f196 --- /dev/null +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpan.groovy @@ -0,0 +1,67 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws + +import static io.opentelemetry.api.trace.SpanKind.CLIENT + +import io.opentelemetry.instrumentation.test.asserts.TraceAssert + +class AwsSpan { + + static s3(TraceAssert traceAssert, int index, spanName, bucketName, method="GET", parentSpan=null) { + return traceAssert.span(index) { + name spanName + kind CLIENT + if (index == 0) { + hasNoParent() + } else { + childOf parentSpan + } + attributes { + "aws.agent" "java-aws-sdk" + "aws.endpoint" String + "aws.operation" spanName.substring(3) + "aws.service" "Amazon S3" + "aws.bucket.name" bucketName + "http.flavor" "1.1" + "http.method" method + "http.status_code" 200 + "http.url" String + "net.peer.name" String + "net.transport" "IP.TCP" + "net.peer.port" { it == null || Number } + } + } + } + + static sqs(TraceAssert traceAssert, int index, spanName, queueUrl=null, queueName=null, spanKind=CLIENT, parentSpan=null) { + return traceAssert.span(index) { + name spanName + kind spanKind + if (index == 0) { + hasNoParent() + } else { + childOf parentSpan + } + attributes { + "aws.agent" "java-aws-sdk" + "aws.endpoint" String + "aws.operation" spanName.substring(4) + "aws.service" "AmazonSQS" + "aws.queue.name" {it == null || it == queueName} + "aws.queue.url" {it == null || it == queueUrl} + "http.flavor" "1.1" + "http.method" "POST" + "http.status_code" 200 + "http.url" String + "http.user_agent" { it == null || String } + "net.peer.name" String + "net.peer.port" { it == null || Number } + "net.transport" "IP.TCP" + } + } + } +} diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/CamelSpringApp.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/CamelSpringApp.groovy new file mode 100644 index 000000000000..69e5011ee07d --- /dev/null +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/CamelSpringApp.groovy @@ -0,0 +1,51 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws + +import org.apache.camel.CamelContext +import org.apache.camel.ProducerTemplate +import org.springframework.boot.SpringApplication +import org.springframework.context.ApplicationContextInitializer +import org.springframework.context.ConfigurableApplicationContext +import org.springframework.context.support.AbstractApplicationContext + +class CamelSpringApp { + + private SpringApplication springApplication + private ConfigurableApplicationContext context + + CamelSpringApp(AwsConnector awsConnector, Class config, Map properties) { + springApplication = new SpringApplication(config) + springApplication.setDefaultProperties(properties) + injectClients(awsConnector) + } + + private injectClients(AwsConnector awsConnector) { + springApplication.addInitializers(new ApplicationContextInitializer() { + @Override + void initialize(AbstractApplicationContext applicationContext) { + applicationContext.getBeanFactory().registerSingleton("snsClient", awsConnector.getSnsClient()) + applicationContext.getBeanFactory().registerSingleton("sqsClient", awsConnector.getSqsClient()) + applicationContext.getBeanFactory().registerSingleton("s3Client", awsConnector.getS3Client()) + } + }) + } + + def start() { + context = springApplication.run() + } + + ProducerTemplate producerTemplate() { + def camelContext = context.getBean(CamelContext) + return camelContext.createProducerTemplate() + } + + def stop() { + if (context != null) { + SpringApplication.exit(context) + } + } +} diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/S3CamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/S3CamelTest.groovy new file mode 100644 index 000000000000..41cc5441c75e --- /dev/null +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/S3CamelTest.groovy @@ -0,0 +1,130 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws + +import static io.opentelemetry.api.trace.SpanKind.CONSUMER +import static io.opentelemetry.api.trace.SpanKind.INTERNAL + +import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import org.testcontainers.shaded.com.google.common.collect.ImmutableMap +import spock.lang.Ignore +import spock.lang.Shared + +@Ignore("Does not work with localstack - X-Ray features needed") +class S3CamelTest extends AgentInstrumentationSpecification { + + @Shared + AwsConnector awsConnector = AwsConnector.liveAws() + + def "camel S3 producer - camel SQS consumer"() { + setup: + String bucketName = "bucket-test-s3-sqs-camel" + String queueName = "s3SqsCamelTest" + def camelApp = new CamelSpringApp(awsConnector, S3Config, ImmutableMap.of("bucketName", bucketName, "queueName", queueName)) + + // setup infra + String queueUrl = awsConnector.createQueue(queueName) + awsConnector.createBucket(bucketName) + String queueArn = awsConnector.getQueueArn(queueUrl) + awsConnector.setQueuePublishingPolicy(queueUrl, queueArn) + awsConnector.enableS3ToSqsNotifications(bucketName, queueArn) + + // consume test message from AWS + awsConnector.receiveMessage(queueUrl) + + // wait for setup traces + waitAndClearSetupTraces(queueUrl, queueName, bucketName) + + when: + camelApp.start() + camelApp.producerTemplate().sendBody("direct:input", "{\"type\": \"hello\"}") + + then: + assertTraces(6) { + trace(0, 1) { + AwsSpan.sqs(it, 0, "SQS.ListQueues") + } + trace(1, 1) { + AwsSpan.s3(it, 0, "S3.ListObjects", bucketName) + } + trace(2, 5) { + span(0) { + name "input" + kind INTERNAL + hasNoParent() + attributes { + "apache-camel.uri" "direct://input" + } + } + span(1) { + name "aws-s3" + kind INTERNAL + childOf span(0) + attributes { + "apache-camel.uri" "aws-s3://${bucketName}?amazonS3Client=%23s3Client" + } + } + AwsSpan.s3(it, 2, "S3.PutObject", bucketName, "PUT", span(1)) + AwsSpan.sqs(it, 3, "SQS.ReceiveMessage", queueUrl, null, CONSUMER, span(2)) + span(4) { + name queueName + kind INTERNAL + childOf span(2) + attributes { + "apache-camel.uri" "aws-sqs://${queueName}?amazonSQSClient=%23sqsClient&delay=1000" + "messaging.destination" queueName + "messaging.message_id" String + } + } + } + // HTTP "client" receiver span, one per each SQS request + trace(3, 1) { + AwsSpan.sqs(it, 0, "SQS.ReceiveMessage", queueUrl) + } + // camel polling + trace(4, 1) { + AwsSpan.sqs(it, 0, "SQS.ReceiveMessage", queueUrl) + + } + // camel cleaning received msg + trace(5, 1) { + AwsSpan.sqs(it, 0, "SQS.DeleteMessage", queueUrl) + } + } + + cleanup: + awsConnector.deleteBucket(bucketName) + awsConnector.purgeQueue(queueUrl) + camelApp.stop() + } + + def waitAndClearSetupTraces(queueUrl, queueName, bucketName) { + assertTraces(7) { + trace(0, 1) { + AwsSpan.sqs(it, 0, "SQS.CreateQueue", queueUrl, queueName) + } + trace(1, 1) { + AwsSpan.s3(it, 0, "S3.CreateBucket", bucketName, "PUT") + } + trace(2, 1) { + AwsSpan.sqs(it, 0, "SQS.GetQueueAttributes", queueUrl) + } + trace(3, 1) { + AwsSpan.sqs(it, 0, "SQS.SetQueueAttributes", queueUrl) + } + trace(4, 1) { + AwsSpan.s3(it, 0, "S3.SetBucketNotificationConfiguration", bucketName, "PUT") + } + trace(5, 1) { + AwsSpan.sqs(it, 0, "SQS.ReceiveMessage", queueUrl) + } + trace(6, 1) { + AwsSpan.sqs(it, 0, "SQS.ReceiveMessage", queueUrl, null, CONSUMER) + } + } + clearExportedData() + } +} \ No newline at end of file diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/S3Config.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/S3Config.groovy similarity index 70% rename from instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/S3Config.groovy rename to instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/S3Config.groovy index efe2057c7ada..8bf1c918b0fe 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/S3Config.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/S3Config.groovy @@ -3,13 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.apachecamel +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws -import com.amazonaws.services.s3.AmazonS3Client -import com.amazonaws.services.sns.AmazonSNSAsyncClient -import com.amazonaws.services.sns.AmazonSNSClient -import com.amazonaws.services.sqs.AmazonSQSAsyncClient -import com.amazonaws.services.sqs.AmazonSQSClient import org.apache.camel.LoggingLevel import org.apache.camel.builder.RouteBuilder import org.apache.camel.component.aws.s3.S3Constants @@ -50,21 +45,4 @@ class S3Config { } } } - - @Bean - AmazonSQSClient sqsClient() { - return AmazonSQSAsyncClient.asyncBuilder() - .build() - } - - @Bean - AmazonSNSClient snsClient() { - return AmazonSNSAsyncClient.asyncBuilder() - .build() - } - - @Bean - AmazonS3Client s3Client() { - return AmazonS3Client.builder().build() - } } diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/S3CamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SnsCamelTest.groovy similarity index 63% rename from instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/S3CamelTest.groovy rename to instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SnsCamelTest.groovy index 1827b6318cd9..3760f90b63a1 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/S3CamelTest.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SnsCamelTest.groovy @@ -3,144 +3,70 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.apachecamel +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.INTERNAL import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import org.apache.camel.CamelContext -import org.apache.camel.ProducerTemplate -import org.springframework.boot.SpringApplication import org.testcontainers.shaded.com.google.common.collect.ImmutableMap import spock.lang.Ignore import spock.lang.Shared @Ignore("Does not work with localstack - X-Ray features needed") -class S3CamelTest extends AgentInstrumentationSpecification { +class SnsCamelTest extends AgentInstrumentationSpecification { @Shared - AwsConnector awsConnector + AwsConnector awsConnector = AwsConnector.liveAws() - def setupSpec() { - awsConnector = AwsConnector.liveAws() - } - - def startCamelApp(String bucketName, String queueName) { - def app = new SpringApplication(S3Config) - app.setDefaultProperties(ImmutableMap.of("bucketName", bucketName, "queueName", queueName)) - return app.run() - } - - def "camel S3 producer - camel SQS consumer"() { + def "AWS SDK SNS producer - camel SQS consumer"() { setup: - String bucketName = "bucket-test-s3-sqs-camel" - String queueName = "s3SqsCamelTest" + String topicName = "snsCamelTest" + String queueName = "snsCamelTest" + def camelApp = new CamelSpringApp(awsConnector, SnsConfig, ImmutableMap.of("topicName", topicName, "queueName", queueName)) // setup infra String queueUrl = awsConnector.createQueue(queueName) - awsConnector.createBucket(bucketName) - - String queueArn = awsConnector.getQueueArn(queueUrl) + String queueArn = awsConnector.getQueueArn(queueName) awsConnector.setQueuePublishingPolicy(queueUrl, queueArn) - awsConnector.enableS3ToSqsNotifications(bucketName, queueArn) + String topicArn = awsConnector.createTopicAndSubscribeQueue(topicName, queueArn) // consume test message from AWS awsConnector.receiveMessage(queueUrl) // wait for setup traces - waitAndClearSetupTraces(queueUrl, queueName, bucketName) + waitAndClearSetupTraces(queueUrl, queueName) when: - def applicationContext = startCamelApp(bucketName, queueName) - def camelContext = applicationContext.getBean(CamelContext) - ProducerTemplate template = camelContext.createProducerTemplate() - template.sendBody("direct:input", "{\"type\": \"hello\"}") + camelApp.start() + awsConnector.publishSampleNotification(topicArn) then: - assertTraces(6) { - trace(0, 1) { + assertTraces(4) { + trace(0, 3) { span(0) { - name "SQS.ListQueues" + name "SNS.Publish" kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "ListQueues" - "aws.service" "AmazonSQS" + "aws.operation" "Publish" + "aws.service" "AmazonSNS" "http.flavor" "1.1" "http.method" "POST" "http.status_code" 200 "http.url" String "net.peer.name" String - "net.peer.port" { it == null || Number } + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" } } - } - trace(1, 1) { - span(0) { - name "S3.ListObjects" - kind CLIENT - hasNoParent() - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "ListObjects" - "aws.service" "Amazon S3" - "aws.bucket.name" bucketName - "http.flavor" "1.1" - "http.method" "GET" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.transport" "IP.TCP" - "net.peer.port" { it == null || Number } - } - } - } - trace(2, 5) { - span(0) { - name "input" - kind INTERNAL - hasNoParent() - attributes { - "apache-camel.uri" "direct://input" - } - } span(1) { - name "aws-s3" - kind INTERNAL - childOf span(0) - attributes { - "apache-camel.uri" "aws-s3://${bucketName}?amazonS3Client=%23s3Client" - } - } - span(2) { - name "S3.PutObject" - kind CLIENT - childOf span(1) - attributes { - "aws.agent" "java-aws-sdk" - "aws.endpoint" String - "aws.operation" "PutObject" - "aws.service" "Amazon S3" - "aws.bucket.name" bucketName - "http.flavor" "1.1" - "http.method" "PUT" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "net.peer.port" { it == null || Number } - "net.transport" "IP.TCP" - } - } - span(3) { name "SQS.ReceiveMessage" kind CONSUMER - childOf span(2) + childOf span(0) attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String @@ -153,23 +79,23 @@ class S3CamelTest extends AgentInstrumentationSpecification { "http.url" String "http.user_agent" String "net.peer.name" String - "net.peer.port" { it == null || Number } + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" } } - span(4) { - name queueName + span(2) { + name "snsCamelTest" kind INTERNAL - childOf span(2) + childOf span(0) attributes { - "apache-camel.uri" "aws-sqs://${queueName}?amazonSQSClient=%23sqsClient&delay=1000" + "apache-camel.uri" "aws-sqs://${queueName}?amazonSQSClient=%23sqsClient" "messaging.destination" queueName "messaging.message_id" String } } } - // HTTP "client" receiver span, one per each SQS request - trace(3, 1) { + // http client span + trace(1, 1) { span(0) { name "SQS.ReceiveMessage" kind CLIENT @@ -185,21 +111,20 @@ class S3CamelTest extends AgentInstrumentationSpecification { "http.status_code" 200 "http.url" String "net.peer.name" String - "net.peer.port" { it == null || Number } + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" } } } - // camel polling - trace(4, 1) { + trace(2, 1) { span(0) { - name "SQS.ReceiveMessage" + name "SQS.DeleteMessage" kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "ReceiveMessage" + "aws.operation" "DeleteMessage" "aws.queue.url" queueUrl "aws.service" "AmazonSQS" "http.flavor" "1.1" @@ -207,21 +132,21 @@ class S3CamelTest extends AgentInstrumentationSpecification { "http.status_code" 200 "http.url" String "net.peer.name" String - "net.peer.port" { it == null || Number } + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" } } } - // camel cleaning received msg - trace(5, 1) { + // camel polling + trace(3, 1) { span(0) { - name "SQS.DeleteMessage" + name "SQS.ReceiveMessage" kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "DeleteMessage" + "aws.operation" "ReceiveMessage" "aws.queue.url" queueUrl "aws.service" "AmazonSQS" "http.flavor" "1.1" @@ -229,134 +154,199 @@ class S3CamelTest extends AgentInstrumentationSpecification { "http.status_code" 200 "http.url" String "net.peer.name" String - "net.peer.port" { it == null || Number } + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" } } } } - cleanup: - awsConnector.deleteBucket(bucketName) awsConnector.purgeQueue(queueUrl) + camelApp.stop() } - def waitAndClearSetupTraces(queueUrl, queueName, bucketName) { - assertTraces(7) { + def waitAndClearSetupTraces(queueUrl, queueName) { + assertTraces(6) { trace(0, 1) { + AwsSpan.sqs(it, 0, "SQS.CreateQueue", queueUrl, queueName) + } + trace(1, 1) { + AwsSpan.sqs(it, 0, "SQS.GetQueueAttributes", queueUrl) + } + trace(2, 1) { + AwsSpan.sqs(it, 0, "SQS.SetQueueAttributes", queueUrl) + } + trace(3, 1) { span(0) { - name "SQS.CreateQueue" + name "SNS.CreateTopic" kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "CreateQueue" - "aws.queue.name" queueName - "aws.service" "AmazonSQS" + "aws.operation" "CreateTopic" + "aws.service" "AmazonSNS" "http.flavor" "1.1" "http.method" "POST" "http.status_code" 200 "http.url" String "net.peer.name" String - "net.peer.port" { it == null || Number } "net.transport" "IP.TCP" + "net.peer.port" {it == null || Number} } } } - trace(1, 1) { + trace(4, 1) { span(0) { - name "S3.CreateBucket" + name "SNS.Subscribe" kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "CreateBucket" - "aws.service" "Amazon S3" - "aws.bucket.name" bucketName + "aws.operation" "Subscribe" + "aws.service" "AmazonSNS" "http.flavor" "1.1" - "http.method" "PUT" + "http.method" "POST" "http.status_code" 200 "http.url" String "net.peer.name" String "net.transport" "IP.TCP" - "net.peer.port" { it == null || Number } + "net.peer.port" {it == null || Number} } } } - trace(2, 1) { + // test message + trace(5, 1) { + AwsSpan.sqs(it, 0, "SQS.ReceiveMessage", queueUrl) + } + } + clearExportedData() + } + + + def "camel SNS producer - camel SQS consumer"() { + setup: + String topicName = "snsCamelTest" + String queueName = "snsCamelTest" + def camelApp = new CamelSpringApp(awsConnector, SnsConfig, ImmutableMap.of("topicName", topicName, "queueName", queueName)) + + // setup infra + String queueUrl = awsConnector.createQueue(queueName) + String queueArn = awsConnector.getQueueArn(queueUrl) + awsConnector.setQueuePublishingPolicy(queueUrl, queueArn) + awsConnector.createTopicAndSubscribeQueue(topicName, queueArn) + + // consume test message from AWS + awsConnector.receiveMessage(queueUrl) + + // wait for setup traces + waitAndClearSetupTraces(queueUrl, queueName) + + when: + camelApp.start() + camelApp.producerTemplate().sendBody("direct:input", "{\"type\": \"hello\"}") + + then: + assertTraces(4) { + trace(0, 5) { + span(0) { - name "SQS.GetQueueAttributes" - kind CLIENT + name "input" + kind INTERNAL hasNoParent() + attributes { + "apache-camel.uri" "direct://input" + } + } + span(1) { + name topicName + kind INTERNAL + childOf span(0) + attributes { + "apache-camel.uri" "aws-sns://${topicName}?amazonSNSClient=%23snsClient" + "messaging.destination" topicName + } + } + span(2) { + name "SNS.Publish" + kind CLIENT + childOf span(1) attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "GetQueueAttributes" - "aws.queue.url" queueUrl - "aws.service" "AmazonSQS" + "aws.operation" "Publish" + "aws.service" "AmazonSNS" "http.flavor" "1.1" "http.method" "POST" "http.status_code" 200 "http.url" String "net.peer.name" String + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" - "net.peer.port" { it == null || Number } } } - } - trace(3, 1) { - span(0) { - name "SQS.SetQueueAttributes" - kind CLIENT - hasNoParent() + span(3) { + name "SQS.ReceiveMessage" + kind CONSUMER + childOf span(2) attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "SetQueueAttributes" + "aws.operation" "ReceiveMessage" "aws.queue.url" queueUrl "aws.service" "AmazonSQS" "http.flavor" "1.1" "http.method" "POST" "http.status_code" 200 "http.url" String + "http.user_agent" String "net.peer.name" String + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" - "net.peer.port" { it == null || Number } + } + } + span(4) { + name "snsCamelTest" + kind INTERNAL + childOf span(2) + attributes { + "apache-camel.uri" "aws-sqs://${queueName}?amazonSQSClient=%23sqsClient" + "messaging.destination" queueName + "messaging.message_id" String } } } - trace(4, 1) { + trace(1, 1) { span(0) { - name "S3.SetBucketNotificationConfiguration" + name "SQS.ReceiveMessage" kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "SetBucketNotificationConfiguration" - "aws.service" "Amazon S3" - "aws.bucket.name" bucketName + "aws.operation" "ReceiveMessage" + "aws.queue.url" queueUrl + "aws.service" "AmazonSQS" "http.flavor" "1.1" - "http.method" "PUT" + "http.method" "POST" "http.status_code" 200 "http.url" String "net.peer.name" String + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" - "net.peer.port" { it == null || Number } } } } - trace(5, 1) { + trace(2, 1) { span(0) { - name "SQS.ReceiveMessage" + name "SQS.DeleteMessage" kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" "aws.endpoint" String - "aws.operation" "ReceiveMessage" + "aws.operation" "DeleteMessage" "aws.queue.url" queueUrl "aws.service" "AmazonSQS" "http.flavor" "1.1" @@ -364,16 +354,16 @@ class S3CamelTest extends AgentInstrumentationSpecification { "http.status_code" 200 "http.url" String "net.peer.name" String + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" - "net.peer.port" { it == null || Number } } } } - // http receive span - trace(6, 1) { + // camel polling + trace(3, 1) { span(0) { name "SQS.ReceiveMessage" - kind CONSUMER + kind CLIENT hasNoParent() attributes { "aws.agent" "java-aws-sdk" @@ -385,14 +375,16 @@ class S3CamelTest extends AgentInstrumentationSpecification { "http.method" "POST" "http.status_code" 200 "http.url" String - "http.user_agent" String "net.peer.name" String + "net.peer.port" {it == null || Number} "net.transport" "IP.TCP" - "net.peer.port" { it == null || Number } } } } } - clearExportedData() + cleanup: + awsConnector.purgeQueue(queueUrl) + camelApp.stop() } -} \ No newline at end of file +} + diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SnsConfig.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SnsConfig.groovy new file mode 100644 index 000000000000..2cc633dae627 --- /dev/null +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SnsConfig.groovy @@ -0,0 +1,46 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws + + +import org.apache.camel.LoggingLevel +import org.apache.camel.builder.RouteBuilder +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.SpringBootConfiguration +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.Bean + +@SpringBootConfiguration +@EnableAutoConfiguration +class SnsConfig { + + @Bean + RouteBuilder sqsCamelOnlyConsumerRoute(@Value("\${queueName}") String queueName) { + return new RouteBuilder() { + + @Override + void configure() throws Exception { + from("aws-sqs://${queueName}?amazonSQSClient=#sqsClient&delay=1000") + .log(LoggingLevel.INFO, "test", "RECEIVER got body : \${body}") + .log(LoggingLevel.INFO, "test", "RECEIVER got headers : \${headers}") + } + } + } + + @Bean + RouteBuilder snsProducerRoute(@Value("\${topicName}") String topicName) { + return new RouteBuilder() { + + @Override + void configure() throws Exception { + from("direct:input") + .log(LoggingLevel.INFO, "test", "SENDING body: \${body}") + .log(LoggingLevel.INFO, "test", "SENDING headers: \${headers}") + .to("aws-sns://${topicName}?amazonSNSClient=#snsClient") + } + } + } +} diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SqsCamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SqsCamelTest.groovy similarity index 99% rename from instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SqsCamelTest.groovy rename to instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SqsCamelTest.groovy index 0a99b1343527..07c7822e8fbf 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SqsCamelTest.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SqsCamelTest.groovy @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.apachecamel +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CONSUMER diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SqsConfig.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SqsConfig.groovy similarity index 97% rename from instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SqsConfig.groovy rename to instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SqsConfig.groovy index 46af215fcaab..82f9014bf21b 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SqsConfig.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/SqsConfig.groovy @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.apachecamel +package io.opentelemetry.javaagent.instrumentation.apachecamel.aws import com.amazonaws.auth.AWSStaticCredentialsProvider import com.amazonaws.auth.BasicAWSCredentials