How to use new field (custom tag) in spring-cloud-sleuth v1.3.x with SpringBoot v1.5.3
We are building a microservices application using Spring Boot v1.5.3.RELEASE. For logging, we have used spring-cloud-sleuth-zipkin (version: Edgware.SR5/1.3.5.RELEASE). Since Spring-cloud-sleuth v2.0.0 is not compatible with SpringBoot v1.x.x, we can't use latest version of spring-cloud-sleuth.
Currently, the auto-generated TraceId is been logged for all log messages. Along with this traceId, we have to log another field ('custom-requestId') in all the log statements.
We have used below code, but in the log statements, this new field is not getting logged. Let me know if I'm missing any code for this to work?
@Autowired @Lazy private Tracer tracer; Span currentSpan = tracer.getCurrentSpan(); String newUniqueId= getNewTraceId(racfId); String baggageKey = "custom-requestId"; String baggageValue = newUniqueId; currentSpan.setBaggageItem(baggageKey, baggageValue); tracer.addTag(baggageKey, baggageValue); MDC.put(baggageKey, baggageValue); tracer.continueSpan(currentSpan); LOGGER.info(" New Field: " +baggageValue );
2018-11-08 11:21:38.422 INFO [aps-service,cb31ddeed481aef2,cb31ddeed481aef2,false] 9712 --- [nio-8090-exec-3] c.v.n.r.s.services.ApsService : New Field: K8BBJ8-80bb94ebbb1bd7be302ddef42