jdbc-observations / datasource-micrometer

Micrometer Observation API instrumentation and Spring Boot 3 Auto-Configuration for JDBC APIs
Apache License 2.0
57 stars 9 forks source link

Question: Is it possible to include query template in `jdbc_query` metrics #13

Closed ieatlettuce closed 1 year ago

ieatlettuce commented 1 year ago

What I see in prometheus metrics

jdbc_query_seconds_max{error="none",} 113.698347232

What I want to see

jdbc_query_seconds_max{error="none",query="select * from user where name=?;"} 113.698347232

I've gone through documentation and code and were not able to identify the place I could inject custom tags or configure it to include SQL template.

I can do totally custom using QueryExecutionListener.afterQuery, but then I'll have two very similar metrics.

ttddyy commented 1 year ago

Hi @ieatlettuce You can create an ObservationHandler that reacts to the QueryContext. In the handler, you can create a meter and add the queries as a tag.