Adding the traceId from Spring Cloud Sleuth to response

There are 2 options. One is to provide your custom extractors - http://cloud.spring.io/spring-cloud-sleuth/1.0.x/#_customizations (it will be MUCH easier with version 1.2.0). Another option (much faster) is to create your own Filter that will be registered after TraceFilter was executed and before it's closed. You can there run tracer.getCurrentSpan() and add any info you need to the response.


Using raj-kumar-bhakthavachalam example but using springframework.cloud.sleuth version 2.1.1 you may use as the following steps:

1. Autowired brave.Tracer

@Autowired
Tracer tracer

2. CurrentSpan returns TraceContext, get traceIdString

tracer.currentSpan().context().traceIdString()