Top Description Inners Fields Methods
io.micrometer.observation

public Interface Observation

extends ObservationView
Known Direct Implementers
io.micrometer.observation.SimpleObservation, io.micrometer.observation.NoopObservation
Imports
io.micrometer.common.KeyValue, .KeyValues, io.micrometer.common.lang.NonNull, .Nullable, io.micrometer.common.util.internal.logging.InternalLoggerFactory, java.util.LinkedHashMap, .Map, java.util.concurrent.Callable, .ConcurrentHashMap, java.util.function.Function, .Supplier, java.util.stream.Collectors

An act of viewing or noticing a fact or an occurrence for some scientific or other special purpose (According to dictionary.com). You can wrap an operation within your code in an Observation so that actions can take place within the lifecycle of that observation via the ObservationHandler. According to what is configured the actions can be e.g. taking measurements via Timer, creating spans for distributed tracing, correlating logs or just logging out additional information. You instrument your code once with an Observation but you can get as many benefits out of it as many ObservationHandler you have.
Authors
Jonatan Ivanov, Tommy Ludwig, Marcin Grzejszczak, Yanming Zhou
Since
1.10.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Observation.CheckedCallable<T, E extends Throwable>

A functional interface like Callable but it can throw a Throwable.

public static interface
Observation.CheckedFunction<T, R, E extends Throwable>

A functional interface like Function but it can throw a Throwable.

public static interface
Observation.CheckedRunnable<E extends Throwable>

A functional interface like Runnable but it can throw a Throwable.

public static class
Observation.Context

A mutable holder of data required by an ObservationHandler.

public static interface
Observation.ContextView

Read only view on the Context.

public static interface
Observation.Event

An arbitrary event that you can extend and signal during an Observation.

public static interface
Observation.Scope

Scope represent an action within which certain resources (e.g. tracing context) are put in scope (e.g. in a ThreadLocal).

Field Summary

Modifier and TypeField and Description
public static final Observation
NOOP

No-op observation.

Method Summary

Modifier and TypeMethod and Description
public Observation

Returns:

this
contextualName
(String
contextual name
contextualName
)

Sets the name that can be defined from the contents of the context.

public static Observation

Returns:

created but not started observation
createNotStarted
(String
name of the observation
name
,
ObservationRegistry
observation registry
registry
)

Creates but does not start an Observation.

public static <T extends Observation.Context> Observation

Returns:

created but not started observation
createNotStarted
(String
name of the observation
name
,
Supplier<T>
supplier for mutable context
contextSupplier
,
ObservationRegistry
observation registry
registry
)

Creates but does not start an Observation.

public static <
type of context
T extends Observation.Context
>
Observation

Returns:

created but not started observation
createNotStarted
(ObservationConvention<T>
custom convention. If null, the default one will be picked.
customConvention
,
ObservationConvention<T>
default convention when no custom convention was passed, nor a pre-configured one was found
defaultConvention
,
Supplier<T>
supplier for the observation context
contextSupplier
,
ObservationRegistry
observation registry
registry
)

Creates but does not start an Observation.

public static Observation

Returns:

created but not started observation
createNotStarted
(ObservationConvention<Observation.Context>
observation convention
observationConvention
,
ObservationRegistry
observation registry
registry
)

Creates but does not start an Observation.

public static <
type of context
T extends Observation.Context
>
Observation

Returns:

created but not started observation
createNotStarted
(ObservationConvention<T>
observation convention
observationConvention
,
Supplier<T>
mutable context supplier
contextSupplier
,
ObservationRegistry
observation registry
registry
)

Creates but does not start an Observation.

public Observation

Returns:

this
error
(Throwable
error
error
)

Signals an error.

public Observation

Returns:

this
event
(Observation.Event
event
event
)

Signals an arbitrary Event.

public Observation.Context

Returns:

corresponding context
getContext
()

Returns the context attached to this observation.

public default Observation.ContextView

Returns:

corresponding context
getContextView
()

Implements io.micrometer.observation.ObservationView.getContextView.

Returns the context attached to this observation as a read only view.
public Observation

Returns:

this
highCardinalityKeyValue
(KeyValue
key value
keyValue
)

Adds a high cardinality key value.

public default Observation

Returns:

this
highCardinalityKeyValue
(String
key
key
,
String
value
value
)

Adds a high cardinality key value.

public default Observation

Returns:

this
highCardinalityKeyValues
(KeyValues
key value instances
keyValues
)

Adds multiple high cardinality key value instances.

public default boolean

Returns:

true when this is a no-op observation
isNoop
()

Checks whether this Observation is no-op.

public Observation

Returns:

this
lowCardinalityKeyValue
(KeyValue
key value
keyValue
)

Adds a low cardinality key value.

public default Observation

Returns:

this
lowCardinalityKeyValue
(String
key
key
,
String
value
value
)

Adds a low cardinality key value.

public default Observation

Returns:

this
lowCardinalityKeyValues
(KeyValues
key value instances
keyValues
)

Adds multiple low cardinality key value instances.

public Observation

Returns:

this
observationConvention
(ObservationConvention<?>
observation convention
observationConvention
)

Sets an observation convention that can be used to attach key values to the observation.

public default void
observe(Runnable
the Runnable to run
runnable
)

Observes the passed Runnable, this means the followings:

  • Starts the Observation
  • Opens a Scope
  • Calls Runnable#run()
  • Closes the Scope
  • Signals the error to the Observation if any
  • Stops the Observation
public default <
the type parameter of the Supplier
T
>
T

Returns:

the result from Supplier#get()
observe
(Supplier<T>
the Supplier to call
supplier
)

Observes the passed Supplier, this means the followings:

  • Starts the Observation
  • Opens a Scope
  • Calls Supplier#get()
  • Closes the Scope
  • Signals the error to the Observation if any
  • Stops the Observation
public default <
type of exception thrown
E extends Throwable
>
void
observeChecked(Observation.CheckedRunnable<E>
the CheckedRunnable to run
checkedRunnable
)

Observes the passed CheckedRunnable, this means the followings:

  • Starts the Observation
  • Opens a Scope
  • Calls CheckedRunnable#run()
  • Closes the Scope
  • Signals the error to the Observation if any
  • Stops the Observation
public default <
the return type of the CheckedCallable
T
,
type of exception checkedCallable throws
E extends Throwable
>
T

Returns:

the result from CheckedCallable#call()
observeChecked
(Observation.CheckedCallable<T, E>
the CheckedCallable to call
checkedCallable
)

Observes the passed CheckedCallable, this means the followings:

  • Starts the Observation
  • Opens a Scope
  • Calls CheckedCallable#call()
  • Closes the Scope
  • Signals the error to the Observation if any
  • Stops the Observation
public default <
the type of input Context to the function
C extends Observation.Context
,
the type of return to the function
T
,
type of exception CheckedFunction throws
E extends Throwable
>
T

Returns:

the result from Function#apply(Object)
observeCheckedWithContext
(Observation.CheckedFunction<C, T, E>
the CheckedFunction to call
function
)

Deprecated scheduled for removal in 1.15.0, use observeChecked(...) directly
Observes the passed Function which provides access to the Context.
public default <
the type of input Context to the function
C extends Observation.Context
,
the type parameter of the Function return
T
>
T

Returns:

the result from Function#apply(Object)
observeWithContext
(Function<C, T>
the Function to call
function
)

Deprecated scheduled for removal in 1.15.0, use observe(...) directly
Observes the passed Function which provides access to the Context.
public Observation.Scope

Returns:

new scope
openScope
()

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

public Observation

Returns:

this
parentObservation
(Observation
parent observation to set
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 default void
scoped(Runnable
the Runnable to run
runnable
)

Wraps the given action in a scope and signals an error.

public default <
the return type of the Supplier
T
>
T

Returns:

the result from Supplier#get()
scoped
(Supplier<T>
the Supplier to call
supplier
)

Wraps the given action in a scope and signals an error.

public default <
type of exception thrown
E extends Throwable
>
void
scopedChecked(Observation.CheckedRunnable<E>
the CheckedRunnable to run
checkedRunnable
)

Wraps the given action in a scope and signals an error.

public default <
the return type of the CheckedCallable
T
,
type of exception checkedCallable throws
E extends Throwable
>
T

Returns:

the result from CheckedCallable#call()
scopedChecked
(Observation.CheckedCallable<T, E>
the CheckedCallable to call
checkedCallable
)

Wraps the given action in a scope and signals an error.

public static Observation

Returns:

a started observation
start
(String
name of the observation
name
,
ObservationRegistry
observation registry
registry
)

Create and start an Observation with the given name.

public static <T extends Observation.Context> Observation

Returns:

started observation
start
(String
name of the observation
name
,
Supplier<T>
mutable context supplier
contextSupplier
,
ObservationRegistry
observation registry
registry
)

Creates and starts an Observation.

public static Observation

Returns:

started observation
start
(ObservationConvention<Observation.Context>
observation convention
observationConvention
,
ObservationRegistry
observation registry
registry
)

Creates and starts an Observation.

public static <
type of context
T extends Observation.Context
>
Observation

Returns:

started observation
start
(ObservationConvention<T>
observation convention
observationConvention
,
Supplier<T>
mutable context supplier
contextSupplier
,
ObservationRegistry
observation registry
registry
)

Creates and starts an Observation.

public static <
type of context
T extends Observation.Context
>
Observation

Returns:

started observation
start
(ObservationConvention<T>
custom convention. If null, the default one will be picked.
customConvention
,
ObservationConvention<T>
default convention when no custom convention was passed, nor a configured one was found
defaultConvention
,
Supplier<T>
the observation context supplier
contextSupplier
,
ObservationRegistry
observation registry
registry
)

Creates and starts an Observation.

public Observation

Returns:

this
start
()

Starts the observation.

public void
stop()

Stop the observation.

public static void
tryScoped(Observation
observation, potentially null
parent
,
Runnable
action to run
action
)

Tries to run the action against an Observation.

public static <T> T

Returns:

result of the action
tryScoped
(Observation
observation, potentially null
parent
,
Supplier<T>
action to run
action
)

Tries to run the action against an Observation.

public static <
type of exception checkedRunnable throws
E extends Throwable
>
void
tryScopedChecked(Observation
observation, potentially null
parent
,
Observation.CheckedRunnable<E>
the CheckedRunnable to run
checkedRunnable
)

Tries to run the action against an Observation.

public static <
the return type of the CheckedCallable
T
,
type of exception checkedCallable throws
E extends Throwable
>
T

Returns:

the result from CheckedCallable#call()
tryScopedChecked
(Observation
observation, potentially null
parent
,
Observation.CheckedCallable<T, E>
the CheckedCallable to call
checkedCallable
)

Tries to run the action against an Observation.

public default Runnable
wrap(Runnable runnable)

public default <T> Supplier<T>
wrap(Supplier<T> supplier)

public default <E extends Throwable> Observation.CheckedRunnable<E>
public default <T, E extends Throwable> Observation.CheckedCallable<T, E>
wrapChecked(Observation.CheckedCallable<T, E> checkedCallable)

Inherited from io.micrometer.observation.ObservationView:
getEnclosingScopegetObservationRegistry