-
Notifications
You must be signed in to change notification settings - Fork 979
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
Make observation return its context and immutable access to parent #3423
Make observation return its context and immutable access to parent #3423
Conversation
7035e00
to
7e908b4
Compare
To prevent modifying the parent observation, introduces the `ObservationView`, a read only view of the observation. Then, makes `Observation.Context#getParentObservation` to return the `ObservationView` which gives immutable way of referencing the context.
7e908b4
to
c6c2fac
Compare
@ttddyy Hi, I came across your PR, which hinders me to accomplish something I had in mind, which I read out from your statement now is a bad practice. Pls tell me, how to achieve it then otherwise. Here is the use case: For all besides the "http.server.requests" the current observation is the "spring.security.http.secured.requests" with parent "spring.security.filterchains" with root parent "http.server.requests" The "http.server.requests" has no parent. Now when I customize tags for these metrics, typically some beans are overridden or interfaces implemented and inside we either have access to the observation context (e.g. for the http.server/client.requests) or not (e.g. for the spring data observations), so one can not write nicely a reusable code how to propagate business data from the business layer into the context and read it out inside the customizers to decide on the custom tags. Btw. here is concrete example: Thanks |
@hadjiski |
This PR changes
Observation#getContext()
to returnContext
. Then, callers can obtain the actualContext
object from observation and perform any update on it.To prevent users modify the parent observation context, this PR introduces
ObservationView
interface. The interface provides a method that returnsContextView
for the observation.Then, the
Observation.Context#getParentObservation()
is updated to returnObservationView
instead of the parentObservation
.By the API contract, users cannot modify the parent observation context.
The
getParentObservation()
return type change is a small breaking change on API.However, modifying the parent observation is a bad practice. Nobody should be doing it and the impact should be minimal.