From d63e21810cdc1336303ddba04955a6c4ecd50564 Mon Sep 17 00:00:00 2001 From: John Poth Date: Wed, 5 Jun 2024 15:37:19 +0200 Subject: [PATCH] CAMEL-20868: camel-aws-xray configure AWS XRay tracing out of the box --- .../camel-aws-xray-starter/pom.xml | 12 ++++ .../src/main/docs/aws-xray.json | 30 +++++++- .../starter/AwsXRayAutoConfiguration.java | 59 ++++++++++++++++ .../AwsXRayConfigurationProperties.java | 69 +++++++++++++++++++ .../starter/CamelAwsXRayTracingStrategy.java | 35 ++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 17 +++++ .../xray/starter/CamelAwsXRayCustomTest.java | 58 ++++++++++++++++ .../starter/CamelAwsXRayDisabledTest.java | 62 +++++++++++++++++ .../xray/starter/CamelAwsXRayNoopTest.java | 61 ++++++++++++++++ .../aws/xray/starter/CamelAwsXRayTest.java | 67 ++++++++++++++++++ .../starter/CustomAwsXRayTracingStrategy.java | 36 ++++++++++ .../src/test/resources/default.properties | 1 + .../src/test/resources/disabled.properties | 1 + .../src/test/resources/noop.properties | 1 + 14 files changed, 508 insertions(+), 1 deletion(-) create mode 100644 components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayAutoConfiguration.java create mode 100644 components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayConfigurationProperties.java create mode 100644 components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTracingStrategy.java create mode 100644 components-starter/camel-aws-xray-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayCustomTest.java create mode 100644 components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayDisabledTest.java create mode 100644 components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayNoopTest.java create mode 100644 components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTest.java create mode 100644 components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CustomAwsXRayTracingStrategy.java create mode 100644 components-starter/camel-aws-xray-starter/src/test/resources/default.properties create mode 100644 components-starter/camel-aws-xray-starter/src/test/resources/disabled.properties create mode 100644 components-starter/camel-aws-xray-starter/src/test/resources/noop.properties diff --git a/components-starter/camel-aws-xray-starter/pom.xml b/components-starter/camel-aws-xray-starter/pom.xml index bd8575f786e..aa6d19a2862 100644 --- a/components-starter/camel-aws-xray-starter/pom.xml +++ b/components-starter/camel-aws-xray-starter/pom.xml @@ -47,6 +47,18 @@ + + org.apache.camel + camel-test-spring-junit5 + ${camel-version} + test + + + org.apache.camel.springboot + camel-spring-boot + ${project.version} + test + org.apache.camel.springboot diff --git a/components-starter/camel-aws-xray-starter/src/main/docs/aws-xray.json b/components-starter/camel-aws-xray-starter/src/main/docs/aws-xray.json index da5f5f24116..3a1f2089d95 100644 --- a/components-starter/camel-aws-xray-starter/src/main/docs/aws-xray.json +++ b/components-starter/camel-aws-xray-starter/src/main/docs/aws-xray.json @@ -1,3 +1,31 @@ { - "properties": [] + "groups": [ + { + "name": "camel.aws-xray", + "type": "org.apache.camel.aws.xray.starter.AwsXRayConfigurationProperties", + "sourceType": "org.apache.camel.aws.xray.starter.AwsXRayConfigurationProperties" + } + ], + "properties": [ + { + "name": "camel.aws-xray.enabled", + "type": "java.lang.Boolean", + "description": "Global option to enable\/disable AWS XRay integration, default is true.", + "sourceType": "org.apache.camel.aws.xray.starter.AwsXRayConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.aws-xray.exclude-patterns", + "type": "java.util.Set", + "description": "Sets exclude pattern(s) that will disable tracing for Camel messages that matches the pattern. Multiple patterns can be separated by comma.", + "sourceType": "org.apache.camel.aws.xray.starter.AwsXRayConfigurationProperties" + }, + { + "name": "camel.aws-xray.tracing-strategy", + "type": "org.apache.camel.aws.xray.starter.AwsXRayConfigurationProperties$TracingStrategy", + "description": "Tracing strategy used. Defaults to {@link org.apache.camel.component.aws.xray.TraceAnnotatedTracingStrategy}", + "sourceType": "org.apache.camel.aws.xray.starter.AwsXRayConfigurationProperties" + } + ], + "hints": [] } \ No newline at end of file diff --git a/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayAutoConfiguration.java b/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayAutoConfiguration.java new file mode 100644 index 00000000000..b03d0225484 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayAutoConfiguration.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.aws.xray.starter; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.aws.xray.NoopTracingStrategy; +import org.apache.camel.component.aws.xray.TraceAnnotatedTracingStrategy; +import org.apache.camel.component.aws.xray.XRayTracer; +import org.apache.camel.spi.InterceptStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@EnableConfigurationProperties(AwsXRayConfigurationProperties.class) +@ConditionalOnProperty(value = "camel.aws-xray.enabled", matchIfMissing = true) +public class AwsXRayAutoConfiguration { + + @Autowired(required=false) + @CamelAwsXRayTracingStrategy + private InterceptStrategy xRayStrategy; + + @Bean + @ConditionalOnMissingBean(XRayTracer.class) + XRayTracer awsTracer(CamelContext context, + AwsXRayConfigurationProperties config) { + XRayTracer tracer = new XRayTracer(); + context.setTracing(true); + tracer.setCamelContext(context); + if(xRayStrategy != null) { + tracer.setTracingStrategy(xRayStrategy); + } else if (config.getTracingStrategy() == AwsXRayConfigurationProperties.TracingStrategy.NOOP) { + tracer.setTracingStrategy(new NoopTracingStrategy()); + } else { + // by default let's use TraceAnnotatedTracingStrategy + tracer.setTracingStrategy(new TraceAnnotatedTracingStrategy()); + } + tracer.setExcludePatterns(config.getExcludePatterns()); + tracer.init(context); + return tracer; + } +} diff --git a/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayConfigurationProperties.java b/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayConfigurationProperties.java new file mode 100644 index 00000000000..9af1e947eb4 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/AwsXRayConfigurationProperties.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.aws.xray.starter; + +import java.util.Set; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.aws-xray") +public class AwsXRayConfigurationProperties { + + /** + * Global option to enable/disable AWS XRay integration, default is true. + */ + private boolean enabled = true; + /** + * Sets exclude pattern(s) that will disable tracing for Camel messages that matches the pattern. Multiple patterns + * can be separated by comma. + */ + private Set excludePatterns; + + /** + * Tracing strategy used. Defaults to {@link org.apache.camel.component.aws.xray.TraceAnnotatedTracingStrategy} + */ + private TracingStrategy tracingStrategy = TracingStrategy.DEFAULT; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public Set getExcludePatterns() { + return excludePatterns; + } + + public void setExcludePatterns(Set excludePatterns) { + this.excludePatterns = excludePatterns; + } + + public TracingStrategy getTracingStrategy() { + return tracingStrategy; + } + + public void setTracingStrategy(TracingStrategy tracingStrategy) { + this.tracingStrategy = tracingStrategy; + } + + + public enum TracingStrategy { + DEFAULT, NOOP } + +} diff --git a/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTracingStrategy.java b/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTracingStrategy.java new file mode 100644 index 00000000000..b275e7f8f03 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/main/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTracingStrategy.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.aws.xray.starter; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.beans.factory.annotation.Qualifier; + +/** + * + * Annotate your custom AWS XRay tracing strategy. Will be used if found. Must implement {@link org.apache.camel.spi.InterceptStrategy}. + * + */ +@Target({ ElementType.TYPE, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Qualifier +public @interface CamelAwsXRayTracingStrategy { +} diff --git a/components-starter/camel-aws-xray-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/components-starter/camel-aws-xray-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000000..4ef9767aed7 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- +org.apache.camel.aws.xray.starter.AwsXRayAutoConfiguration \ No newline at end of file diff --git a/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayCustomTest.java b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayCustomTest.java new file mode 100644 index 00000000000..fbfaa72bcdc --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayCustomTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.aws.xray.starter; + +import java.util.List; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.aws.xray.XRayTracer; +import org.apache.camel.spi.InterceptStrategy; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@DirtiesContext +@CamelSpringBootTest +@SpringBootTest(classes = { CamelAutoConfiguration.class, CamelAwsXRayCustomTest.class, AwsXRayAutoConfiguration.class, CustomAwsXRayTracingStrategy.class }) +public class CamelAwsXRayCustomTest { + + @Autowired + private CamelContext context; + + @Autowired + private XRayTracer tracer; + + @Test + public void testTraceAnnotatedTracingStrategy() { + assertTrue(context.hasService(tracer)); + List interceptStrategies = context.getCamelContextExtension().getInterceptStrategies(); + boolean found = false; + for (InterceptStrategy is: interceptStrategies) { + if (is instanceof CustomAwsXRayTracingStrategy) { + found = true; + break; + } + } + assertTrue(found, "Tracing Strategy should have been added"); + } +} diff --git a/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayDisabledTest.java b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayDisabledTest.java new file mode 100644 index 00000000000..4e16b384b4c --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayDisabledTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.aws.xray.starter; + +import java.util.List; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.aws.xray.TraceAnnotatedTracingStrategy; +import org.apache.camel.component.aws.xray.XRayTracer; +import org.apache.camel.spi.InterceptStrategy; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; + +@DirtiesContext +@TestPropertySource(locations = "/disabled.properties") +@CamelSpringBootTest +@SpringBootTest(classes = { CamelAutoConfiguration.class, CamelAwsXRayDisabledTest.class, AwsXRayAutoConfiguration.class }) +public class CamelAwsXRayDisabledTest { + + @Autowired + private CamelContext context; + + @Autowired(required = false) + private XRayTracer tracer; + + @Test + public void testTraceAnnotatedTracingStrategy() { + assertNull(tracer); + List interceptStrategies = context.getCamelContextExtension().getInterceptStrategies(); + boolean found = false; + for (InterceptStrategy is: interceptStrategies) { + if (is instanceof TraceAnnotatedTracingStrategy) { + found = true; + break; + } + } + assertFalse(found, "Tracing Strategy should not have been added"); + } +} diff --git a/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayNoopTest.java b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayNoopTest.java new file mode 100644 index 00000000000..d98f338f006 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayNoopTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.aws.xray.starter; + +import java.util.List; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.aws.xray.NoopTracingStrategy; +import org.apache.camel.component.aws.xray.XRayTracer; +import org.apache.camel.spi.InterceptStrategy; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@DirtiesContext +@CamelSpringBootTest +@TestPropertySource(locations = "/noop.properties") +@SpringBootTest(classes = { CamelAutoConfiguration.class, CamelAwsXRayNoopTest.class, AwsXRayAutoConfiguration.class }) +public class CamelAwsXRayNoopTest { + + @Autowired + private CamelContext context; + + @Autowired + private XRayTracer tracer; + + @Test + public void testTraceAnnotatedTracingStrategy() { + assertTrue(context.hasService(tracer)); + List interceptStrategies = context.getCamelContextExtension().getInterceptStrategies(); + boolean found = false; + for (InterceptStrategy is: interceptStrategies) { + if (is instanceof NoopTracingStrategy) { + found = true; + break; + } + } + assertTrue(found, "Noop Tracing Strategy should have been added"); + } +} diff --git a/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTest.java b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTest.java new file mode 100644 index 00000000000..aca3ce72a0a --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CamelAwsXRayTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.aws.xray.starter; + +import java.util.List; +import java.util.Set; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.aws.xray.TraceAnnotatedTracingStrategy; +import org.apache.camel.component.aws.xray.XRayTracer; +import org.apache.camel.spi.InterceptStrategy; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@DirtiesContext +@TestPropertySource(locations = "/default.properties") +@CamelSpringBootTest +@SpringBootTest(classes = { CamelAutoConfiguration.class, CamelAwsXRayTest.class, AwsXRayAutoConfiguration.class }) +public class CamelAwsXRayTest { + + @Autowired + private CamelContext context; + + @Autowired + private XRayTracer tracer; + + @Test + public void testTraceAnnotatedTracingStrategy() { + assertTrue(context.hasService(tracer)); + Set excludePatterns = tracer.getExcludePatterns(); + assertTrue(excludePatterns.contains("excludeme")); + assertTrue(excludePatterns.contains("foobar")); + assertEquals(2, excludePatterns.size()); + List interceptStrategies = context.getCamelContextExtension().getInterceptStrategies(); + boolean found = false; + for (InterceptStrategy is: interceptStrategies) { + if (is instanceof TraceAnnotatedTracingStrategy) { + found = true; + break; + } + } + assertTrue(found, "Tracing Strategy should have been added"); + } +} diff --git a/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CustomAwsXRayTracingStrategy.java b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CustomAwsXRayTracingStrategy.java new file mode 100644 index 00000000000..37ad6e4485d --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/java/org/apache/camel/aws/xray/starter/CustomAwsXRayTracingStrategy.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.aws.xray.starter; + +import org.apache.camel.CamelContext; +import org.apache.camel.NamedNode; +import org.apache.camel.Processor; +import org.apache.camel.spi.InterceptStrategy; +import org.apache.camel.support.processor.DelegateAsyncProcessor; + +@CamelAwsXRayTracingStrategy +public class CustomAwsXRayTracingStrategy implements InterceptStrategy { + + @Override + public Processor wrapProcessorInInterceptors( + CamelContext camelContext, NamedNode processorDefinition, + Processor target, Processor nextTarget) { + // custom logic here + return new DelegateAsyncProcessor(target); + } +} diff --git a/components-starter/camel-aws-xray-starter/src/test/resources/default.properties b/components-starter/camel-aws-xray-starter/src/test/resources/default.properties new file mode 100644 index 00000000000..b4e675bb651 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/resources/default.properties @@ -0,0 +1 @@ +camel.aws-xray.exclude-patterns=excludeme,foobar \ No newline at end of file diff --git a/components-starter/camel-aws-xray-starter/src/test/resources/disabled.properties b/components-starter/camel-aws-xray-starter/src/test/resources/disabled.properties new file mode 100644 index 00000000000..69ee422be60 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/resources/disabled.properties @@ -0,0 +1 @@ +camel.aws-xray.enabled=false \ No newline at end of file diff --git a/components-starter/camel-aws-xray-starter/src/test/resources/noop.properties b/components-starter/camel-aws-xray-starter/src/test/resources/noop.properties new file mode 100644 index 00000000000..77bada1c756 --- /dev/null +++ b/components-starter/camel-aws-xray-starter/src/test/resources/noop.properties @@ -0,0 +1 @@ +camel.aws-xray.tracing-strategy=noop \ No newline at end of file