#SpringMicroservicesLogTracing
In this example we create Zipkin server to trace all logs from microservices
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.11.5</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.11.5</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
@SpringBootApplication
@EnableZipkinServer
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
@SpringBootApplication
@RestController
public class Main {
private static final Logger LOG = Logger.getLogger(Main.class.getName());
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
@RequestMapping("/")
public String home() {
LOG.log(Level.INFO, "Creating new log");
return "Hello from microservice";
}
}
spring.application.name=zipkinserver
server.port:9411
management.metrics.web.server.auto-time-requests=false
spring.application.name=SleuthExample
spring.zipkin.baseUrl=http://localhost:9411/
spring.sleuth.sampler.probability = 1.0
If we go to: http://localhost:8080/ we can see: "Hello from microservice" message
If we go to: http://localhost:8080/home we can see: "Error type=Not Found, status=404" message