-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Allow custom ScheduledTaskObservationConvention in ScheduledMethodRunnable #32563
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
Thanks for the report @hadjiski - I will look into this. I agree that we are not consistent with allowing custom conventions locally, but this can be harder to achieve depending on how deep the integration is and how is it is to surface such an option into the configuration.
To me the package io.spring.sample
import io.micrometer.common.KeyValue;
import io.micrometer.observation.GlobalObservationConvention;
import org.springframework.scheduling.support.DefaultScheduledTaskObservationConvention;
import org.springframework.scheduling.support.ScheduledTaskObservationContext;
public class CustomScheduledTaskObservationConvention extends DefaultScheduledTaskObservationConvention
implements GlobalObservationConvention<ScheduledTaskObservationContext> {
@Override
protected KeyValue codeFunction(ScheduledTaskObservationContext context) {
return super.codeFunction(context);
}
} |
Thank you @bclozel for the fast reply, I was so back and forth between all the ways to utilize the observations and their customizations, that I mixed it with the situation around the Btw. how am I supposed to propagate business data from outside to the current observation resp. the provided context, so I can use it in the above overridden customized method to take some decisions. Explaining the solution for http.server.requests in more details:
Though the |
@hadjiski getting the current observation from within the scheduled method should work, we have an integration test that verifies that. If you can reproduce the problem in a minimal sample application, please create a new issue and share that application. |
@bclozel my bad, I had multiple scheduled methods and only for one of them setup the propagation. |
Currently a custom convention can be achieved only by going through the micrometer global conventions:
SomeCustom implementes GlobalObservationConvention<ScheduledTaskObservationContext>
which need to be extra registered in a ObservationRegistryCustomizer bean
This though is making it impossible to re-use the default code from the
DefaultScheduledTaskObservationConvention
because the observation registry -> observationConfig -> observationConvention method is expecting aGlobalObservationConvention<?>
whereas aDefaultScheduledTaskObservationConvention
is in a slight different chain of theObservationConvention
inheritance.Would it be feasible/possible to let the
ScheduledMethodRunnable
arrange its convention similar to theRestClientObservationConfiguration
for example, where a simple component or a bean extending theDefaultClientRequestObservationConvention
is enough to be used as a custom convention for thehttp.client.requests
metrics.Not sure what is the reason, but these customizations of conventions seem to not follow a consistent approach in general, see the recently fixed situation for the DefaultMongoHandlerObservationConvention, also in general:
DefaultServerRequestObservationConvention
// works like a charm for the http.server.requests metricsDefaultClientRequestObservationConvention
// works like a charm for the http.client.requests metricsDefaultRepositoryTagsProvider
// works like a charm for the spring.data.repository.invocations metrics though differs from first two onesDefaultMongoCommandTagsProvider
// works like a charm for the mongodb.driver.commands metrics though differs from first two onesGlobalObservationConvention<ScheduledTaskObservationContext>
// works for the tasks.scheduled.execution metrics, but as described above - only after manually adding it as part of a custom bean configuration of theObservationRegistryCustomizer<ObservationRegistry>
...observationRegistry.observationConfig().observationConvention(...)The text was updated successfully, but these errors were encountered: