Class Slf4jThreadLocalAccessor
java.lang.Object
io.micrometer.context.integration.Slf4jThreadLocalAccessor
- All Implemented Interfaces:
ThreadLocalAccessor<Map<String,String>>
public class Slf4jThreadLocalAccessor
extends Object
implements ThreadLocalAccessor<Map<String,String>>
ThreadLocalAccessor for copying contents of the MDC across
Thread boundaries. It can work with selected keys only or copy the entire
contents of the MDC. It is recommended to use only when no other
ThreadLocalAccessor interacts with the MDC or the selected keys, for
instance tracing libraries.- Since:
- 1.1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey under which this accessor is registered inContextRegistry. -
Constructor Summary
ConstructorsConstructorDescriptionSlf4jThreadLocalAccessor(String... keys) Create an instance ofSlf4jThreadLocalAccessor. -
Method Summary
Modifier and TypeMethodDescriptiongetValue()Return the currentThreadLocalvalue.key()The key to associate with the ThreadLocal value when saved within aContextSnapshot.voidsetValue()Called instead ofThreadLocalAccessor.setValue(Object)in order to remove the currentThreadLocalvalue at the start of aContextSnapshot.Scope.voidSet theThreadLocalat the start of aContextSnapshot.Scopeto a value obtained from aContextSnapshotor from a different type of context (through aContextAccessor).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micrometer.context.ThreadLocalAccessor
reset, restore, restore
-
Field Details
-
KEY
Key under which this accessor is registered inContextRegistry.- See Also:
-
-
Constructor Details
-
Slf4jThreadLocalAccessor
Create an instance ofSlf4jThreadLocalAccessor.- Parameters:
keys- selected keys for which values from theMDCshould be propagated acrossThreadboundaries. If none provided, the entire contents of theMDCare propagated.
-
-
Method Details
-
key
Description copied from interface:ThreadLocalAccessorThe key to associate with the ThreadLocal value when saved within aContextSnapshot.- Specified by:
keyin interfaceThreadLocalAccessor<Map<String,String>>
-
getValue
Description copied from interface:ThreadLocalAccessorReturn the currentThreadLocalvalue.This method is called in two scenarios:
- When capturing a
ContextSnapshot. Anullvalue is ignored and theThreadLocalAccessor.key()will not be present in the snapshot. - When setting
ThreadLocalvalues from aContextSnapshotor from a Context object (through aContextAccessor) to save existing values in order toThreadLocalAccessor.restore(Object)them at the end of the scope. Anullvalue means theThreadLocalshould not be set and upon closing aContextSnapshot.Scope, theThreadLocalAccessor.restore()variant is called.
- Specified by:
getValuein interfaceThreadLocalAccessor<Map<String,String>>
- When capturing a
-
setValue
Description copied from interface:ThreadLocalAccessorSet theThreadLocalat the start of aContextSnapshot.Scopeto a value obtained from aContextSnapshotor from a different type of context (through aContextAccessor).- Specified by:
setValuein interfaceThreadLocalAccessor<Map<String,String>> - Parameters:
value- the value to set, nevernullwhen called from aContextSnapshotimplementation, which is not allowed to store mappings tonull.
-
setValue
public void setValue()Description copied from interface:ThreadLocalAccessorCalled instead ofThreadLocalAccessor.setValue(Object)in order to remove the currentThreadLocalvalue at the start of aContextSnapshot.Scope.- Specified by:
setValuein interfaceThreadLocalAccessor<Map<String,String>>
-