Skip to content

MeterRegistryCustomizer not called if Spring Data is in the classpath #26675

Closed
@samcontesse

Description

@samcontesse

Hello!

It seems that the newly introduced RepositoryMetricsAutoConfiguration (Spring Boot 2.5.0) triggers the creation of the MeterRegistry bean during the initialization of the bean post processor. This leaves no chance for MeterRegistryPostProcessor#postProcessAfterInitialization to customize the registry with MeterRegistryCustomizer.
The call stack shows some registerBeanPostProcessors when the registry is instanciated which is not the case when RepositoryMetricsAutoConfiguration is not loaded.

I created a minimal sample repo to reproduce the issue.

If you run it, you can see that MetricsCustomizerNotCalledApplication#meterRegistryCustomizer is never called. If spring-boot-starter-data-jpa is removed from dependencies, it is called as expected.

A ugly workaround would be to call it again afterwards with something like:

    @Bean
    public InitializingBean forceMeterPostProcessor(BeanPostProcessor meterRegistryPostProcessor, MeterRegistry registry) {

        return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
    }

Thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions