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

The list of queries is missing in QueryContext supplied to micrometer's ObservationPredicate #18

Closed
dmurat opened this issue May 4, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@dmurat
Copy link
Contributor

dmurat commented May 4, 2023

When the micrometer ObservationPredicate is configured, supplied QueryContext does not contain the list of queries.

Related discussion: #17

For example, the following test will not pass at the moment:

	@Test
	void queryPredicateGetsExpectedData() throws Exception{
		ObservationPredicate testQueryObservationPredicate = (s, observationContext) -> {
			if (observationContext instanceof QueryContext) {
				QueryContext queryContext = (QueryContext) observationContext;
				List<String> queries = queryContext.getQueries();

				assertThat(queries).isNotEmpty();
				assertThat(queries.get(0)).isEqualTo("SELECT 1");
				return true;
			}
			return true;
		};

		this.registry.observationConfig().observationHandler(new DefaultTracingObservationHandler(this.tracer));
		this.registry.observationConfig().observationPredicate(testQueryObservationPredicate);
		DataSourceObservationListener listener = new DataSourceObservationListener(this.registry);

		Method execute = Statement.class.getMethod("execute", String.class);

		QueryInfo queryInfo = new QueryInfo();
		queryInfo.setQuery("SELECT 1");

		ExecutionInfo executionInfo = new ExecutionInfo();
		executionInfo.setConnectionId("id-1");
		executionInfo.setDataSourceName("myDS");
		executionInfo.setMethod(execute);
		List<QueryInfo> queryInfos = Collections.singletonList(queryInfo);

		listener.beforeQuery(executionInfo, queryInfos);
	}

I will try to create appropriate PR.

@dmurat
Copy link
Contributor Author

dmurat commented May 4, 2023

PR is here: #19

@ttddyy ttddyy closed this as completed in 8ec5378 May 5, 2023
@ttddyy ttddyy added the bug Something isn't working label May 5, 2023
@dmurat
Copy link
Contributor Author

dmurat commented Dec 26, 2023

Hi,

Is it possible to get the 1.0.3 release published? I would very much like to have a fix for this bug.
Tnx.

@ttddyy
Copy link
Member

ttddyy commented Dec 27, 2023

@dmurat oh, sorry to kept you so long for getting this change in a release.
I just released 1.0.3 which includes this fix.

@dmurat
Copy link
Contributor Author

dmurat commented Dec 27, 2023

No problem, and thank you. You are very kind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants