Package io.micrometer.observation
Class Observation.Context
java.lang.Object
io.micrometer.observation.Observation.Context
- All Implemented Interfaces:
Observation.ContextView
- Direct Known Subclasses:
ObservedAspect.ObservedAspectContext,ReceiverContext,SenderContext
- Enclosing interface:
Observation
A mutable holder of data required by an
ObservationHandler. When extended
you can provide your own, custom information to be processed by the handlers.- Since:
- 1.10.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddHighCardinalityKeyValue(io.micrometer.common.KeyValue keyValue) Adds a high cardinality key value - those will be appended to those fetched from theObservationConvention.getHighCardinalityKeyValues(Context)method.addHighCardinalityKeyValues(io.micrometer.common.KeyValues keyValues) Adds multiple high cardinality key values at once.addLowCardinalityKeyValue(io.micrometer.common.KeyValue keyValue) Adds a low cardinality key value - those will be appended to those fetched from theObservationConvention.getLowCardinalityKeyValues(Context)method.addLowCardinalityKeyValues(io.micrometer.common.KeyValues keyValues) Adds multiple low cardinality key values at once.voidclear()Clears the entries from the context.<T> TcomputeIfAbsent(Object key, Function<Object, ? extends T> mappingFunction) Returns an element or calls a mapping function if entry not present.booleancontainsKey(Object key) Checks if context contains a key.<T> TGets an entry from the context.io.micrometer.common.KeyValuesReturns all key values.Returns the contextual name.getError()Error that occurred while processing theObservation.io.micrometer.common.KeyValueReturns a high cardinality key value ornullif not present.io.micrometer.common.KeyValuesReturns high cardinality key values.io.micrometer.common.KeyValueReturns a low cardinality key value ornullif not present.io.micrometer.common.KeyValuesReturns low cardinality key values.getName()The observation name.<T> TgetOrDefault(Object key, T defaultObject) Returns an element or default if not present.Returns the parentObservationView.<T> TgetRequired(Object key) Gets an entry from the context.Puts an element to the context.Removes an entry from the context.removeHighCardinalityKeyValue(String keyName) Removes a high cardinality key value by looking at its key - those will be removed to those fetched from theObservationConvention.getHighCardinalityKeyValues(Context)method.removeHighCardinalityKeyValues(String... keyNames) Removes multiple high cardinality key values at once.removeLowCardinalityKeyValue(String keyName) Removes a low cardinality key value by looking at its key - those will be removed to those fetched from theObservationConvention.getLowCardinalityKeyValues(Context)method.removeLowCardinalityKeyValues(String... keyNames) Removes multiple low cardinality key values at once.voidsetContextualName(String contextualName) Sets the contextual name.voidSets an error that occurred while processing theObservation.voidSets the observation name.voidsetParentObservation(ObservationView parentObservation) Sets the parentObservationView.toString()
-
Constructor Details
-
Context
public Context()
-
-
Method Details
-
getName
The observation name.- Specified by:
getNamein interfaceObservation.ContextView- Returns:
- name
-
setName
Sets the observation name.- Parameters:
name- observation name
-
getContextualName
Returns the contextual name. The name that makes sense within the current context (e.g. name derived from HTTP request).- Specified by:
getContextualNamein interfaceObservation.ContextView- Returns:
- contextual name
-
setContextualName
Sets the contextual name.- Parameters:
contextualName- name
-
getParentObservation
Returns the parentObservationView.- Specified by:
getParentObservationin interfaceObservation.ContextView- Returns:
- parent observation or
nullif there was no parent
-
setParentObservation
Sets the parentObservationView.- Parameters:
parentObservation- parent observation to set
-
getError
Error that occurred while processing theObservation.- Specified by:
getErrorin interfaceObservation.ContextView- Returns:
- error (null if there wasn't any)
-
setError
Sets an error that occurred while processing theObservation.- Parameters:
error- error
-
put
Puts an element to the context.- Type Parameters:
T- value type- Parameters:
key- keyobject- value- Returns:
- this for chaining
-
get
Gets an entry from the context. Returnsnullwhen entry is not present.- Specified by:
getin interfaceObservation.ContextView- Type Parameters:
T- value type- Parameters:
key- key- Returns:
- entry or
nullif not present
-
remove
Removes an entry from the context.- Parameters:
key- key by which to remove an entry- Returns:
- the previous value associated with the key, or null if there was no mapping for the key
-
getRequired
Gets an entry from the context. Throws exception when entry is not present.- Specified by:
getRequiredin interfaceObservation.ContextView- Type Parameters:
T- value type- Parameters:
key- key- Returns:
- entry
- Throws:
IllegalArgumentException- if not present
-
containsKey
Checks if context contains a key.- Specified by:
containsKeyin interfaceObservation.ContextView- Parameters:
key- key- Returns:
truewhen the context contains the entry with the given key
-
getOrDefault
Returns an element or default if not present.- Specified by:
getOrDefaultin interfaceObservation.ContextView- Type Parameters:
T- value type- Parameters:
key- keydefaultObject- default object to return- Returns:
- object or default if not present
-
computeIfAbsent
Returns an element or calls a mapping function if entry not present. The function will insert the value to the map.- Type Parameters:
T- value type- Parameters:
key- keymappingFunction- mapping function- Returns:
- object or one derived from the mapping function if not present
-
clear
public void clear()Clears the entries from the context. -
addLowCardinalityKeyValue
Adds a low cardinality key value - those will be appended to those fetched from theObservationConvention.getLowCardinalityKeyValues(Context)method.- Parameters:
keyValue- a key value- Returns:
- this context
-
addHighCardinalityKeyValue
Adds a high cardinality key value - those will be appended to those fetched from theObservationConvention.getHighCardinalityKeyValues(Context)method.- Parameters:
keyValue- a key value- Returns:
- this context
-
removeLowCardinalityKeyValue
Removes a low cardinality key value by looking at its key - those will be removed to those fetched from theObservationConvention.getLowCardinalityKeyValues(Context)method.- Parameters:
keyName- name of the key- Returns:
- this context
- Since:
- 1.10.1
-
removeHighCardinalityKeyValue
Removes a high cardinality key value by looking at its key - those will be removed to those fetched from theObservationConvention.getHighCardinalityKeyValues(Context)method.- Parameters:
keyName- name of the key- Returns:
- this context
- Since:
- 1.10.1
-
addLowCardinalityKeyValues
Adds multiple low cardinality key values at once.- Parameters:
keyValues- collection of key values- Returns:
- this context
-
addHighCardinalityKeyValues
Adds multiple high cardinality key values at once.- Parameters:
keyValues- collection of key values- Returns:
- this context
-
removeLowCardinalityKeyValues
Removes multiple low cardinality key values at once.- Parameters:
keyNames- collection of key names- Returns:
- this context
- Since:
- 1.10.1
-
removeHighCardinalityKeyValues
Removes multiple high cardinality key values at once.- Parameters:
keyNames- collection of key names- Returns:
- this context
- Since:
- 1.10.1
-
getLowCardinalityKeyValues
@NonNull public io.micrometer.common.KeyValues getLowCardinalityKeyValues()Description copied from interface:Observation.ContextViewReturns low cardinality key values.- Specified by:
getLowCardinalityKeyValuesin interfaceObservation.ContextView- Returns:
- low cardinality key values
-
getHighCardinalityKeyValues
@NonNull public io.micrometer.common.KeyValues getHighCardinalityKeyValues()Description copied from interface:Observation.ContextViewReturns high cardinality key values.- Specified by:
getHighCardinalityKeyValuesin interfaceObservation.ContextView- Returns:
- high cardinality key values
-
getLowCardinalityKeyValue
Description copied from interface:Observation.ContextViewReturns a low cardinality key value ornullif not present.- Specified by:
getLowCardinalityKeyValuein interfaceObservation.ContextView- Parameters:
key- key- Returns:
- a low cardinality key value or
null
-
getHighCardinalityKeyValue
Description copied from interface:Observation.ContextViewReturns a high cardinality key value ornullif not present.- Specified by:
getHighCardinalityKeyValuein interfaceObservation.ContextView- Parameters:
key- key- Returns:
- a high cardinality key value or
null
-
getAllKeyValues
@NonNull public io.micrometer.common.KeyValues getAllKeyValues()Description copied from interface:Observation.ContextViewReturns all key values.- Specified by:
getAllKeyValuesin interfaceObservation.ContextView- Returns:
- all key values
-
toString
-