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

Inject ObjectProvider into BeanPostProcessors to avoid premature initialization of OpenTelemetry #3171

Merged
merged 1 commit into from
Jun 3, 2021

Conversation

HaloFour
Copy link
Contributor

@HaloFour HaloFour commented Jun 2, 2021

When a BeanPostProcessor takes a dependency on a bean directly it forces that bean and it's dependencies to be immediately instantiated. This can create a situation where those dependencies might not be post-processed by other BeanPostProcessors that have not yet been initialized. By injecting ObjectProvider<T> into the BeanPostProcessors the initialization of those dependencies can be deferred avoiding this issue.

@HaloFour
Copy link
Contributor Author

HaloFour commented Jun 2, 2021

I had been bitten by this as I have a custom SpanExporter implementation that uses MeterRegistry to report span metrics to prometheus. These BeanPostProcessors were causing OpenTelemetry and my SpanExporter to be instantiated which was causing MeterRegistry to also be initialized before MeterRegistryPostProcessor was available. That was causing my MeterRegistryCustomizer to not be processed resulting in custom tags not being applied to any metrics.

I've not found any written documentation that states that BeanPostProcessors should always use ObjectProvider<T> or @Lazy but it seems like the safest route to take.

@trask trask merged commit 7ef31a0 into open-telemetry:main Jun 3, 2021
robododge pushed a commit to robododge/opentelemetry-java-instrumentation that referenced this pull request Jun 17, 2021
@HaloFour HaloFour deleted the lazy-spring-bpp-autoconfigure branch July 17, 2021 01:04
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.

None yet

3 participants