Skip to content

Add auto-configuration for OpenTelemetry SdkMeterProvider #46640

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ThomasVitale
Copy link

@ThomasVitale ThomasVitale commented Jul 31, 2025

  • Introduced metrics sub-package in the spring-boot-opentelemetry module.
  • Provided auto-configuration for SdkMeterProvider with customisation options via configuration properties and customizer bean.
  • Defined missing OpenTelemetry Clock bean used to initialise observability signals providers.
  • Added automated tests for the newly added auto-configuration.

Fixes gh-36546

ObjectProvider<SdkMeterProviderBuilderCustomizer> customizers) {
SdkMeterProviderBuilder builder = SdkMeterProvider.builder().setClock(clock).setResource(resource);
if (properties.getExemplars().isEnabled()) {
SdkMeterProviderUtil.setExemplarFilter(builder, exemplarFilter);
Copy link
Author

Choose a reason for hiding this comment

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

Exemplars are disabled by default because even though the Spec/API is GA, the method in the Java SDK to configure them is not exposed publicly, but through this util. Is that acceptable for Spring Boot?

The API (mapped closely by the configuration properties) won't change as it's stable. So, any change to the SDK internals will not require any code/configuration change from Spring Boot users (a.k.a. stable feature). See: https://opentelemetry.io/docs/specs/otel/metrics/sdk/#exemplar (stable API). More context: open-telemetry/opentelemetry-java#7503.

My recommendation would be to keep this functionality, but disabled by default. Considering that the OTLP Meter Registry doesn't support exemplars yet, this would be the only way in Spring Boot to support exemplars in OpenTelemetry.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine for me.

@ThomasVitale ThomasVitale marked this pull request as ready for review August 1, 2025 09:33

@Bean
@ConditionalOnMissingBean
@ConditionalOnBean({ Clock.class, Resource.class })
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work reliably without auto-configuration ordering, e.g.

@AutoConfiguration(after = OpenTelemetrySdkAutoConfiguration.class)

The logging auto-configuration doesn't have those conditionals, so i think it's okay to drop them here too.

ObjectProvider<SdkMeterProviderBuilderCustomizer> customizers) {
SdkMeterProviderBuilder builder = SdkMeterProvider.builder().setClock(clock).setResource(resource);
if (properties.getExemplars().isEnabled()) {
SdkMeterProviderUtil.setExemplarFilter(builder, exemplarFilter);
Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine for me.


@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(OpenTelemetry.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same ordering issue.

/**
* Maximum number of distinct points per metric.
*/
private Integer cardinalityLimit = 2000;
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be an int, couldn't it?

*
* @author Thomas Vitale
*/
class OpenTelemetryMetricsPropertiesTests {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see much value in these tests, as they only exercise a POJO class.

@mhalbritter
Copy link
Contributor

mhalbritter commented Aug 8, 2025

Thanks for the PR @ThomasVitale . Before we merge this, we need to decide on #36546 (comment), because this PR provides OTel beans but no way of exporting the metrics to a backend.

@mhalbritter mhalbritter added the status: waiting-for-feedback We need additional information before we can continue label Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide auto-configuration for OpenTelemetry metrics
3 participants