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

OpenTelemetryDataSource error when refresh configuration #13512

Open
kkz-01 opened this issue Mar 13, 2025 · 5 comments
Open

OpenTelemetryDataSource error when refresh configuration #13512

kkz-01 opened this issue Mar 13, 2025 · 5 comments
Labels
bug Something isn't working spring boot starter

Comments

@kkz-01
Copy link

kkz-01 commented Mar 13, 2025

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?

@kkz-01 kkz-01 added the bug Something isn't working label Mar 13, 2025
@trask trask transferred this issue from open-telemetry/opentelemetry-java Mar 13, 2025
@trask
Copy link
Member

trask commented Mar 13, 2025

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

cc @jeanbisutti @zeitlinger

@jeanbisutti
Copy link
Member

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

@kkz-01
Copy link
Author

kkz-01 commented Mar 14, 2025

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

@kkz-01
Copy link
Author

kkz-01 commented Mar 16, 2025

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
Copy link
Author

kkz-01 commented Mar 16, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working spring boot starter
Projects
None yet
Development

No branches or pull requests

3 participants