Merge pull request #11752 from Attila96/feature/bael-5317_current_trace_id_spring_cloud_sleuth
[BAEL-5317] Get current trace ID in Spring Cloud Sleuth
This commit is contained in:
commit
76ef4363ca
@ -39,7 +39,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<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>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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("/traceid")
|
||||||
|
public String getSleuthTraceId() {
|
||||||
|
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 from Sleuth";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user