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,10 @@ package sample;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
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.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -28,17 +30,18 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class SampleBackground {
|
||||
private static final Log log = LogFactory.getLog(SampleBackground.class);
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private Random random;
|
||||
private Random random = new Random();
|
||||
|
||||
@Async
|
||||
public void background() throws InterruptedException {
|
||||
log.info("background");
|
||||
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
|
||||
*/
|
||||
@@ -44,8 +42,6 @@ public class SampleController
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private SpanAccessor accessor;
|
||||
@Autowired
|
||||
private SampleBackground controller;
|
||||
|
||||
private final Random random = new Random();
|
||||
@@ -53,6 +49,7 @@ public class SampleController
|
||||
|
||||
@RequestMapping("/")
|
||||
public String hi() throws InterruptedException {
|
||||
log.info("hi!");
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
|
||||
String s = this.restTemplate
|
||||
@@ -65,51 +62,55 @@ public class SampleController
|
||||
return new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
log.info("call");
|
||||
int millis = SampleController.this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis",
|
||||
SampleController.this.tracer.currentSpan().tag("callable-sleep-millis",
|
||||
String.valueOf(millis));
|
||||
Span currentSpan = SampleController.this.accessor.getCurrentSpan();
|
||||
return "async hi: " + currentSpan;
|
||||
Span span = SampleController.this.tracer.currentSpan();
|
||||
return "async hi: " + span;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String async() throws InterruptedException {
|
||||
log.info("async");
|
||||
this.controller.background();
|
||||
return "ho";
|
||||
}
|
||||
|
||||
@RequestMapping("/hi2")
|
||||
public String hi2() throws InterruptedException {
|
||||
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());
|
||||
log.info("traced");
|
||||
Span span = this.tracer.nextSpan().name("http:customTraceEndpoint");
|
||||
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;
|
||||
}
|
||||
|
||||
@RequestMapping("/start")
|
||||
public String start() throws InterruptedException {
|
||||
log.info("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);
|
||||
|
||||
@@ -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,6 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import brave.sampler.Sampler;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -26,7 +27,6 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
|
||||
@EnableAsync
|
||||
public class SampleSleuthApplication {
|
||||
|
||||
@@ -40,6 +40,11 @@ public class SampleSleuthApplication {
|
||||
return new SampleController();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Sampler sampler() {
|
||||
return Sampler.ALWAYS_SAMPLE;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleSleuthApplication.class, args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user