I am trying to run Spring Cloud Sleuth and observe traceid, span id oin logs.
I have configured as below but when i call a requesti cnat see any traceId or logId in logs.
Is there anyone help with this. Thanks.
2020-12-02 11:40:02 [main] INFO az.iba.ms.chasis.ChasisApplication - Started ChasisApplication in 21.425 seconds (JVM running for 23.816)
2020-12-02 11:40:03 [RMI TCP Connection(2)-172.31.109.104] INFO o.a.c.c.C.[.[localhost].[/chasis-ms] - Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-12-02 11:40:03 [RMI TCP Connection(2)-172.31.109.104] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
2020-12-02 11:40:03 [RMI TCP Connection(2)-172.31.109.104] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 24 ms
2020-12-02 11:40:17 [http-nio-8081-exec-1] INFO a.i.m.c.controller.ChasisController - Request {}helloChasis from chasis-ms
build.gradle
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '2.2.6.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zipkin', version: '2.2.6.RELEASE'
Controller.java
package az.iba.ms.chasis.controller;
import az.iba.ms.chasis.entity.Chasis;
import az.iba.ms.chasis.logger.MainLogger;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@RestController
@RequestMapping(value = "/v1")
@Log4j2
@Api(produces = MediaType.APPLICATION_JSON_VALUE, tags = "Chasis microservice")
public class ChasisController {
private static final MainLogger LOGGER = MainLogger.getLogger(ChasisController.class);
private static final Logger LOG = LoggerFactory.getLogger(ChasisController.class);
@Autowired
private RestTemplate restTemplate;
@ApiOperation(value = "View a list of accounts for given CIF list", response = Chasis.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully retrieved message"),
@ApiResponse(code = 404, message = "The resource is not found")}
)
@GetMapping("/hello")
public String helloChasis() {
LOG.info("Request {}" + "helloChasis from chasis-ms");
return "Greetings from Chasis";
}
}
If I need to guess, this is caused by some custom Log4J settings you have, more precisely your Log4J pattern (I don't see them so I'm just guessing). Spring Cloud Sleuth relies on log patterns that is setup by Spring Boot out of the box (see: logging config).
I suggest you to give it a try and use the default config first and if it works, you can customize the default pattern (I don't recommend customizing it, the defaults are pretty good).