Search code examples
spring-cloudspring-cloud-sleuth

Adding the traceId from Spring Cloud Sleuth to response


I am currently implementing Spring Cloud Sleuth in our project. I have a requirement to add the traceId to the response headers. Is there a way that this can be achieved?

Thanks,
Anoop


Solution

  • 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.