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

public Class ObservationAwareSpanThreadLocalAccessor

extends Object
implements ThreadLocalAccessor<Span>
Class Inheritance
All Implemented Interfaces
io.micrometer.context.ThreadLocalAccessor
Imports
io.micrometer.common.util.internal.logging.InternalLogger, .InternalLoggerFactory, io.micrometer.context.ContextRegistry, .ThreadLocalAccessor, io.micrometer.observation.Observation, .ObservationRegistry, io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor, io.micrometer.tracing.Span, .Tracer, io.micrometer.tracing.handler.TracingObservationHandler, java.io.Closeable, java.util.Map, .Objects, java.util.concurrent.ConcurrentHashMap

A ThreadLocalAccessor to put and restore current Span depending on whether ObservationThreadLocalAccessor did some work or not (if ObservationThreadLocalAccessor opened a scope, then this class doesn't want to create yet another span).

In essence logic of this class is as follows:

Important Note

ObservationAwareSpanThreadLocalAccessor must be registered AFTER the ObservationThreadLocalAccessor. The easiest way to achieve that is to call ContextRegistry#registerThreadLocalAccessor(ThreadLocalAccessor) manually.

Authors
Marcin Grzejszczak, Taeik Lim
Since
1.0.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
public static final String
KEY

Key under which Micrometer Tracing is being registered.

private static final InternalLogger
private final ObservationRegistry
pack-priv final Map<Thread, ObservationAwareSpanThreadLocalAccessor.SpanAction>
private final Tracer

Constructor Summary

AccessConstructor and Description
public
public
ObservationAwareSpanThreadLocalAccessor(ObservationRegistry
observationRegistry
observationRegistry
,
Tracer
tracer
tracer
)

Creates a new instance of ObservationThreadLocalAccessor.

Method Summary

Modifier and TypeMethod and Description
public Span
public Object
key()

Implements io.micrometer.context.ThreadLocalAccessor.key.

The key to associate with the ThreadLocal value when saved within a ContextSnapshot.
public void
restore(Span
previous value to set, never null when called from a ContextSnapshot * implementation, which is not allowed to store mappings to null.
previousValue
)

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

Restore the ThreadLocal at the end of a io.
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
setValue(Span
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

KEYback to summary
public static final String KEY

Key under which Micrometer Tracing is being registered.

logback to summary
private static final InternalLogger log
registryback to summary
private final ObservationRegistry registry
spanActionsback to summary
pack-priv final Map<Thread, ObservationAwareSpanThreadLocalAccessor.SpanAction> spanActions
tracerback to summary
private final Tracer tracer

Constructor Detail

ObservationAwareSpanThreadLocalAccessorback to summary
public ObservationAwareSpanThreadLocalAccessor(Tracer tracer)

Creates a new instance of ObservationThreadLocalAccessor.

Parameters
tracer:Tracer

tracer

ObservationAwareSpanThreadLocalAccessorback to summary
public ObservationAwareSpanThreadLocalAccessor(ObservationRegistry observationRegistry, Tracer tracer)

Creates a new instance of ObservationThreadLocalAccessor.

Parameters
observationRegistry:ObservationRegistry

observationRegistry

tracer:Tracer

tracer

Method Detail

getValueback to summary
public Span 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
restoreback to summary
public void restore(Span previousValue)

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
previousValue:Span

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

Annotations
@Override
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
setValueback to summary
public void setValue(Span 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:Span

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 ObservationAwareSpanThreadLocalAccessor.SpanAction

extends Object
implements AutoCloseable
Class Inheritance
  • java.lang.Object
  • io.micrometer.tracing.contextpropagation.ObservationAwareSpanThreadLocalAccessor.SpanAction
All Implemented Interfaces
java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
pack-priv final ObservationAwareSpanThreadLocalAccessor.SpanAction
pack-priv AutoCloseable
pack-priv final Map<Thread, ObservationAwareSpanThreadLocalAccessor.SpanAction>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

previousback to summary
pack-priv final ObservationAwareSpanThreadLocalAccessor.SpanAction previous
scopeback to summary
pack-priv AutoCloseable scope
todoback to summary
pack-priv final Map<Thread, ObservationAwareSpanThreadLocalAccessor.SpanAction> todo

Constructor Detail

SpanActionback to summary
pack-priv SpanAction(Map<Thread, ObservationAwareSpanThreadLocalAccessor.SpanAction> spanActions, ObservationAwareSpanThreadLocalAccessor.SpanAction previous)

Method Detail

closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
setScopeback to summary
pack-priv void setScope(Closeable scope)