Manually set baggage is not automatically cleaned up from MDC
See original GitHub issueI have configured:
spring.sleuth:
propagation-keys:
- x-session-id
log:
slf4j:
whitelisted-mdc-keys: x-session-id
If I pass this propagation key with a value to my app as HTTP header then after the request is completed it is automatically removed from MDC by Slf4jScopeDecorator.
But if I don’t pass it as header but manually set the value somewhere during processing of the request then I have to manually set it to two places:
ExtraFieldPropagation.set(continuedSpan.context(), "x-session-id", "mySession123");
MDC.put("x-session-id", "mySession123");
and I also have to create an Interceptor and manually wipe it from MDC after the request processing has completed by calling:
MDC.remove("my-key")
This is because Slf4jScopeDecorator only wipes any baggage that arrived with the request.
I propose to create a mechanism to register the value with single call (so it gets set in both to ExtraFieldPropagation and to MDC) and also after a value has been registered it would be automatically wiped from MDC after the request has completed.
Related StackOverflow post.
Issue Analytics
- State:
- Created 4 years ago
- Comments:23 (18 by maintainers)
This feature is not released yet I think.
No. sleuth cannot clear MDC. In current implementation,
previousMdc
’s key set is consist of whited list keys that have non-null value. But, if you callExtraFieldPropagation.set(key, value)
afterTraceWebFilter.filter()
, there is no value in ExtraFieldPropagation whenSlf4jScopeDecorator
decorate current span.