spring-cloud-sleuth: Manually set baggage is not automatically cleaned up from MDC
I 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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 23 (18 by maintainers)
Commits related to this issue
- Adds CorrelationScopeDecorator.addDirtyName `CorrelationScopeDecorator.addDirtyName()` indicates a correlation property which could be updated without Brave knowing about it. When set, we will always... — committed to openzipkin/brave by deleted user 4 years ago
- Adds CorrelationScopeDecorator.addDirtyName (#1137) `CorrelationScopeDecorator.addDirtyName()` indicates a correlation property which could be updated without Brave knowing about it. When set, we wi... — committed to openzipkin/brave by adriancole 4 years ago
- Reorganizes code under o.s.c.sleuth.baggage This moves code and properties under org.springframework.cloud.sleuth.baggage Properties are now under "spring.sleuth.baggage" Those coming from 2.x shoul... — committed to spring-cloud/spring-cloud-sleuth by deleted user 4 years ago
- Adds CorrelationScopeDecorator.addDirtyName (#1137) `CorrelationScopeDecorator.addDirtyName()` indicates a correlation property which could be updated without Brave knowing about it. When set, we wi... — committed to thgoexpt/Java-distributed-tracing-implementation by thgoexpt 4 years ago
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.Can you check the pr I’ve created that should solve the problem?