Top Description Inners Fields Constructors Methods
io.micrometer.tracing.contextpropagation

public Class ObservationAwareBaggageThreadLocalAccessor

extends Object
implements ThreadLocalAccessor<BaggageToPropagate>
Class Inheritance
All Implemented Interfaces
io.micrometer.context.ThreadLocalAccessor
Imports
io.micrometer.common.lang.NonNull, io.micrometer.common.util.internal.logging.InternalLogger, .InternalLoggerFactory, io.micrometer.context.ThreadLocalAccessor, io.micrometer.observation.Observation, .ObservationRegistry, io.micrometer.tracing.Baggage, .BaggageInScope, .Span, .Tracer, .Tracer.SpanInScope, io.micrometer.tracing.handler.TracingObservationHandler, java.util.Map, .Map.Entry, .Set, java.util.concurrent.ConcurrentHashMap, java.util.function.Consumer

ThreadLocalAccessor used to propagate baggage via BaggageToPropagate.
Author
Marcin Grzejszczak
Since
1.2.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv final Map<Thread, ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope>
public static final String
KEY

Key under which Micrometer Tracing Baggage accessor is being registered.

private static final InternalLogger
private final ObservationRegistry
private final Tracer

Constructor Summary

AccessConstructor and Description
public
ObservationAwareBaggageThreadLocalAccessor(ObservationRegistry
observation registry
observationRegistry
,
Tracer
tracer
tracer
)

Creates a new instance of this class.

Method Summary

Modifier and TypeMethod and Description
private static ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope
private void
private Span
getCurrentSpan(Observation currentObservation)

public BaggageToPropagate
public Object
key()

Implements io.micrometer.context.ThreadLocalAccessor.key.

The key to associate with the ThreadLocal value when saved within a ContextSnapshot.
private ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope
public void
reset()

Overrides default io.micrometer.context.ThreadLocalAccessor.reset.

Deprecated
Remove the ThreadLocal value when setting ThreadLocal values in case of missing mapping for a key() from a ContextSnapshot, or a Context object (operated upon by ContextAccessor).
public void
restore()

Overrides default io.micrometer.context.ThreadLocalAccessor.restore.

Called instead of restore(Object) when there was no ThreadLocal value existing at the start of the scope.
public void
restore(BaggageToPropagate
previous value to set, never null when called from a ContextSnapshot * implementation, which is not allowed to store mappings to null.
value
)

Overrides default io.micrometer.context.ThreadLocalAccessor.restore.

Restore the ThreadLocal at the end of a io.
private static ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope
private ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope
public void
setValue(BaggageToPropagate
the value to set, never null when called from a ContextSnapshot implementation, which is not allowed to store mappings to null.
value
)

Implements io.micrometer.context.ThreadLocalAccessor.setValue.

Set the ThreadLocal at the start of a io.
public void
setValue()

Overrides default io.micrometer.context.ThreadLocalAccessor.setValue.

Called instead of setValue(Object) in order to remove the current ThreadLocal value at the start of a io.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baggageInScopeback to summary
pack-priv final Map<Thread, ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope> baggageInScope
KEYback to summary
public static final String KEY

Key under which Micrometer Tracing Baggage accessor is being registered.

logback to summary
private static final InternalLogger log
registryback to summary
private final ObservationRegistry registry
tracerback to summary
private final Tracer tracer

Constructor Detail

ObservationAwareBaggageThreadLocalAccessorback to summary
public ObservationAwareBaggageThreadLocalAccessor(ObservationRegistry observationRegistry, Tracer tracer)

Creates a new instance of this class.

Parameters
observationRegistry:ObservationRegistry

observation registry

tracer:Tracer

tracer

Since
1.2.2

Method Detail

baggageScopeClosingScopeback to summary
private static ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope baggageScopeClosingScope(Map.Entry<String, String> entry, ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope scope, BaggageInScope baggage)
Annotations
@NonNull
closeCurrentScopeback to summary
private void closeCurrentScope()
getCurrentSpanback to summary
private Span getCurrentSpan(Observation currentObservation)
getValueback to summary
public BaggageToPropagate getValue()

Implements io.micrometer.context.ThreadLocalAccessor.getValue.

Doc from io.micrometer.context.ThreadLocalAccessor.getValue.

Return the current ThreadLocal value.

This method is called in two scenarios:

Annotations
@Override
keyback to summary
public Object key()

Implements io.micrometer.context.ThreadLocalAccessor.key.

Doc from io.micrometer.context.ThreadLocalAccessor.key.

The key to associate with the ThreadLocal value when saved within a ContextSnapshot.

Annotations
@Override
openScopeForEachBaggageEntryback to summary
private ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope openScopeForEachBaggageEntry(Set<Map.Entry<String, String>> entries, Span span, ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope scope)
resetback to summary
public void reset()

Overrides default io.micrometer.context.ThreadLocalAccessor.reset.

Doc from io.micrometer.context.ThreadLocalAccessor.reset.

Deprecated

Remove the ThreadLocal value when setting ThreadLocal values in case of missing mapping for a key() from a ContextSnapshot, or a Context object (operated upon by ContextAccessor).

Annotations
@Override
@Deprecated
restoreback to summary
public void restore()

Overrides default io.micrometer.context.ThreadLocalAccessor.restore.

Doc from io.micrometer.context.ThreadLocalAccessor.restore.

Called instead of restore(Object) when there was no ThreadLocal value existing at the start of the scope.

Annotations
@Override
restoreback to summary
public void restore(BaggageToPropagate value)

Overrides default io.micrometer.context.ThreadLocalAccessor.restore.

Doc from io.micrometer.context.ThreadLocalAccessor.restore.

Restore the ThreadLocal at the end of a io.micrometer.context.ContextSnapshot.Scope to the previous value it had before the start of the scope.

Parameters
value:BaggageToPropagate

previous value to set, never null when called from a ContextSnapshot * implementation, which is not allowed to store mappings to null.

Annotations
@Override
scopeClosingBaggageAndScopeback to summary
private static ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope scopeClosingBaggageAndScope(Map.Entry<String, String> entry, BaggageInScope baggage)
scopeRestoringBaggageAndScopeback to summary
private ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope scopeRestoringBaggageAndScope(ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope currentScope, ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope previousScope)
setValueback to summary
public void setValue(BaggageToPropagate value)

Implements io.micrometer.context.ThreadLocalAccessor.setValue.

Doc from io.micrometer.context.ThreadLocalAccessor.setValue.

Set the ThreadLocal at the start of a io.micrometer.context.ContextSnapshot.Scope to a value obtained from a ContextSnapshot or from a different type of context (through a ContextAccessor).

Parameters
value:BaggageToPropagate

the value to set, never null when called from a ContextSnapshot implementation, which is not allowed to store mappings to null.

Annotations
@Override
setValueback to summary
public void setValue()

Overrides default io.micrometer.context.ThreadLocalAccessor.setValue.

Doc from io.micrometer.context.ThreadLocalAccessor.setValue.

Called instead of setValue(Object) in order to remove the current ThreadLocal value at the start of a io.micrometer.context.ContextSnapshot.Scope.

Annotations
@Override
io.micrometer.tracing.contextpropagation back to summary

pack-priv Class ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope

extends Object
implements Consumer<Object>
Class Inheritance
  • java.lang.Object
  • io.micrometer.tracing.contextpropagation.ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope
All Implemented Interfaces
java.util.function.Consumer

Field Summary

Modifier and TypeField and Description
private final Consumer<Object>
private final Map.Entry<String, String>
private static final InternalLogger

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
accept(Object
the input argument
o
)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.
public ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope
andThen(Consumer<? super Object>
the operation to perform after this operation
after
)

Overrides default java.util.function.Consumer.andThen.

Returns a composed Consumer that performs, in sequence, this operation followed by the after operation.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

consumerback to summary
private final Consumer<Object> consumer
entryback to summary
private final Map.Entry<String, String> entry
logback to summary
private static final InternalLogger log

Constructor Detail

BaggageAndScopeback to summary
pack-priv BaggageAndScope(Consumer<Object> consumer, Map.Entry<String, String> entry)
BaggageAndScopeback to summary
pack-priv BaggageAndScope(Consumer<Object> consumer)

Method Detail

acceptback to summary
public void accept(Object o)

Implements java.util.function.Consumer.accept.

Doc from java.util.function.Consumer.accept.

Performs this operation on the given argument.

Parameters
o:Object

the input argument

Annotations
@Override
andThenback to summary
public ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope andThen(Consumer<? super Object> after)

Overrides default java.util.function.Consumer.andThen.

Doc from java.util.function.Consumer.andThen.

Returns a composed Consumer that performs, in sequence, this operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the after operation will not be performed.

Parameters
after:Consumer<? super Object>

the operation to perform after this operation

Returns:ObservationAwareBaggageThreadLocalAccessor.BaggageAndScope

a composed Consumer that performs in sequence this operation followed by the after operation

Annotations
@NonNull
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override