Skip to content

Conversation

cfredri4
Copy link

This change configures the global observation registry.

Same as is done for the metric registry, but for the observation registry.

This change configures the global observation registry.

Signed-off-by: cfredri4 <christian.fredriksson.2@volvocars.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 29, 2025
@wilkinsona wilkinsona added the status: waiting-for-internal-feedback An issue that needs input from a member of another Spring Team label Sep 30, 2025
@jonatan-ivanov
Copy link
Member

What is your use-case?
I don't think it is a good idea to use the global (meter or) observation registry, you should rather inject it.

@cfredri4
Copy link
Author

cfredri4 commented Oct 1, 2025

The use case is convenience. It's very convenient to just do Observations.getGlobalRegistry() instead of injecting the registry.
That's why the global registry exists in the first place I assume? And since it does exist, I would intuitively expect Spring Boot to configure it just like is done for metrics.

@jonatan-ivanov
Copy link
Member

The use case is convenience. It's very convenient to just do Observations.getGlobalRegistry() instead of injecting the registry.

In my opinion, there is a price you need to pay for doing that (hard to test/configure). This also goes against one of the fundamental concepts of Spring Framework: https://docs.spring.io/spring-framework/reference/core/beans/dependencies/factory-collaborators.html

That's why the global registry exists in the first place I assume? And since it does exist, I would intuitively expect Spring Boot to configure it just like is done for metrics.

The global meter registry predates me and I think maybe it was partly created for this reason (I think largely not) but it would be a wrong assumption for the global observation registry. If I remember correctly, it was created because it was impossible to inject components into some custom components of Netty. If you check its javadoc, it says: "For use especially in places where dependency injection of ObservationRegistry is not possible".

@snicoll
Copy link
Member

snicoll commented Oct 2, 2025

Thanks @jonatan-ivanov for the review. Closing a result.

@snicoll snicoll closed this Oct 2, 2025
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged status: waiting-for-internal-feedback An issue that needs input from a member of another Spring Team labels Oct 2, 2025
@cfredri4
Copy link
Author

cfredri4 commented Oct 2, 2025

In my opinion, there is a price you need to pay for doing that (hard to test/configure). This also goes against one of the fundamental concepts of Spring Framework: https://docs.spring.io/spring-framework/reference/core/beans/dependencies/factory-collaborators.html

Sure, but that price is - in many simple cases like mine and I would assume many others - completely insignificant.
I don't need or want to care about the observation registry. There is no testing or configuration of the registry or observations. There is one registry and my services does not/should not care about its details; Spring Boot configures it and it just works.

If I remember correctly, it was created because it was impossible to inject components into some custom components of Netty. If you check its javadoc, it says: "For use especially in places where dependency injection of ObservationRegistry is not possible".

But then for those cases, shouldn't Spring be configuring the global registry to allow such use?
(then you can look away while I and others "abuse" it for convenience. 🫣)

@cfredri4 cfredri4 deleted the configure-global-observation-registry branch October 2, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants