Skip to content

Commit c4b6937

Browse files
committed
BAEL-574 adding Zipkin Span Reporters to define the URL from eureka
1 parent bebef9a commit c4b6937

6 files changed

Lines changed: 99 additions & 3 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.spring.cloud.bootstrap.gateway;
2+
3+
import com.netflix.appinfo.InstanceInfo;
4+
import com.netflix.discovery.EurekaClient;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.cloud.sleuth.metric.SpanMetricReporter;
8+
import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter;
9+
import org.springframework.cloud.sleuth.zipkin.ZipkinProperties;
10+
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
11+
import org.springframework.context.annotation.Configuration;
12+
import zipkin.Span;
13+
14+
@Configuration
15+
public class EurekaZipkinSpanReporter implements ZipkinSpanReporter {
16+
17+
@Autowired
18+
private EurekaClient eurekaClient;
19+
@Autowired
20+
private SpanMetricReporter spanMetricReporter;
21+
@Autowired
22+
private ZipkinProperties zipkinProperties;
23+
@Value("${spring.sleuth.web.skipPattern}")
24+
private String skipPattern;
25+
26+
@Override
27+
public void report(Span span) {
28+
InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false);
29+
HttpZipkinSpanReporter reporter = new HttpZipkinSpanReporter(instance.getHomePageUrl(), zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter);
30+
if (!span.name.matches(skipPattern)) reporter.report(span);
31+
}
32+
}

‎spring-cloud/spring-cloud-bootstrap/gateway/src/main/resources/bootstrap.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ zuul.routes.zipkin.sensitive-headers=Set-Cookie,Authorization
1111
hystrix.command.zipkin.execution.isolation.thread.timeoutInMilliseconds=600000
1212

1313
spring.sleuth.sampler.percentage=1.0
14-
spring.sleuth.web.skipPattern=(.+?cleanup.*|.+favicon.*)
14+
spring.sleuth.web.skipPattern=(^cleanup.*|.+favicon.*)
1515
spring.zipkin.base-url=http://zipkin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.spring.cloud.bootstrap.svcbook;
2+
3+
import com.netflix.appinfo.InstanceInfo;
4+
import com.netflix.discovery.EurekaClient;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.cloud.sleuth.metric.SpanMetricReporter;
8+
import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter;
9+
import org.springframework.cloud.sleuth.zipkin.ZipkinProperties;
10+
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
11+
import org.springframework.context.annotation.Configuration;
12+
import zipkin.Span;
13+
14+
@Configuration
15+
public class EurekaZipkinSpanReporter implements ZipkinSpanReporter {
16+
17+
@Autowired
18+
private EurekaClient eurekaClient;
19+
@Autowired
20+
private SpanMetricReporter spanMetricReporter;
21+
@Autowired
22+
private ZipkinProperties zipkinProperties;
23+
@Value("${spring.sleuth.web.skipPattern}")
24+
private String skipPattern;
25+
26+
@Override
27+
public void report(Span span) {
28+
InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false);
29+
HttpZipkinSpanReporter reporter = new HttpZipkinSpanReporter(instance.getHomePageUrl(), zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter);
30+
if (!span.name.matches(skipPattern)) reporter.report(span);
31+
}
32+
}

‎spring-cloud/spring-cloud-bootstrap/svc-book/src/main/resources/bootstrap.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ spring.cloud.config.password=configPassword
77
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/
88

99
spring.sleuth.sampler.percentage=1.0
10-
spring.zipkin.base-url=http://zipkin
10+
spring.sleuth.web.skipPattern=(^cleanup.*)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.spring.cloud.bootstrap.svcrating;
2+
3+
import com.netflix.appinfo.InstanceInfo;
4+
import com.netflix.discovery.EurekaClient;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.cloud.sleuth.metric.SpanMetricReporter;
8+
import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter;
9+
import org.springframework.cloud.sleuth.zipkin.ZipkinProperties;
10+
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
11+
import org.springframework.context.annotation.Configuration;
12+
import zipkin.Span;
13+
14+
@Configuration
15+
public class EurekaZipkinSpanReporter implements ZipkinSpanReporter {
16+
17+
@Autowired
18+
private EurekaClient eurekaClient;
19+
@Autowired
20+
private SpanMetricReporter spanMetricReporter;
21+
@Autowired
22+
private ZipkinProperties zipkinProperties;
23+
@Value("${spring.sleuth.web.skipPattern}")
24+
private String skipPattern;
25+
26+
@Override
27+
public void report(Span span) {
28+
InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false);
29+
HttpZipkinSpanReporter reporter = new HttpZipkinSpanReporter(instance.getHomePageUrl(), zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter);
30+
if (!span.name.matches(skipPattern)) reporter.report(span);
31+
}
32+
}

‎spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/resources/bootstrap.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ spring.cloud.config.password=configPassword
77
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/
88

99
spring.sleuth.sampler.percentage=1.0
10-
spring.zipkin.base-url=http://zipkin
10+
spring.sleuth.web.skipPattern=(^cleanup.*)

0 commit comments

Comments
 (0)