Add implementation for BAEL-5317.

This commit is contained in:
Attila Uhrin 2022-01-30 10:58:44 +01:00
parent 19d7034d42
commit fc36443ae2
5 changed files with 60 additions and 4 deletions

View File

@ -39,7 +39,7 @@
</dependencies>
<properties>
<spring-cloud-sleuth.version>2.0.2.RELEASE</spring-cloud-sleuth.version>
<spring-cloud-sleuth.version>3.1.0</spring-cloud-sleuth.version>
</properties>
</project>

View File

@ -0,0 +1,11 @@
package com.baeldung.sleuth.traceid;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SleuthCurrentTraceIdApp {
public static void main(String[] args) {
SpringApplication.run(SleuthCurrentTraceIdApp.class, args);
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.sleuth.traceid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import brave.Span;
import brave.Tracer;
@RestController
public class SleuthTraceIdController {
private static final Logger logger = LoggerFactory.getLogger(SleuthTraceIdController.class);
@Autowired
private Tracer tracer;
@GetMapping("/hello")
public String hello() {
logger.info("Hello with Sleuth");
Span span = tracer.currentSpan();
if (span != null) {
logger.info("Span ID hex {}", span.context().spanIdString());
logger.info("Span ID decimal {}", span.context().spanId());
logger.info("Trace ID hex {}", span.context().traceIdString());
logger.info("Trace ID decimal {}", span.context().traceId());
}
return "hello";
}
}

View File

@ -0,0 +1,15 @@
package com.baeldung.sleuth.traceid;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SleuthCurrentTraceIdApp.class)
public class CurrentTraceIdAppSpringContextTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -1,12 +1,10 @@
package com.baeldung;
package com.baeldung.spring.session;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.session.SleuthWebApp;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SleuthWebApp.class)
public class SpringContextTest {