Sleuth now uses Brave (#829)
with this pull request we have rewritten the whole Sleuth internals to use Brave. That way we can leverage all the functionalities & instrumentations that Brave already has (https://github.com/openzipkin/brave/tree/master/instrumentation). Migration guide is available here: https://github.com/spring-cloud/spring-cloud-sleuth/wiki/Spring-Cloud-Sleuth-2.0-Migration-Guide fixes #711 - Brave instrumentation fixes #92 - we move to Brave's Sampler fixes #143 - Brave is capable of passing context fixes #255 - we've moved away from Zipkin Stream server fixes #305 - Brave has GRPC instrumentation (https://github.com/openzipkin/brave/tree/master/instrumentation/grpc) fixes #459 - Brave (openzipkin/brave#510) & Zipkin (openzipkin/zipkin#1754) will deal with the AWS XRay instrumentation fixes #577 - Messaging instrumentation has been rewritten
This commit is contained in:
committed by
GitHub
parent
9f716d7d92
commit
7eb374b5a5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,8 @@ package sample;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import brave.Tracer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,14 +31,13 @@ public class SampleBackground {
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private Random random;
|
||||
private Random random = new Random();
|
||||
|
||||
@Async
|
||||
public void background() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.currentSpan().tag("background-sleep-millis", String.valueOf(millis));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,22 +16,20 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -46,11 +44,8 @@ ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private SpanAccessor accessor;
|
||||
@Autowired
|
||||
private SampleBackground controller;
|
||||
@Autowired
|
||||
private Random random;
|
||||
private Random random = new Random();
|
||||
private int port;
|
||||
|
||||
@RequestMapping("/")
|
||||
@@ -69,8 +64,8 @@ ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
public String call() throws Exception {
|
||||
int millis = SampleController.this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
Span currentSpan = SampleController.this.accessor.getCurrentSpan();
|
||||
Span currentSpan = SampleController.this.tracer.currentSpan();
|
||||
currentSpan.tag("callable-sleep-millis", String.valueOf(millis));
|
||||
return "async hi: " + currentSpan;
|
||||
}
|
||||
};
|
||||
@@ -88,22 +83,21 @@ ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
log.info("hi2");
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@RequestMapping("/traced")
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.createSpan("http:customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
Span span = this.tracer.nextSpan().name("http:customTraceEndpoint").start();
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info(String.format("Sleeping for [%d] millis", millis));
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
this.tracer.close(span);
|
||||
span.finish();
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@@ -112,8 +106,7 @@ ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info(String.format("Sleeping for [%d] millis", millis));
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis));
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
return "start/" + s;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,27 +16,22 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import zipkin2.Span;
|
||||
import zipkin2.reporter.Reporter;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import zipkin2.Span;
|
||||
import zipkin2.reporter.Reporter;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
|
||||
@EnableAsync
|
||||
public class SampleZipkinApplication {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SampleZipkinApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleZipkinApplication.class, args);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,10 +23,16 @@ import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import brave.sampler.Sampler;
|
||||
import integration.ZipkinTests.WaitUntilZipkinIsUpConfig;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import sample.SampleZipkinApplication;
|
||||
import tools.AbstractIntegrationTest;
|
||||
import tools.SpanUtil;
|
||||
import zipkin2.Span;
|
||||
import zipkin2.codec.SpanBytesDecoder;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -39,10 +45,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import sample.SampleZipkinApplication;
|
||||
import tools.AbstractIntegrationTest;
|
||||
import zipkin2.Span;
|
||||
import zipkin2.codec.SpanBytesDecoder;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -88,6 +90,10 @@ public class ZipkinTests extends AbstractIntegrationTest {
|
||||
zipkinProperties.setBaseUrl(zipkin.url("/").toString());
|
||||
return zipkinProperties;
|
||||
}
|
||||
|
||||
@Bean Sampler sampler() {
|
||||
return Sampler.ALWAYS_SAMPLE;
|
||||
}
|
||||
}
|
||||
|
||||
void spansSentToZipkin(MockWebServer zipkin, long traceId)
|
||||
@@ -107,7 +113,7 @@ public class ZipkinTests extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
List<String> traceIdsNotFoundInZipkin(List<Span> spans, long traceId) {
|
||||
String traceIdString = org.springframework.cloud.sleuth.Span.idToHex(traceId);
|
||||
String traceIdString = SpanUtil.idToHex(traceId);
|
||||
Optional<String> traceIds = spans.stream()
|
||||
.map(Span::traceId)
|
||||
.filter(traceIdString::equals)
|
||||
|
||||
Reference in New Issue
Block a user