diff --git a/.gitignore b/.gitignore index a3f50035..b9266af2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,13 @@ target # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# IntelliJ project files +.idea/ +*.iml + +# Eclipse +.project +.classpath +.settings + diff --git a/opentracing-spring-cloud-tracerresolver/pom.xml b/opentracing-spring-cloud-tracerresolver/pom.xml new file mode 100644 index 00000000..dcb6ba73 --- /dev/null +++ b/opentracing-spring-cloud-tracerresolver/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + io.opentracing.contrib + opentracing-spring-cloud-parent + 0.0.1-SNAPSHOT + + + opentracing-spring-cloud-tracerresolver + + + + io.opentracing.contrib + opentracing-tracerresolver + ${version.io.opentracing.contrib-opentracing-tracerresolver} + provided + + + + org.springframework.boot + spring-boot-autoconfigure + ${version.org.springframework.boot} + + + + io.opentracing + opentracing-mock + test + + + org.springframework.boot + spring-boot-starter-test + ${version.org.springframework.boot} + test + + + org.springframework.boot + spring-boot-starter-web + ${version.org.springframework.boot} + test + + + diff --git a/opentracing-spring-cloud-tracerresolver/src/main/java/io/opentracing/contrib/spring/cloud/tracerresolver/TracerResolverConfiguration.java b/opentracing-spring-cloud-tracerresolver/src/main/java/io/opentracing/contrib/spring/cloud/tracerresolver/TracerResolverConfiguration.java new file mode 100644 index 00000000..ca5f8acf --- /dev/null +++ b/opentracing-spring-cloud-tracerresolver/src/main/java/io/opentracing/contrib/spring/cloud/tracerresolver/TracerResolverConfiguration.java @@ -0,0 +1,31 @@ +/** + * Copyright 2017 The OpenTracing Authors + * + * Licensed 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 io.opentracing.contrib.spring.cloud.tracerresolver; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.opentracing.contrib.tracerresolver.TracerResolver; + +@Configuration +@ConditionalOnClass(value = {TracerResolver.class}) +public class TracerResolverConfiguration { + + @Bean + public io.opentracing.Tracer tracer() { + return TracerResolver.resolveTracer(); + } + +} diff --git a/opentracing-spring-cloud-tracerresolver/src/main/resources/META-INF/spring.factories b/opentracing-spring-cloud-tracerresolver/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..44067dbf --- /dev/null +++ b/opentracing-spring-cloud-tracerresolver/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +io.opentracing.contrib.spring.cloud.tracerresolver.TracerResolverConfiguration diff --git a/opentracing-spring-cloud-tracerresolver/src/test/java/io/opentracing/contrib/spring/cloud/tracerresolver/MockTracerResolver.java b/opentracing-spring-cloud-tracerresolver/src/test/java/io/opentracing/contrib/spring/cloud/tracerresolver/MockTracerResolver.java new file mode 100644 index 00000000..6e9c55e1 --- /dev/null +++ b/opentracing-spring-cloud-tracerresolver/src/test/java/io/opentracing/contrib/spring/cloud/tracerresolver/MockTracerResolver.java @@ -0,0 +1,27 @@ +/** + * Copyright 2017 The OpenTracing Authors + * + * Licensed 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 io.opentracing.contrib.spring.cloud.tracerresolver; + +import io.opentracing.Tracer; +import io.opentracing.contrib.tracerresolver.TracerResolver; +import io.opentracing.mock.MockTracer; + +public class MockTracerResolver extends TracerResolver { + + @Override + protected Tracer resolve() { + return new MockTracer(); + } + +} diff --git a/opentracing-spring-cloud-tracerresolver/src/test/java/io/opentracing/contrib/spring/cloud/tracerresolver/TracerResolverConfigurationTest.java b/opentracing-spring-cloud-tracerresolver/src/test/java/io/opentracing/contrib/spring/cloud/tracerresolver/TracerResolverConfigurationTest.java new file mode 100644 index 00000000..a8fe00c6 --- /dev/null +++ b/opentracing-spring-cloud-tracerresolver/src/test/java/io/opentracing/contrib/spring/cloud/tracerresolver/TracerResolverConfigurationTest.java @@ -0,0 +1,46 @@ +/** + * Copyright 2017 The OpenTracing Authors + * + * Licensed 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 io.opentracing.contrib.spring.cloud.tracerresolver; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import io.opentracing.Tracer; +import io.opentracing.mock.MockTracer; + +@SpringBootTest +@RunWith(SpringJUnit4ClassRunner.class) +public class TracerResolverConfigurationTest { + + @Autowired + protected Tracer tracer; + + @Configuration + @EnableAutoConfiguration + public static class SpringConfiguration { + } + + @Test + public void testTracerResolved() { + assertEquals(MockTracer.class, tracer.getClass()); + } + +} diff --git a/opentracing-spring-cloud-tracerresolver/src/test/resources/META-INF/services/io.opentracing.contrib.tracerresolver.TracerResolver b/opentracing-spring-cloud-tracerresolver/src/test/resources/META-INF/services/io.opentracing.contrib.tracerresolver.TracerResolver new file mode 100644 index 00000000..0e0a5fa2 --- /dev/null +++ b/opentracing-spring-cloud-tracerresolver/src/test/resources/META-INF/services/io.opentracing.contrib.tracerresolver.TracerResolver @@ -0,0 +1 @@ +io.opentracing.contrib.spring.cloud.tracerresolver.MockTracerResolver diff --git a/pom.xml b/pom.xml index c5a0922a..49cc0ec2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ 0.0.1-SNAPSHOT opentracing-spring-cloud + opentracing-spring-cloud-tracerresolver pom @@ -44,6 +45,7 @@ 0.30.0 0.0.6 + 0.1.0 1.4.3.RELEASE 3.0.0