-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Add auto-configuration for Micrometer 2.0 Observation API #29666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've only taken a first pass through this so my thoughts probably aren't yet complete. Things I've spotted thus far:
If we want Boot's auto-configuration to be able to find the predicates as beans and inject them into the config, I think a dedicated interface would be better. For example, it makes it easier to identify the beans the should be injected without having to worry about generics. With regards to the composite observation handlers, what should Boot do with the 3 that it creates? I am guessing that they need to be registered with Micrometer but I didn't see that mentioned above. Apologies if I missed it. Also, what should happen with the normal, non-composite handler beans? Do they also need to be registered or should it only be the composites that are registered with Micrometer?
Generally speaking, we try to avoid having properties to disable features. I wonder if the classpath could be used as a signal instead but that would depend on the structure of the code in Micrometer. With regards to the tracing bridges, do you have a feel for the dependency management implications? I imagine that we'll want to manage the version of the Brave and OTel dependencies. Are their release schedules and approach to maintenance amenable to that? |
Makes sense micrometer-metrics/micrometer#3003
I've forgotten to put it there - I've updated the description. Yes, they will need to be registered in
That should happen for sure. The thing is that people might state that e.g. tracing is lowering performance and they want to disable just that at runtime. |
This is blocked for the same reasons as #29753. |
Hey @marcingrzejszczak, got a question about the grouping logic:
Why is this necessary? Handlers added via I imagine our code for registration something like this: private void registerHandlers(List<ObservationHandler<?>> observationHandlers, ObservationRegistry observationRegistry) {
// API is forcing us to use raw types - need to create an issue for that
List<ObservationHandler> meterHandlers = new ArrayList<>();
List<ObservationHandler> tracingHandlers = new ArrayList<>();
for (ObservationHandler<?> observationHandler : observationHandlers) {
if (observationHandler instanceof MeterObservationHandler) {
meterHandlers.add(observationHandler);
} else if (observationHandler instanceof TracingObservationHandler) {
tracingHandlers.add(observationHandler);
} else {
observationRegistry.observationConfig().observationHandler(observationHandler);
}
}
if (!meterHandlers.isEmpty()) {
observationRegistry.observationConfig().observationHandler(new FirstMatchingCompositeObservationHandler(meterHandlers));
}
if (!tracingHandlers.isEmpty()) {
observationRegistry.observationConfig().observationHandler(new FirstMatchingCompositeObservationHandler(tracingHandlers));
}
} Does that work or am I'm missing something? |
I edited your ticket and moved the changes for Micrometer Tracing in a separate issue, #30156 |
Yes, that's OK (I've forgotten to update the ticket with that suggestion). |
Thanks for confirmation. I opened an issue regarding the use of raw types (micrometer-metrics/micrometer#3064) |
- Enables timer creation for observations by calling withTimerObservationHandler on the MeterRegistry - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandler: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
I see one problem actually. Tracing might not be in the classpath. That means that if it's not then accessing the Tracing handler will lead to class not found exception |
Yes, we will handle that with some |
- Enables timer creation for observations by calling withTimerObservationHandler on the MeterRegistry - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandler: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
Hey @marcingrzejszczak, regarding the option to disable metrics and just leave tracing: Ideally, Micrometer's modules would be structured such that we can figure this out just from what's on the classpath. We don't really like having configuration options if we can avoid it. So if a user wants tracing, they include |
For further discussions on the implementation, let's please use #30186 - this makes it easier to have them in one place and I can mark them as resolved. Thanks! |
If I add |
We'll delay the merge until the 3.0.0-M2 release is done, as this depends on micrometer snapshots. |
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
3.0.0-M2 is released, no longer blocking the merge. |
Build for the PR is currently broken, as Spring Boot uses Micrometer |
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
Spring Batch now builds against micrometer |
We need to wait until all the projects in the release train build against micrometer |
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
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 thatMeterRegistry
now has aobservationConfig
configuration that allows to plug inObservationHandlers
.Required by Boot AutoConfiguration
To create an
Observation
one has to call factory methods onObservation
(start
orcreateNotStarted
). TheMeterRegistry#ObservationConfig
can have a list ofObservationPredicate
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 isAutoTimer
in Spring Boot. NowAutoTimer
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 isTimerObservationHandler
. That in turn will create aTimer
when an Observation was started and will stop it when the Observation was finished.MeterRegistry
comes with a methodwithTimerObservationHandler
that will by default create this handler. Theoretically there might be case that someone adds Micrometer but doesn't want to create aTimer
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
ObservationHandler
s. First isObservationHandler.FirstMatchingCompositeObservationHandler
. It will groupObservationHandler
s and pick the first one whosesupportsContext
method returnstrue
.Second is
ObservationHandler.AllMatchingCompositeObservationHandler
. It will groupObservationHandler
s and pick all whosesupportsContext
method returnstrue
.After having grouped the handlers they have to be injected to the
ObservationRegistry
via theObservationRegistry#observationConfig()#observationHandler
method.Required by Boot AutoConfiguration
The following rules of handler groupings should take place:
MeterObservationHandler
implementations should be automatically grouped in aObservationHandler.FirstMatchingCompositeObservationHandler
.TracingObservationHandler
implementations should be automatically grouped inObservationHandler.FirstMatchingCompositeObservationHandler
.ObservationHandler
implementations should be grouped inObservationHandler.AllMatchingCompositeObservationHandler
(without duplicates)Example:
MeterObservationHandler
bean calledMeter
coming from the frameworkTracingObservationHandler
bean calledTracing
coming from the frameworkObservationHandler
bean calledHandler
coming from the frameworkFirstMatchingCompositeObservationHandler
bean calledFirst
coming from the frameworkAllMatchingCompositeObservationHandler
bean calledAll
coming from the frameworkFirstMatchingCompositeObservationHandler
bean calledFirst from the user
coming from the userAllMatchingCompositeObservationHandler
bean calledAll from the user
coming from the userMeterObservationHandler
bean calledMeter from the user
coming from the userTracingObservationHandler
bean calledTracing from the user
coming from the userObservationHandler
bean calledHandler from the user
coming from the userWe should have the following setup of beans by Boot
FirstMatchingCompositeObservationHandler
created by Boot that groups all meter related handlersMeterObservationHandler
calledMeter
MeterObservationHandler
caledMeter from the user
(order can vary depending onOrdered
)FirstMatchingCompositeObservationHandler
created by Boot that groups all tracing related handlersTracingObservationHandler
calledTracing
TracingObservationHandler
caledTracing from the user
(order can vary depending onOrdered
)ObservationHandler
bean calledHandler
(order can vary depending onOrdered
)ObservationHandler
bean calledHandler from the user
(order can vary depending onOrdered
)FirstMatchingCompositeObservationHandler
bean calledFirst
(order can vary depending onOrdered
)FirstMatchingCompositeObservationHandler
bean calledFirst from the user
(order can vary depending onOrdered
)AllMatchingCompositeObservationHandler
bean calledAll
(order can vary depending onOrdered
)AllMatchingCompositeObservationHandler
bean 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
FirstMatchingCompositeObservationHandler
created by Boot that groups all meter related handlerssupportsContext
should returnfalse
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 runtimeFirstMatchingCompositeObservationHandler
created by Boot that groups all tracing related handlerssupportsContext
should returnfalse
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 runtimeGlobalTagsProvider
A user can provide a
GlobalTagsProvider
that can be applied to all observations. We would need Boot to autowire a list ofGlobalTagsProvider
and put them on theObservationRegistry
via theObservationRegistry.tagsProvider(...)
method.The text was updated successfully, but these errors were encountered: