Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

68 changes: 68 additions & 0 deletions opentracing-spring-cloud-api-extensions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-cloud-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>opentracing-spring-cloud-api-extensions</artifactId>

<dependencies>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-api-extensions</artifactId>
<version>${version.io.opentracing.contrib-opentracing-api-extensions}</version>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-api-extensions-tracer</artifactId>
<version>${version.io.opentracing.contrib-opentracing-api-extensions}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${version.org.springframework.boot}</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${version.commons-logging}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${version.org.awaitility-awaitility}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${version.org.springframework.boot}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${version.org.springframework.boot}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* 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.api.extensions;

import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;

import io.opentracing.Tracer;
import io.opentracing.contrib.api.TracerObserver;
import io.opentracing.contrib.api.tracer.APIExtensionsTracer;

@Configuration
public class TracerBeanPostProcessor implements BeanPostProcessor {

private static final Log log = LogFactory.getLog(TracerBeanPostProcessor.class);

@Autowired(required=false)
private Set<TracerObserver> tracerObservers;

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (tracerObservers != null && bean instanceof Tracer) {
boolean observerFound = false;
APIExtensionsTracer tracer = new APIExtensionsTracer((Tracer)bean);
for (TracerObserver observer : tracerObservers) {
if (observer != null) {
observerFound = true;
tracer.addTracerObserver(observer);
}
}
if (observerFound) {
log.info("Use extensions API tracer with observers=" + tracerObservers);
return tracer;
}
}
return bean;
}

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
io.opentracing.contrib.spring.cloud.api.extensions.TracerBeanPostProcessor
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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.api.extensions;

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.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import io.opentracing.Tracer;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.ThreadLocalActiveSpanSource;

@SpringBootTest(
classes = {TracerBeanPostProcessorNoObserversTest.SpringConfiguration.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class TracerBeanPostProcessorNoObserversTest {

@Configuration
@EnableAutoConfiguration
public static class SpringConfiguration {
@Bean
public MockTracer tracer() {
return new MockTracer(new ThreadLocalActiveSpanSource());
}
}

@Autowired
protected Tracer tracer;

@Test
public void testTracerNotWrapped() {
assertEquals(MockTracer.class, tracer.getClass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* 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.api.extensions;

import static org.junit.Assert.assertNotEquals;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
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.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import io.opentracing.Tracer;
import io.opentracing.contrib.api.SpanData;
import io.opentracing.contrib.api.TracerObserver;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.ThreadLocalActiveSpanSource;

@SpringBootTest(
classes = {TracerBeanPostProcessorTest.SpringConfiguration.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class TracerBeanPostProcessorTest {

private static final MockTracer mockTracer = new MockTracer(new ThreadLocalActiveSpanSource());

private static final TracerObserver tracerObserver = Mockito.mock(TracerObserver.class);

@Configuration
@EnableAutoConfiguration
public static class SpringConfiguration {
@Bean
public Tracer tracer() {
return mockTracer;
}

@Bean
public TracerObserver observer() {
return tracerObserver;
}
}

@Autowired
protected Tracer tracer;

@Before
public void before() {
mockTracer.reset();
}

@Test
public void testTracerWrapped() {
assertNotEquals(MockTracer.class, tracer.getClass());

tracer.buildSpan("testop").startManual();

Mockito.verify(tracerObserver).onStart(Matchers.any(SpanData.class));
}

}
89 changes: 89 additions & 0 deletions opentracing-spring-cloud-metrics-prometheus/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-cloud-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>opentracing-spring-cloud-metrics-prometheus</artifactId>

<dependencies>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-cloud-metrics</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-metrics-prometheus</artifactId>
<version>${version.io.opentracing.contrib-opentracing-metrics}</version>
<exclusions>
<exclusion>
<groupId>io.prometheus</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>${version.io.prometheus}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>${version.io.prometheus}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${version.javax.servlet-api}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-web-servlet-filter</artifactId>
<version>${version.io.opentracing.contrib-opentracing-web-servlet-filter}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${version.org.springframework.boot}</version>
</dependency>

<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${version.org.awaitility-awaitility}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${version.org.springframework.boot}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${version.org.springframework.boot}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.metrics.prometheus;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.prometheus.client.CollectorRegistry;

@Configuration
@ConditionalOnClass(value = {CollectorRegistry.class})
public class PrometheusConfiguration {

@Bean
@ConditionalOnMissingBean
public CollectorRegistry defaultCollectorRegistry() {
return CollectorRegistry.defaultRegistry;
}
}
Loading