diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/EurekaZipkinSpanReporter.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/EurekaZipkinSpanReporter.java new file mode 100644 index 0000000000..87f9c0506c --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/EurekaZipkinSpanReporter.java @@ -0,0 +1,32 @@ +package com.baeldung.spring.cloud.bootstrap.gateway; + +import com.netflix.appinfo.InstanceInfo; +import com.netflix.discovery.EurekaClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.sleuth.metric.SpanMetricReporter; +import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter; +import org.springframework.cloud.sleuth.zipkin.ZipkinProperties; +import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter; +import org.springframework.context.annotation.Configuration; +import zipkin.Span; + +@Configuration +public class EurekaZipkinSpanReporter implements ZipkinSpanReporter { + + @Autowired + private EurekaClient eurekaClient; + @Autowired + private SpanMetricReporter spanMetricReporter; + @Autowired + private ZipkinProperties zipkinProperties; + @Value("${spring.sleuth.web.skipPattern}") + private String skipPattern; + + @Override + public void report(Span span) { + InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); + HttpZipkinSpanReporter reporter = new HttpZipkinSpanReporter(instance.getHomePageUrl(), zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + if (!span.name.matches(skipPattern)) reporter.report(span); + } +} diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/resources/bootstrap.properties index ca453e1007..5756b8205a 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/resources/bootstrap.properties +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/resources/bootstrap.properties @@ -11,5 +11,5 @@ zuul.routes.zipkin.sensitive-headers=Set-Cookie,Authorization hystrix.command.zipkin.execution.isolation.thread.timeoutInMilliseconds=600000 spring.sleuth.sampler.percentage=1.0 -spring.sleuth.web.skipPattern=(.+?cleanup.*|.+favicon.*) +spring.sleuth.web.skipPattern=(^cleanup.*|.+favicon.*) spring.zipkin.base-url=http://zipkin \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/EurekaZipkinSpanReporter.java b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/EurekaZipkinSpanReporter.java new file mode 100644 index 0000000000..96b514ca3f --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/EurekaZipkinSpanReporter.java @@ -0,0 +1,32 @@ +package com.baeldung.spring.cloud.bootstrap.svcbook; + +import com.netflix.appinfo.InstanceInfo; +import com.netflix.discovery.EurekaClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.sleuth.metric.SpanMetricReporter; +import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter; +import org.springframework.cloud.sleuth.zipkin.ZipkinProperties; +import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter; +import org.springframework.context.annotation.Configuration; +import zipkin.Span; + +@Configuration +public class EurekaZipkinSpanReporter implements ZipkinSpanReporter { + + @Autowired + private EurekaClient eurekaClient; + @Autowired + private SpanMetricReporter spanMetricReporter; + @Autowired + private ZipkinProperties zipkinProperties; + @Value("${spring.sleuth.web.skipPattern}") + private String skipPattern; + + @Override + public void report(Span span) { + InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); + HttpZipkinSpanReporter reporter = new HttpZipkinSpanReporter(instance.getHomePageUrl(), zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + if (!span.name.matches(skipPattern)) reporter.report(span); + } +} diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/resources/bootstrap.properties index e8360ecb6f..aa24cb2ab3 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/resources/bootstrap.properties +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/resources/bootstrap.properties @@ -7,4 +7,4 @@ spring.cloud.config.password=configPassword eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ spring.sleuth.sampler.percentage=1.0 -spring.zipkin.base-url=http://zipkin \ No newline at end of file +spring.sleuth.web.skipPattern=(^cleanup.*) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/EurekaZipkinSpanReporter.java b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/EurekaZipkinSpanReporter.java new file mode 100644 index 0000000000..39f9c7c96e --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/EurekaZipkinSpanReporter.java @@ -0,0 +1,32 @@ +package com.baeldung.spring.cloud.bootstrap.svcrating; + +import com.netflix.appinfo.InstanceInfo; +import com.netflix.discovery.EurekaClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.sleuth.metric.SpanMetricReporter; +import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter; +import org.springframework.cloud.sleuth.zipkin.ZipkinProperties; +import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter; +import org.springframework.context.annotation.Configuration; +import zipkin.Span; + +@Configuration +public class EurekaZipkinSpanReporter implements ZipkinSpanReporter { + + @Autowired + private EurekaClient eurekaClient; + @Autowired + private SpanMetricReporter spanMetricReporter; + @Autowired + private ZipkinProperties zipkinProperties; + @Value("${spring.sleuth.web.skipPattern}") + private String skipPattern; + + @Override + public void report(Span span) { + InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); + HttpZipkinSpanReporter reporter = new HttpZipkinSpanReporter(instance.getHomePageUrl(), zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + if (!span.name.matches(skipPattern)) reporter.report(span); + } +} diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/resources/bootstrap.properties index a43e7d76a5..ccbd6eeffe 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/resources/bootstrap.properties +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/resources/bootstrap.properties @@ -7,4 +7,4 @@ spring.cloud.config.password=configPassword eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ spring.sleuth.sampler.percentage=1.0 -spring.zipkin.base-url=http://zipkin +spring.sleuth.web.skipPattern=(^cleanup.*)