Skip to content

Commit 84f4d37

Browse files
author
Dave Syer
committed
Add Feign sample that fails to close a span
See gh-240
1 parent caba82c commit 84f4d37

File tree

6 files changed

+241
-0
lines changed

6 files changed

+241
-0
lines changed

spring-cloud-sleuth-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<module>spring-cloud-sleuth-sample-test-core</module>
2222
<module>spring-cloud-sleuth-sample-messaging</module>
2323
<module>spring-cloud-sleuth-sample-websocket</module>
24+
<module>spring-cloud-sleuth-sample-feign</module>
2425
<module>spring-cloud-sleuth-sample-ribbon</module>
2526
<module>spring-cloud-sleuth-sample-zipkin</module>
2627
<module>spring-cloud-sleuth-sample-stream</module>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- ~ Copyright 2013-2016 the original author or authors. ~ ~ Licensed under
3+
the Apache License, Version 2.0 (the "License"); ~ you may not use this file
4+
except in compliance with the License. ~ You may obtain a copy of the License
5+
at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by
6+
applicable law or agreed to in writing, software ~ distributed under the
7+
License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS
8+
OF ANY KIND, either express or implied. ~ See the License for the specific
9+
language governing permissions and ~ limitations under the License. -->
10+
11+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
13+
<modelVersion>4.0.0</modelVersion>
14+
15+
<artifactId>spring-cloud-sleuth-sample-feign</artifactId>
16+
<packaging>jar</packaging>
17+
<name>spring-cloud-sleuth-sample-feign</name>
18+
<description>Spring Cloud Sleuth Sample</description>
19+
20+
<parent>
21+
<groupId>org.springframework.cloud</groupId>
22+
<artifactId>spring-cloud-sleuth-samples</artifactId>
23+
<version>1.0.0.BUILD-SNAPSHOT</version>
24+
<relativePath>..</relativePath>
25+
</parent>
26+
27+
<properties>
28+
<sonar.skip>true</sonar.skip>
29+
</properties>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-maven-plugin</artifactId>
36+
<executions>
37+
<execution>
38+
<goals>
39+
<goal>repackage</goal>
40+
</goals>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
<plugin>
45+
<!--skip deploy -->
46+
<artifactId>maven-deploy-plugin</artifactId>
47+
<configuration>
48+
<skip>true</skip>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
54+
<dependencies>
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-starter-web</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.springframework.cloud</groupId>
61+
<artifactId>spring-cloud-starter-feign</artifactId>
62+
</dependency>
63+
<dependency>
64+
<!-- Including Eureka is a good test, even if there is no service to connect
65+
with because it exercises slightly different code paths in Ribbon -->
66+
<groupId>org.springframework.cloud</groupId>
67+
<artifactId>spring-cloud-starter-eureka</artifactId>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.springframework.cloud</groupId>
71+
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-aop</artifactId>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-starter-actuator</artifactId>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.springframework.boot</groupId>
83+
<artifactId>spring-boot-starter-test</artifactId>
84+
<scope>test</scope>
85+
</dependency>
86+
</dependencies>
87+
88+
</project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2013-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample;
18+
19+
import java.util.Random;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.cloud.netflix.feign.FeignClient;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.RequestMethod;
25+
import org.springframework.web.bind.annotation.RestController;
26+
27+
/**
28+
* @author Spencer Gibb
29+
* @author Dave Syer
30+
*/
31+
@RestController
32+
public class SampleController {
33+
34+
private Zipkin zipkin;
35+
36+
private Random random = new Random();
37+
38+
@Autowired
39+
public SampleController(Zipkin zipkin) {
40+
this.zipkin = zipkin;
41+
}
42+
43+
@RequestMapping("/")
44+
public String hi() throws InterruptedException {
45+
Thread.sleep(this.random.nextInt(1000));
46+
String s = this.zipkin.hi2();
47+
return "hi/" + s;
48+
}
49+
50+
@RequestMapping("/call")
51+
public String traced() {
52+
String s = this.zipkin.call();
53+
return "call/" + s;
54+
}
55+
56+
}
57+
58+
@FeignClient("zipkin")
59+
interface Zipkin {
60+
@RequestMapping(value = "/call", method = RequestMethod.GET)
61+
String call();
62+
63+
@RequestMapping(value = "/hi2", method = RequestMethod.GET)
64+
String hi2();
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2013-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample;
18+
19+
import org.apache.commons.logging.Log;
20+
import org.apache.commons.logging.LogFactory;
21+
import org.springframework.boot.SpringApplication;
22+
import org.springframework.boot.autoconfigure.SpringBootApplication;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
24+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
25+
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
26+
import org.springframework.context.annotation.Bean;
27+
28+
import zipkin.Span;
29+
30+
/**
31+
* @author Spencer Gibb
32+
*/
33+
@SpringBootApplication
34+
@EnableFeignClients
35+
public class SampleFeignApplication {
36+
37+
private static Log logger = LogFactory.getLog(SampleFeignApplication.class);
38+
39+
public static void main(String[] args) {
40+
SpringApplication.run(SampleFeignApplication.class, args);
41+
}
42+
43+
// Use this for debugging (or if there is no Zipkin server running on port 9411)
44+
@Bean
45+
@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
46+
public ZipkinSpanReporter spanCollector() {
47+
return new ZipkinSpanReporter() {
48+
@Override
49+
public void report(Span span) {
50+
logger.info(span);
51+
}
52+
};
53+
}
54+
55+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
server:
2+
port: 3383
3+
4+
logging.level.com.netflix.discovery: 'OFF'
5+
6+
sample:
7+
zipkin:
8+
enabled: false
9+
10+
spring:
11+
application:
12+
name: testSleuthFeign
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package sample;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.SpringApplicationConfiguration;
6+
import org.springframework.test.context.TestPropertySource;
7+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
8+
import org.springframework.test.context.web.WebAppConfiguration;
9+
10+
@RunWith(SpringJUnit4ClassRunner.class)
11+
@SpringApplicationConfiguration(classes = SampleFeignApplication.class)
12+
@WebAppConfiguration
13+
@TestPropertySource(properties="sample.zipkin.enabled=false")
14+
public class SampleFeignApplicationTests {
15+
16+
@Test
17+
public void contextLoads() {
18+
}
19+
20+
}

0 commit comments

Comments
 (0)