jdbc-observations / datasource-micrometer

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

Fix "jdbc.includes" to control observation creation #15

Closed ttddyy closed 1 year ago

ttddyy commented 1 year ago

It is reported by @artembilan Currently, when jdbc.includes=QUERY is set, it still creates connection spans.

By quick look, the auto-config defines corresponding ObservationHandler beans based on the jdbc.includes property. These Observationhandler bean classes use the instanceof for the observation context(Connection|Query|ResultSet]Context). However, in Boot, the MicrometerTracingAutoConfiguration creates a default PropagatingSenderTracingObservationHandler bean. This class performs context instanceof SenderContext. Since [Connection|Query|ResultSet]Context are a child of SenderContext, the default handler always matches and creates corresponding spans.

Instead of using ObservationHandler, it needs to use ObservationPredicate for the jdbc.includes to control whether to create observation(span/metrics) specified in the property.