we recently migrated our spring boot code from version 2.1.11.RELEASE
to 3.3.5
, previously when using 2.1.11.RELEASE
we were able to print the X-Forwarded-For header value in log using spring-cloud-starter-sleuth
by adding the X-Forwarded-For in MDC context as follows:
In bootstrap.yml (2.1.11.RELEASE)
spring:
sleuth:
log:
slf4j:
whitelisted-mdc-keys: x-forwarded-for
propagation-keys: x-forwarded-for
In logback-spring.xml (2.1.11.RELEASE)
<pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %p [${springAppName},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{x-forwarded-for:-}] %c{3}:[%C{1}:%M:%L] - [%t][%file:%line] - %m%n</pattern>
As a part of migration to spring boot version 3.3.5
, same has been replaced by io.micrometer:micrometer-tracing-bridge-brave
dependency instead of spring-cloud-starter-sleuth.
In application.yml (3.3.5)
management:
tracing:
propagation:
type: b3
baggage:
correlation:
fields: x-forwarded-for
remote-fields: x-forwarded-for
In logback-spring.xml (3.3.5)
No change in in logback-spring.xml
I’m able to print all other relevant information from HTTP headers such as X-Forwarded-Host
, X-request-id
, X-real-ip
, etc. in the log by adding the field inside application.yml >> management.tracing.baggage.correlation.fields
, management.tracing.baggage.remote-fields
and correspondingly whitelisting them in logback-spring.xml >> <pattern></pattern>
.
Only challenge is I’m not able to print the X-Forwarded-For