Skip to content
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

fix micrometer bridge auto configuration annotation #13083

Merged
merged 16 commits into from
Feb 12, 2025

Conversation

zeitlinger
Copy link
Member

Fixes #12719 - hopefully

@zeitlinger zeitlinger requested a review from a team as a code owner January 22, 2025 13:05
@zeitlinger zeitlinger changed the title fix annotation fix micrometer bridge auto configuration annotation Jan 22, 2025
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think a test could be added for this?

@zeitlinger
Copy link
Member Author

do you think a test could be added for this?

yes - I even found the test that I broke with this PR.

@zeitlinger zeitlinger self-assigned this Jan 23, 2025
@zeitlinger zeitlinger force-pushed the micrometer-bridge-auto-config branch from a888249 to b9a2ab1 Compare January 27, 2025 13:43
@zeitlinger zeitlinger force-pushed the micrometer-bridge-auto-config branch from 0f347b6 to 84abdcc Compare February 6, 2025 14:05
Comment on lines 25 to 33
testing {
suites {
val testPrometheus by registering(JvmTestSuite::class) {
dependencies {
runtimeOnly("io.micrometer:micrometer-registry-prometheus:1.14.3")
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there are no source for this suite it won't run any tests as far as I can tell

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - I had to test this by adding id("com.adarshr.test-logger") version "4.0.0" to see that noting gets executed...

used the setup for stable semconv now

@zeitlinger
Copy link
Member Author

Exception

    java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusSimpleclientMetricsExportAutoConfiguration.simpleclientPrometheusMeterRegistry	
        at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)	
        at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:99)	
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:184)	
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:145)	
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:121)	
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:430)	
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:290)	
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:349)	
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118)	
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791)	
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609)	
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)	
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)	
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)	
        at io.opentelemetry.javaagent.instrumentation.spring.actuator.v2_0.ActuatorTest.shouldInjectOtelMeterRegistry(ActuatorTest.java:35)	
        Caused by:	
        java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusSimpleclientMetricsExportAutoConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@76ed5528]	
            at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483)	
            at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:360)	
            at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:417)	
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$1(AbstractAutowireCapableBeanFactory.java:751)	
            at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)	
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:750)	
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:683)	
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:654)	
            at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1683)	
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:592)	
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:564)	
            at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanDefinitionsForType(OnBeanCondition.java:332)	
            at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanDefinitionsForType(OnBeanCondition.java:324)	
            at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanDefinitionsForType(OnBeanCondition.java:314)	
            at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:213)	
            at org.springframework.boot.autoconfigure.condition.OnBeanCondition.evaluateConditionalOnMissingBean(OnBeanCondition.java:196)	
            at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:143)	
            at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)	
            ... 14 more	
            Caused by:	
            java.lang.NoClassDefFoundError: io/prometheus/client/exemplars/tracer/common/SpanContextSupplier	
                at java.base/java.lang.Class.getDeclaredMethods0(Native Method)	
                at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3578)	
                at java.base/java.lang.Class.getDeclaredMethods(Class.java:2676)	
                at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465)	
                ... 31 more	
                Caused by:	
                java.lang.ClassNotFoundException: io.prometheus.client.exemplars.tracer.common.SpanContextSupplier	
                    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)	
                    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)	
                    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)	
                    ... 35 more

@zeitlinger
Copy link
Member Author

I can't reproduce the error locally with ./gradlew :instrumentation:spring:spring-boot-actuator-autoconfigure-2.0:javaagent:test -PtestIndy=true

@laurit can you help?

@laurit
Copy link
Contributor

laurit commented Feb 10, 2025

I can't reproduce the error locally with ./gradlew :instrumentation:spring:spring-boot-actuator-autoconfigure-2.0:javaagent:test -PtestIndy=true

@laurit can you help?

For met it repros fine. I think the problem is in runtimeOnly("io.micrometer:micrometer-registry-prometheus:1.0.1") which means that this dependency along with its transitive dependencies is bundled inside the agent. When using indy we prefer classes from the agent over the application classes so muzzle checks fail because the micrometer version inside the agent doesn't have the required method.

@@ -32,4 +40,30 @@ public class OpenTelemetryMeterRegistryAutoConfiguration {
public MeterRegistry otelMeterRegistry() {
return MicrometerSingletons.meterRegistry();
}

@Bean
static BeanPostProcessor postProcessCompositeMeterRegistry() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a convention of making these methods public?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeitlinger
Copy link
Member Author

I can't reproduce the error locally with ./gradlew :instrumentation:spring:spring-boot-actuator-autoconfigure-2.0:javaagent:test -PtestIndy=true
@laurit can you help?

For met it repros fine. I think the problem is in runtimeOnly("io.micrometer:micrometer-registry-prometheus:1.0.1") which means that this dependency along with its transitive dependencies is bundled inside the agent. When using indy we prefer classes from the agent over the application classes so muzzle checks fail because the micrometer version inside the agent doesn't have the required method.

thanks - I'll try with testLibrary

@zeitlinger
Copy link
Member Author

zeitlinger commented Feb 10, 2025

I can't reproduce the error locally with ./gradlew :instrumentation:spring:spring-boot-actuator-autoconfigure-2.0:javaagent:test -PtestIndy=true
@laurit can you help?

For met it repros fine. I think the problem is in runtimeOnly("io.micrometer:micrometer-registry-prometheus:1.0.1") which means that this dependency along with its transitive dependencies is bundled inside the agent. When using indy we prefer classes from the agent over the application classes so muzzle checks fail because the micrometer version inside the agent doesn't have the required method.

thanks - I'll try with testLibrary

apparently that worked

@laurit I'm hoping that this also makes sense 😄

@trask trask added this to the v2.13.0 milestone Feb 12, 2025
…javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/actuator/v2_0/OpenTelemetryMeterRegistryAutoConfiguration.java

Co-authored-by: Trask Stalnaker <[email protected]>
@trask trask merged commit 15358d6 into open-telemetry:main Feb 12, 2025
61 checks passed
@zeitlinger zeitlinger deleted the micrometer-bridge-auto-config branch February 12, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Micrometer-bridge breaks Spring Actuator metrics
3 participants