We are having three modules Gateway
using spring-cloud-gateway
, Service1
and Service2
.
Gateway call service1
and service1
calls service2
. Service1
and Service2
are using spring web flux
Gateway have 3 filters. global filter, Pre filter and post filter.
spring:
cloud:
gateway:
default-filters:
- name: GlobalFilter
routes:
id: service1
uri: http://localhost:9091/
predicates:
- Path=/service1/**
filters:
- name: PreFilter
- name: PostFilter
In global filter we are reading value from request body setting set as new baggage key.
ExtraFieldPropagation.set(tracer.currentSpan().context() ,X-CUST_TRAN_ID, transactionID);
We have also set Slueth properties like below so that it will be printed in logs as well as forwarded to next services (service1
and service2
)
sleuth:
baggage-keys:
- X-CUST_TRAN_ID
log:
slf4j:
whitelisted-mdc-keys:
- X-CUST_TRAN_ID
Problem we are facing is
X-CUST_TRAN_ID
values gets send via request and response and printed in service1
and service2
's logs but not in Gateway
itself.
It does not gets printed either in GlobalFilter
's log or in PreFilter
log statements but gets printed in PostFilters
log statements. Since CUST_TRAN_ID
is set in GlobalFilter
's filter it should get printed in log statements after set to context.
Please help is there in better way to set the field for propagation as well as printing in log statements.