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

Make Context.getParentObservation() available for ObservationPredicate #3867

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

quaff
Copy link
Contributor

@quaff quaff commented May 31, 2023

After this commit, Context.setParentObservation() is called before matching predicate.
now we can filter out parentless observations like this:

	@Bean
	ObservationPredicate noParentlessDatabaseObservations() {
		return (name, context) -> {
			if (context instanceof LettuceObservationContext || context instanceof DataSourceBaseContext) {
				return context.getParentObservation() != null;
			}
			return true;
		};
	}

Resolves #3678

@jonatan-ivanov
Copy link
Member

jonatan-ivanov commented May 31, 2023

Thank you for the PR! Let us discuss this internally, I think this could resolve #3678 also we might want to add something like a getRootObservation method to get the first Observation in the chain conveniently.

@quaff
Copy link
Contributor Author

quaff commented Jun 1, 2023

Thank you for the PR! Let us discuss this internally, I think this could resolve #3678 also we might want to add something like a getRootObservation method to get the first Observation in the chain conveniently.

Should I add getRootObservation in this PR?

@quaff
Copy link
Contributor Author

quaff commented Jul 4, 2023

Would it be merged in next release?

@quaff
Copy link
Contributor Author

quaff commented Aug 16, 2023

I think it like a bug more than a enhancement, please fix it ASAP.

Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

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

The changes seem reasonable to me. One minor concern is that moving this out of the constructor means that we need to always make sure to set the parent wherever we might create an Observation. Even if this pull request covers all the places now, it's something that could be missed in future changes. I'm not sure we can do anything about that and allow the behavior we're seeking to change.
I'm asking others on the team to review so we can get feedback on this change in snapshots and a future milestone if we are going to merge this.

After this commit, Context.setParentObservation() is called before matching predicate.
@quaff
Copy link
Contributor Author

quaff commented Aug 16, 2023

The changes seem reasonable to me. One minor concern is that moving this out of the constructor means that we need to always make sure to set the parent wherever we might create an Observation. Even if this pull request covers all the places now, it's something that could be missed in future changes. I'm not sure we can do anything about that and allow the behavior we're seeking to change. I'm asking others on the team to review so we can get feedback on this change in snapshots and a future milestone if we are going to merge this.

We could revert SimpleObservation.java to make sure that, but it's safe to remove the redundant code since SimpleObservation is not public. @shakuzen

@shakuzen shakuzen modified the milestone: 1.12.0-M3 Aug 16, 2023
@shakuzen
Copy link
Member

The team discussed and we're okay to merge now and get some feedback and testing from users of this code. There are several consumers of this code that we'll want to get feedback on post-merge. I've built this locally and ran the tracing build against it - the build passed. Some instrumentation may be able to get rid of some code thanks to this change if they are manually setting a parent on the context before creating an Observation.

Thank you @quaff for the pull request.

We could revert SimpleObservation.java to make sure that, but it's safe to remove the redundant code since SimpleObservation is not public.

Thanks for thinking about this. That idea did occur to me, but I think if we're hitting that code path, we're going to have a difference in behavior between that path and other paths that we probably don't want.

@shakuzen shakuzen merged commit c959eb3 into micrometer-metrics:main Aug 16, 2023
6 checks passed
@quaff
Copy link
Contributor Author

quaff commented Aug 16, 2023

@shakuzen Thanks for your quick response, I've updated the commit to eliminate unnecessary null check context == null ? new Context() : context, you can polish it in another commit.

@shakuzen
Copy link
Member

I've updated the commit to eliminate unnecessary null check context == null ? new Context() : context, you can polish it in another commit.

I didn't notice that. We should not have changed that in this pull request. It's not good that we didn't have tests that failed because of the change. The context supplier comes from users, so we can't know that it doesn't return null, and we have no way of marking nullability of what the supplier returns. While isObservationEnabled takes a nullable context, the SimpleObservation constructor does not. But since we're using the context before either of those now, we need to figure out what to do.

@Nirshal
Copy link

Nirshal commented Aug 16, 2023

Any estimate on which release this will be included in?

@jonatan-ivanov
Copy link
Member

jonatan-ivanov commented Aug 16, 2023

@Nirshal If you look at the right side of the UI in the Development section, an issue is linked to this PR. That issue has a milestone: 12.0.0-M3. The milestone should have a due date (it did not have it, I just set it): 2023-09-11.
It's not guaranteed that we will release it on that day but that's the date we are aiming for.

If you are asking about the GA release date that should be in November (I guess 13th).

You can also check: https://calendar.spring.io/

@Nirshal
Copy link

Nirshal commented Aug 16, 2023

@jonatan-ivanov thanks a lot for the explanation!

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.

Provide a way to make decisions based on the parent in ObservationPredicate
4 participants