Micrometer 2.0.0 changes
Micrometer 2.0.0 comes with the following changes
Observation API
The most notable change is adding the ObservationRegistry interface. MeterRegistry implements it so there wouldn't be any change there. The thing that does change is that MeterRegistry now has a observationConfig configuration that allows to plug in ObservationHandlers.
Required by Boot AutoConfiguration
To create an Observation one has to call factory methods on Observation (start or createNotStarted). The MeterRegistry#ObservationConfig can have a list of ObservationPredicate injected to define whether for given Observation name and metadata an Observation should be created or a NoOp observation should be returned. Example use case is AutoTimer in Spring Boot. Now AutoTimer is an inbuilt feature of the Observation API.
ObservationHandler
An ObservationHandler allows plugging in into the lifecycle of an Observation. That means that we can react to events such as observation was started, stopped, there was an error etc.
Micrometer comes with an interface MeterObservationHandler whose default implementation is TimerObservationHandler. That in turn will create a Timer when an Observation was started and will stop it when the Observation was finished. MeterRegistry comes with a method withTimerObservationHandler that will by default create this handler. Theoretically there might be case that someone adds Micrometer but doesn't want to create a Timer when an Observation is created.
Micrometer Tracing comes with an interface TracingObservationHandler that contains additional logic for tracing related handlers.
Micrometer comes with 2 additional interfaces that group ObservationHandlers. First is ObservationHandler.FirstMatchingCompositeObservationHandler . It will group ObservationHandlers and pick the first one whose supportsContext method returns true.
Second is ObservationHandler.AllMatchingCompositeObservationHandler. It will group ObservationHandlers and pick all whose supportsContext method returns true.
After having grouped the handlers they have to be injected to the ObservationRegistry via the ObservationRegistry#observationConfig()#observationHandler method.
Required by Boot AutoConfiguration
The following rules of handler groupings should take place:
- All
MeterObservationHandler implementations should be automatically grouped in a ObservationHandler.FirstMatchingCompositeObservationHandler.
- All
TracingObservationHandler implementations should be automatically grouped in ObservationHandler.FirstMatchingCompositeObservationHandler.
- All
ObservationHandler implementations should be grouped in ObservationHandler.AllMatchingCompositeObservationHandler (without duplicates)
Example:
- We have a
MeterObservationHandler bean called Meter coming from the framework
- We have a
TracingObservationHandler bean called Tracing coming from the framework
- We have a
ObservationHandler bean called Handler coming from the framework
- We have a
FirstMatchingCompositeObservationHandler bean called First coming from the framework
- We have a
AllMatchingCompositeObservationHandler bean called All coming from the framework
- We have a
FirstMatchingCompositeObservationHandler bean called First from the user coming from the user
- We have a
AllMatchingCompositeObservationHandler bean called All from the user coming from the user
- We have a
MeterObservationHandler bean called Meter from the user coming from the user
- We have a
TracingObservationHandler bean called Tracing from the user coming from the user
- We have a
ObservationHandler bean called Handler from the user coming from the user
We should have the following setup of beans by Boot
FirstMatchingCompositeObservationHandler created by Boot that groups all meter related handlers
MeterObservationHandler called Meter
MeterObservationHandler caled Meter from the user (order can vary depending on Ordered)
FirstMatchingCompositeObservationHandler created by Boot that groups all tracing related handlers
TracingObservationHandler called Tracing
TracingObservationHandler caled Tracing from the user (order can vary depending on Ordered)
ObservationHandler bean called Handler (order can vary depending on Ordered)
ObservationHandler bean called Handler from the user (order can vary depending on Ordered)
FirstMatchingCompositeObservationHandler bean called First (order can vary depending on Ordered)
FirstMatchingCompositeObservationHandler bean called First from the user (order can vary depending on Ordered)
AllMatchingCompositeObservationHandler bean called All (order can vary depending on Ordered)
AllMatchingCompositeObservationHandler bean called All from the user (order can vary depending on Ordered)
ObservationRegistry.observationConfig().observationHandler() will be called to register the beans presented above.
Following conditionals have to be applicable
- When this feature is disabled (no Micrometer on the classpath / a property is explicitly disabled) nothing is created
FirstMatchingCompositeObservationHandler created by Boot that groups all meter related handlers
supportsContext should return false when a property to disable metrics is turned on (Micrometer on the classpath / a property for metrics enabling is explicitly disabled) - we can toggle this on and off at runtime
FirstMatchingCompositeObservationHandler created by Boot that groups all tracing related handlers
- should not be created when Micrometer Tracing is not on the classpath
supportsContext should return false when a property to disable tracing is turned on (Micrometer & Micrometer Tracing on the classpath / a property for tracing enabling is explicitly disabled) - we can toggle this on and off at runtime
GlobalTagsProvider
A user can provide a GlobalTagsProvider that can be applied to all observations. We would need Boot to autowire a list of GlobalTagsProvider and put them on the ObservationRegistry via the ObservationRegistry.tagsProvider(...) method.
Micrometer 2.0.0 changes
Micrometer 2.0.0 comes with the following changes
Observation API
The most notable change is adding the
ObservationRegistryinterface.MeterRegistryimplements it so there wouldn't be any change there. The thing that does change is thatMeterRegistrynow has aobservationConfigconfiguration that allows to plug inObservationHandlers.Required by Boot AutoConfiguration
To create an
Observationone has to call factory methods onObservation(startorcreateNotStarted). TheMeterRegistry#ObservationConfigcan have a list ofObservationPredicateinjected to define whether for given Observation name and metadata an Observation should be created or a NoOp observation should be returned. Example use case isAutoTimerin Spring Boot. NowAutoTimeris an inbuilt feature of the Observation API.ObservationHandlerAn
ObservationHandlerallows plugging in into the lifecycle of an Observation. That means that we can react to events such as observation was started, stopped, there was an error etc.Micrometer comes with an interface
MeterObservationHandlerwhose default implementation isTimerObservationHandler. That in turn will create aTimerwhen an Observation was started and will stop it when the Observation was finished.MeterRegistrycomes with a methodwithTimerObservationHandlerthat will by default create this handler. Theoretically there might be case that someone adds Micrometer but doesn't want to create aTimerwhen an Observation is created.Micrometer Tracing comes with an interface
TracingObservationHandlerthat contains additional logic for tracing related handlers.Micrometer comes with 2 additional interfaces that group
ObservationHandlers. First isObservationHandler.FirstMatchingCompositeObservationHandler. It will groupObservationHandlers and pick the first one whosesupportsContextmethod returnstrue.Second is
ObservationHandler.AllMatchingCompositeObservationHandler. It will groupObservationHandlers and pick all whosesupportsContextmethod returnstrue.After having grouped the handlers they have to be injected to the
ObservationRegistryvia theObservationRegistry#observationConfig()#observationHandlermethod.Required by Boot AutoConfiguration
The following rules of handler groupings should take place:
MeterObservationHandlerimplementations should be automatically grouped in aObservationHandler.FirstMatchingCompositeObservationHandler.TracingObservationHandlerimplementations should be automatically grouped inObservationHandler.FirstMatchingCompositeObservationHandler.ObservationHandlerimplementations should be grouped inObservationHandler.AllMatchingCompositeObservationHandler(without duplicates)Example:
MeterObservationHandlerbean calledMetercoming from the frameworkTracingObservationHandlerbean calledTracingcoming from the frameworkObservationHandlerbean calledHandlercoming from the frameworkFirstMatchingCompositeObservationHandlerbean calledFirstcoming from the frameworkAllMatchingCompositeObservationHandlerbean calledAllcoming from the frameworkFirstMatchingCompositeObservationHandlerbean calledFirst from the usercoming from the userAllMatchingCompositeObservationHandlerbean calledAll from the usercoming from the userMeterObservationHandlerbean calledMeter from the usercoming from the userTracingObservationHandlerbean calledTracing from the usercoming from the userObservationHandlerbean calledHandler from the usercoming from the userWe should have the following setup of beans by Boot
FirstMatchingCompositeObservationHandlercreated by Boot that groups all meter related handlersMeterObservationHandlercalledMeterMeterObservationHandlercaledMeter from the user(order can vary depending onOrdered)FirstMatchingCompositeObservationHandlercreated by Boot that groups all tracing related handlersTracingObservationHandlercalledTracingTracingObservationHandlercaledTracing from the user(order can vary depending onOrdered)ObservationHandlerbean calledHandler(order can vary depending onOrdered)ObservationHandlerbean calledHandler from the user(order can vary depending onOrdered)FirstMatchingCompositeObservationHandlerbean calledFirst(order can vary depending onOrdered)FirstMatchingCompositeObservationHandlerbean calledFirst from the user(order can vary depending onOrdered)AllMatchingCompositeObservationHandlerbean calledAll(order can vary depending onOrdered)AllMatchingCompositeObservationHandlerbean calledAll from the user(order can vary depending onOrdered)ObservationRegistry.observationConfig().observationHandler()will be called to register the beans presented above.Following conditionals have to be applicable
FirstMatchingCompositeObservationHandlercreated by Boot that groups all meter related handlerssupportsContextshould returnfalsewhen a property to disable metrics is turned on (Micrometer on the classpath / a property for metrics enabling is explicitly disabled) - we can toggle this on and off at runtimeFirstMatchingCompositeObservationHandlercreated by Boot that groups all tracing related handlerssupportsContextshould returnfalsewhen a property to disable tracing is turned on (Micrometer & Micrometer Tracing on the classpath / a property for tracing enabling is explicitly disabled) - we can toggle this on and off at runtimeGlobalTagsProvider
A user can provide a
GlobalTagsProviderthat can be applied to all observations. We would need Boot to autowire a list ofGlobalTagsProviderand put them on theObservationRegistryvia theObservationRegistry.tagsProvider(...)method.