Viraj Dhamal
Viraj Dhamal

Reputation: 5325

Add request header value in Sleuth log

I want to print request header with sleuth logs. Currently logs get printed in my spring boot microservice as given below-

2022-11-02 17:45:16.176 INFO [app-name,c9f95e8f223dca74,c9f95e8f223dca74] 35436 - [appName, traceId, spanId].

In API we are getting request header (X-B3-TraceId) that I want to print with trace id and span id. I am using spring boot 2.6.6 version and sleuth 3.1.1 version

Upvotes: 0

Views: 763

Answers (1)

xMilos
xMilos

Reputation: 2018

Add this in your application.properties

logging.pattern.level: '%clr(%5p) %clr([X-B3-TraceId=%X{traceId:-} X-B3-SpanId=%X{spanId:-} X-B3-ParentId=%X{parentId:-}]){green}'

response will be:

 INFO [X-B3-TraceId=840c9aae7060367d X-B3-SpanId=840c9aae7060367d X-B3-ParentId=]' 20912 ---

Upvotes: 1

Related Questions