Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
ThomasVitale wants to merge 2 commits into spring-projects:main
base: main
Choose a base branch
Loading
from ThomasVitale:gh-36546

Conversation

Copy link

@ThomasVitale ThomasVitale commented Jul 31, 2025
edited
Loading

  • 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

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
ObjectProvider<SdkMeterProviderBuilderCustomizer> customizers) {
SdkMeterProviderBuilder builder = SdkMeterProvider.builder().setClock(clock).setResource(resource);
if (properties.getExemplars().isEnabled()) {
SdkMeterProviderUtil.setExemplarFilter(builder, exemplarFilter);
Copy link
Author

@ThomasVitale ThomasVitale Aug 1, 2025

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

@mhalbritter mhalbritter Aug 8, 2025

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 reacted with thumbs up emoji
@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

@mhalbritter mhalbritter Aug 8, 2025

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.

Copy link
Author

@ThomasVitale ThomasVitale Aug 11, 2025

Choose a reason for hiding this comment

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

Ok, I'll remove all those conditionals

Copy link
Author

@ThomasVitale ThomasVitale Aug 11, 2025

Choose a reason for hiding this comment

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

Removed

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

@mhalbritter mhalbritter Aug 8, 2025

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 reacted with thumbs up emoji

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

@mhalbritter mhalbritter Aug 8, 2025

Choose a reason for hiding this comment

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

Same ordering issue.

Copy link
Author

@ThomasVitale ThomasVitale Aug 11, 2025

Choose a reason for hiding this comment

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

Removed

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

@mhalbritter mhalbritter Aug 8, 2025

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?

Copy link
Author

@ThomasVitale ThomasVitale Aug 11, 2025

Choose a reason for hiding this comment

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

That's true. I'll change it.

Copy link
Author

@ThomasVitale ThomasVitale Aug 11, 2025

Choose a reason for hiding this comment

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

Done

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

@mhalbritter mhalbritter Aug 8, 2025

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.

Copy link
Author

@ThomasVitale ThomasVitale Aug 11, 2025

Choose a reason for hiding this comment

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

I'll remove them

Copy link
Author

@ThomasVitale ThomasVitale Aug 11, 2025

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

mhalbritter commented Aug 8, 2025
edited
Loading

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
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Copy link
Author

@mhalbritter thanks so much for the review. I have addressed your comments and pushed a second commit (after the final review, I can squash them to provide a single commit).

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 11, 2025
@mhalbritter mhalbritter added type: enhancement A general enhancement status: blocked An issue that's blocked on an external project change and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Aug 12, 2025
@mhalbritter mhalbritter added this to the 4.0.x milestone Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@mhalbritter mhalbritter mhalbritter left review comments

Labels
status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement
Projects
None yet
Milestone
4.0.x
Development

Successfully merging this pull request may close these issues.

Provide auto-configuration for OpenTelemetry metrics

AltStyle によって変換されたページ (->オリジナル) /