Changes for BAEL-1633

This commit is contained in:
Nikhil Khatwani
2018-03-20 17:38:40 +05:30
parent f17816d5e1
commit 0cc8aed509
2 changed files with 41 additions and 22 deletions

View File

@@ -3,11 +3,13 @@ package com.baeldung.spring.session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import brave.Span;
import brave.Tracer;
import brave.Tracer.SpanInScope;
@Service
public class SleuthService {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -26,12 +28,12 @@ public class SleuthService {
public void doSomeWorkNewSpan() throws InterruptedException {
logger.info("I'm in the original span");
Span newSpan = tracer.createSpan("newSpan");
try {
Span newSpan = tracer.newTrace().name("newSpan").start();
try (SpanInScope ws = tracer.withSpanInScope(newSpan.start())) {
Thread.sleep(1000L);
logger.info("I'm in the new span doing some cool work that needs its own span");
} finally {
tracer.close(newSpan);
newSpan.finish();
}
logger.info("I'm in the original span");