Skip to content

OpenTelemetryDataSource error when refresh configuration #13512

@kkz-01

Description

@kkz-01

Describe the bug
When using nacos to refresh the configuration, the OpenTelemetryDataSource reports an error and the configuration refresh does not take effect

Steps to reproduce
Use pom.xml to import opentelemetry-instrumentation-bom(v2.12.0) and opentelemetry-spring-boot-starter then use nacos to modify the configuration

What did you expect to see?
OpenTelemetryDataSource does not report an error and can obtain the correct constructor, Configuration refresh works fine

What did you see instead?
Refresh configuration failed. Through debug, found the error ExistingValue must be an instance of com.zaxxer.hikari.HikariDataSource.

It seems that SpringBoot cannot get the correct constructor of OpenTelemetryDataSource well.

What version and what artifacts are you using?

  • opentelemetry-instrumentation-bom(v2.12.0)
  • opentelemetry-spring-boot-starter
  • nacos-client(v2.3.2)
  • SpringBoot(v3.2.7)
  • use pom.xml to reference artifacts

Environment
Windows 10

Additional context
Through debug I got some information

The entrance is nacos-client, but the final error is due to the constructor method error returned by OpenTelemetryDataSource

error:

Image

entrance:

Image

I have been tracking the problem through debug and found the method link is as follows:

CacheData(nacos-client) -> publish RefreshEvent by ApplicationContext -> SimpleApplicationEventMulticaster#invokeListener (spring-context) -> ... -> ConfigurationPropertiesRebinder#onApplicationEvent -> ... -> ConfigurationPropertiesRebinder#rebind(String name, ApplicationContext appContext) -> initializeBean#initializeBean -> ... -> ConfigurationPropertiesBean#get which Causes an error

Image

beacause of the findFactoryMethod returns the wrong construction method, it causes an error in bindTarget = bindTarget.withExistingValue(bean);

Image

and i find that if factoryMethod return null. in ConfigurationPropertiesBean#createBindTarget it can return correct Constructor

Image

finally catch by ConfigurationPropertiesRebinder#rebind

Image

This looks like a bug right?

Activity

trask

trask commented on Mar 13, 2025

@trask
Member

transferred to opentelemetry-java-instrumentation repo where the spring boot starter lives

cc @jeanbisutti @zeitlinger

jeanbisutti

jeanbisutti commented on Mar 13, 2025

@jeanbisutti
Member

@kkz-01 Could you please provide a small repro with the detailed steps to reproduce the issue? It would help investigate.

kkz-01

kkz-01 commented on Mar 14, 2025

@kkz-01
Author

@jeanbisutti you can find code in repository
I have provided detailed steps to reproduce the issue and related picture in README.md

kkz-01

kkz-01 commented on Mar 16, 2025

@kkz-01
Author

I looked the code of opentelemetry-spring-boot-starter and found that OpenTelemetryDataSource wraps the data source through DataSourcePostProcessor#postProcessAfterInitialization but does not inject it into the container. I think the easiest way to fix this problem is to inject OpenTelemetryDataSource into the container through @Bean or other methods.

kkz-01

kkz-01 commented on Mar 16, 2025

@kkz-01
Author

Because OpenTelemetryDataSource is not injected into the container and in SpringBoot DataSourceConfiguration$Hikari#dataSource method create a Default HikariDataSource, the bean obtained by the beanFactory.getMergedBeanDefinition("dataSource"); is the bean injected by DataSourceConfiguration$Hikari#dataSource which causes the constructor obtained is not OpenTelemetryDataSource and does not pass the check in Bindable#withExistingValue

zeitlinger

zeitlinger commented on Mar 17, 2025

@zeitlinger
Member

@kkz-01 sounds like you've found the root cause. A PR with a fix would be highly welcome 😄

shellysam

shellysam commented on Apr 30, 2025

@shellysam

@kkz-01 @zeitlinger
I also face the same issue. Is there a fix? Or a way how this can be handled?

dngyukm

dngyukm commented on May 19, 2025

@dngyukm

@kkz-01 @zeitlinger
Hello, I’d like to work on this issue if that’s alright.

zeitlinger

zeitlinger commented on May 19, 2025

@zeitlinger
Member

@dngyukm yes that would be awesome 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @trask@zeitlinger@jeanbisutti@shellysam@kkz-01

    Issue actions

      OpenTelemetryDataSource error when refresh configuration · Issue #13512 · open-telemetry/opentelemetry-java-instrumentation