Top Description Inners Fields Constructors Methods
io.micrometer.observation

pack-priv Class SimpleObservation

extends Object
implements Observation
Class Inheritance
All Implemented Interfaces
io.micrometer.observation.Observation, io.micrometer.observation.ObservationView
Known Direct Subclasses
io.micrometer.observation.NullObservation
Imports
io.micrometer.common.KeyValue, io.micrometer.common.lang.Nullable, io.micrometer.common.util.StringUtils, io.micrometer.common.util.internal.logging.InternalLogger, .InternalLoggerFactory, io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor, java.util.ArrayDeque, .Collection, .Deque, .Iterator, .Map, java.util.concurrent.ConcurrentHashMap

Default implementation of Observation.
Authors
Jonatan Ivanov, Tommy Ludwig, Marcin Grzejszczak, Yanming Zhou
Since
1.10.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final Observation.Context
private ObservationConvention<T extends Observation.Context>
private final Collection<ObservationFilter>
private final Deque<ObservationHandler<T extends Observation.Context>>
pack-priv final Map<Thread, Observation.Scope>
pack-priv final ObservationRegistry

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Observation
contextualName(String
contextual name
contextualName
)

Implements io.micrometer.observation.Observation.contextualName.

Sets the name that can be defined from the contents of the context.
public Observation
error(Throwable
error
error
)

Implements io.micrometer.observation.Observation.error.

Signals an error.
public Observation
event(Observation.Event
event
event
)

Implements io.micrometer.observation.Observation.event.

Signals an arbitrary Event.
public Observation.Context
getContext()

Implements io.micrometer.observation.Observation.getContext.

Returns the context attached to this observation.
private static ObservationConvention<T extends Observation.Context>
public Observation.Scope
getEnclosingScope()

Overrides default io.micrometer.observation.ObservationView.getEnclosingScope.

Pops the last scope attached to this ObservationView in this thread.
private static Deque<ObservationHandler<T extends Observation.Context>>
public ObservationRegistry
public Observation
highCardinalityKeyValue(KeyValue
key value
keyValue
)

Implements io.micrometer.observation.Observation.highCardinalityKeyValue.

Adds a high cardinality key value.
public Observation
lowCardinalityKeyValue(KeyValue
key value
keyValue
)

Implements io.micrometer.observation.Observation.lowCardinalityKeyValue.

Adds a low cardinality key value.
pack-priv void
pack-priv void
pack-priv void
pack-priv void
pack-priv void
pack-priv void
pack-priv void
pack-priv void
public Observation
observationConvention(ObservationConvention<?>
observation convention
convention
)

Implements io.micrometer.observation.Observation.observationConvention.

Sets an observation convention that can be used to attach key values to the observation.
public Observation.Scope
openScope()

Implements io.micrometer.observation.Observation.openScope.

When put in scope, additional operations can take place by the ObservationHandlers such as putting entries in thread local.
public Observation
parentObservation(Observation
parent observation to set
parentObservation
)

Implements io.micrometer.observation.Observation.parentObservation.

If you have access to a previously created Observation you can manually set the parent Observation using this method - that way you won't need to open scopes just to create a child observation.
public Observation
start()

Implements io.micrometer.observation.Observation.start.

Starts the observation.
public void
stop()

Implements io.micrometer.observation.Observation.stop.

Stop the observation.
public String
toString()

Overrides java.lang.Object.toString.

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

Field Detail

contextback to summary
private final Observation.Context context
conventionback to summary
private ObservationConvention<T extends Observation.Context> convention
Annotations
@Nullable
@SuppressWarnings:rawtypes
filtersback to summary
private final Collection<ObservationFilter> filters
handlersback to summary
private final Deque<ObservationHandler<T extends Observation.Context>> handlers
Annotations
@SuppressWarnings:rawtypes
lastScopeback to summary
pack-priv final Map<Thread, Observation.Scope> lastScope
registryback to summary
pack-priv final ObservationRegistry registry

Constructor Detail

SimpleObservationback to summary
pack-priv SimpleObservation(String name, ObservationRegistry registry, Observation.Context context)
SimpleObservationback to summary
pack-priv SimpleObservation(ObservationConvention<? extends Observation.Context> convention, ObservationRegistry registry, Observation.Context context)

Method Detail

contextualNameback to summary
public Observation contextualName(String contextualName)

Implements io.micrometer.observation.Observation.contextualName.

Doc from io.micrometer.observation.Observation.contextualName.

Sets the name that can be defined from the contents of the context. E.g. a span name should not be the default observation name but one coming from an HTTP request.

Parameters
contextualName:String

contextual name

Returns:Observation

this

Annotations
@Override
errorback to summary
public Observation error(Throwable error)

Implements io.micrometer.observation.Observation.error.

Doc from io.micrometer.observation.Observation.error.

Signals an error.

Parameters
error:Throwable

error

Returns:Observation

this

Annotations
@Override
eventback to summary
public Observation event(Observation.Event event)

Implements io.micrometer.observation.Observation.event.

Doc from io.micrometer.observation.Observation.event.

Signals an arbitrary Event.

Parameters
event:Observation.Event

event

Returns:Observation

this

Annotations
@Override
getContextback to summary
public Observation.Context getContext()

Implements io.micrometer.observation.Observation.getContext.

Doc from io.micrometer.observation.Observation.getContext.

Returns the context attached to this observation.

Returns:Observation.Context

corresponding context

Annotations
@Override
getConventionFromConfigback to summary
private static ObservationConvention<T extends Observation.Context> getConventionFromConfig(ObservationRegistry registry, Observation.Context context)
Annotations
@Nullable
getEnclosingScopeback to summary
public Observation.Scope getEnclosingScope()

Overrides default io.micrometer.observation.ObservationView.getEnclosingScope.

Doc from io.micrometer.observation.ObservationView.getEnclosingScope.

Pops the last scope attached to this ObservationView in this thread.

Returns:Observation.Scope

scope for this ObservationView, null if there was no scope

Annotations
@Nullable
@Override
getHandlersFromConfigback to summary
private static Deque<ObservationHandler<T extends Observation.Context>> getHandlersFromConfig(ObservationRegistry registry, Observation.Context context)
getObservationRegistryback to summary
public ObservationRegistry getObservationRegistry()

Overrides default io.micrometer.observation.ObservationView.getObservationRegistry.

Doc from io.micrometer.observation.ObservationView.getObservationRegistry.

Returns the ObservationRegistry attached to this observation.

Returns:ObservationRegistry

corresponding observation registry

Annotations
@Override
highCardinalityKeyValueback to summary
public Observation highCardinalityKeyValue(KeyValue keyValue)

Implements io.micrometer.observation.Observation.highCardinalityKeyValue.

Doc from io.micrometer.observation.Observation.highCardinalityKeyValue.

Adds a high cardinality key value. High cardinality means that this key value will have an unbounded number of possible values. An HTTP URL is a good example of such a key value (e.g. /foo/bar, /foo/baz etc.).

Parameters
keyValue:KeyValue

key value

Returns:Observation

this

Annotations
@Override
lowCardinalityKeyValueback to summary
public Observation lowCardinalityKeyValue(KeyValue keyValue)

Implements io.micrometer.observation.Observation.lowCardinalityKeyValue.

Doc from io.micrometer.observation.Observation.lowCardinalityKeyValue.

Adds a low cardinality key value. Low cardinality means that this key value will have a bounded number of possible values. A templated HTTP URL is a good example of such a key value (e.g. /foo/{userId}).

Parameters
keyValue:KeyValue

key value

Returns:Observation

this

Annotations
@Override
notifyOnErrorback to summary
pack-priv void notifyOnError()
Annotations
@SuppressWarnings:unchecked
notifyOnEventback to summary
pack-priv void notifyOnEvent(Observation.Event event)
Annotations
@SuppressWarnings:unchecked
notifyOnObservationStartedback to summary
pack-priv void notifyOnObservationStarted()
Annotations
@SuppressWarnings:unchecked
notifyOnObservationStoppedback to summary
pack-priv void notifyOnObservationStopped(Observation.Context context)
Annotations
@SuppressWarnings:unchecked
notifyOnScopeClosedback to summary
pack-priv void notifyOnScopeClosed()
Annotations
@SuppressWarnings:unchecked
notifyOnScopeMakeCurrentback to summary
pack-priv void notifyOnScopeMakeCurrent()
Annotations
@SuppressWarnings:unchecked
notifyOnScopeOpenedback to summary
pack-priv void notifyOnScopeOpened()
Annotations
@SuppressWarnings:unchecked
notifyOnScopeResetback to summary
pack-priv void notifyOnScopeReset()
Annotations
@SuppressWarnings:unchecked
observationConventionback to summary
public Observation observationConvention(ObservationConvention<?> convention)

Implements io.micrometer.observation.Observation.observationConvention.

Doc from io.micrometer.observation.Observation.observationConvention.

Sets an observation convention that can be used to attach key values to the observation. Implementations should only set the convention when it supports (see: ObservationConvention#supportsContext(Context)) the current Context.

Warning

You must set the ObservationConvention to the Observation before it is started.

Parameters
convention:ObservationConvention<?>

observation convention

Returns:Observation

this

Annotations
@Override
openScopeback to summary
public Observation.Scope openScope()

Implements io.micrometer.observation.Observation.openScope.

Doc from io.micrometer.observation.Observation.openScope.

When put in scope, additional operations can take place by the ObservationHandlers such as putting entries in thread local.

Returns:Observation.Scope

new scope

Annotations
@Override
parentObservationback to summary
public Observation parentObservation(Observation parentObservation)

Implements io.micrometer.observation.Observation.parentObservation.

Doc from io.micrometer.observation.Observation.parentObservation.

If you have access to a previously created Observation you can manually set the parent Observation using this method - that way you won't need to open scopes just to create a child observation. If you're using the openScope() method then the parent observation will be automatically set, and you don't have to call this method.

Parameters
parentObservation:Observation

parent observation to set

Returns:Observation

this

Annotations
@Override
startback to summary
public Observation start()

Implements io.micrometer.observation.Observation.start.

Doc from io.micrometer.observation.Observation.start.

Starts the observation. Remember to call this method, otherwise timing calculations will not take place.

Returns:Observation

this

Annotations
@Override
stopback to summary
public void stop()

Implements io.micrometer.observation.Observation.stop.

Doc from io.micrometer.observation.Observation.stop.

Stop the observation. Remember to call this method, otherwise timing calculations won't be finished.

Annotations
@SuppressWarnings:rawtypes, unchecked
@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
io.micrometer.observation back to summary

pack-priv Class SimpleObservation.SimpleScope

extends Object
implements Scope
Class Inheritance
All Implemented Interfaces
io.micrometer.observation.Observation.Scope, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
private final Observation
private static final InternalLogger
pack-priv final Observation.Scope
pack-priv final ObservationRegistry

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements io.micrometer.observation.Observation.Scope.close.

Clears the current scope and notifies the handlers that the scope was closed.
public Observation
getCurrentObservation()

Implements io.micrometer.observation.Observation.Scope.getCurrentObservation.

Current observation available within this scope.
private SimpleObservation.SimpleScope
public Observation.Scope
public void
public void
reset()

Implements io.micrometer.observation.Observation.Scope.reset.

Resets the current scope.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentObservationback to summary
private final Observation currentObservation
logback to summary
private static final InternalLogger log
previousObservationScopeback to summary
pack-priv final Observation.Scope previousObservationScope
Annotations
@Nullable
registryback to summary
pack-priv final ObservationRegistry registry

Constructor Detail

SimpleScopeback to summary
pack-priv SimpleScope(ObservationRegistry registry, Observation current)

Method Detail

closeback to summary
public void close()

Implements io.micrometer.observation.Observation.Scope.close.

Doc from io.micrometer.observation.Observation.Scope.close.

Clears the current scope and notifies the handlers that the scope was closed. You don't need to call this method manually. If you use try-with-resource, it will call this for you. Please only call this method if you know what you are doing and your use-case demands the usage of it.

Annotations
@Override
getCurrentObservationback to summary
public Observation getCurrentObservation()

Implements io.micrometer.observation.Observation.Scope.getCurrentObservation.

Doc from io.micrometer.observation.Observation.Scope.getCurrentObservation.

Current observation available within this scope.

Returns:Observation

current observation that this scope was created by

Annotations
@Override
getLastScopeback to summary
private SimpleObservation.SimpleScope getLastScope(SimpleObservation.SimpleScope simpleScope)
Annotations
@Nullable
getPreviousObservationScopeback to summary
public Observation.Scope getPreviousObservationScope()

Overrides default io.micrometer.observation.Observation.Scope.getPreviousObservationScope.

Doc from io.micrometer.observation.Observation.Scope.getPreviousObservationScope.

Parent scope.

Returns:Observation.Scope

previously opened scope when this one was created

Annotations
@Nullable
@Override
makeCurrentback to summary
public void makeCurrent()

Implements io.micrometer.observation.Observation.Scope.makeCurrent.

This method is called e.g. via ObservationThreadLocalAccessor#restore(Observation). In that case, we're calling ObservationThreadLocalAccessor#reset() first, and we're closing all the scopes, HOWEVER those are called on the Observation scope that was present there in thread local at the time of calling the method, NOT on the scope that we want to make current (that one can contain some leftovers from previous scope openings like creation of e.g. Brave scope in the TracingContext that is there inside the Observation's Context. When we want to go back to the enclosing scope and want to make that scope current we need to be sure that there are no remaining scoped objects inside Observation's context. This is why BEFORE rebuilding the scope structure we need to notify the handlers to clear them first (again this is a separate scope to the one that was cleared by the reset method) via calling ObservationHandler#onScopeReset(Context).

Annotations
@Override
resetback to summary
public void reset()

Implements io.micrometer.observation.Observation.Scope.reset.

Doc from io.micrometer.observation.Observation.Scope.reset.

Resets the current scope. The effect of calling this method should be clearing all related thread local entries. You don't need to call this method in most of the cases. Please only call this method if you know what you are doing and your use-case demands the usage of it.

Annotations
@Override