TraceManager -> Tracer; startSpan -> startTrace
This commit is contained in:
committed by
Marcin Grzejszczak
parent
da065504a7
commit
6b88e97b9c
@@ -18,7 +18,7 @@ package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Random;
|
||||
public class SampleBackground {
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SampleBackground {
|
||||
public void background() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
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;
|
||||
@@ -43,7 +43,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private TraceAccessor accessor;
|
||||
@Autowired
|
||||
@@ -69,7 +69,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String call() throws Exception {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
SampleController.this.traceManager.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
Span currentSpan = SampleController.this.accessor.getCurrentSpan();
|
||||
return "async hi: " + currentSpan;
|
||||
}
|
||||
@@ -87,23 +87,23 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String hi2() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
Trace trace = this.traceManager.startSpan("customTraceEndpoint",
|
||||
Trace trace = this.tracer.startTrace("customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
|
||||
Reference in New Issue
Block a user