-
-
Notifications
You must be signed in to change notification settings - Fork 138
Interceptors
Interceptors allow operating on queries globally from a single point. This can simplify cross-cutting concerns like logging, tracing, metrics measurements, and thread local transformations.
To implement an interceptor, one should inherit from QueryInterceptor
. There are methods that allow intercepting a query or a prepared statement.
For example, the below method gets the query string and is expected to return it.
fun interceptQuery(query: String): String
Manipulating the value and returning a different value allows manipulating statements globally.
The interceptQueryComplete
allows installing a hook on the result itself in a similar manner.
Once interceptor is implemented, add it to the pool configuration or connection configuration.
A simple interceptor that is logging with slf4j is implemented. See LoggingInterceptorSupplier.
To use it, add to the configuration: interceptors = listOf(LoggingInterceptorSupplier())
.
Messages will be appended to logger com.github.jasync.sql.QueryLog
in DEBUG level.
This allows passing the MDC context along with the request and back on the response. To add it, install the built-in MdcQueryInterceptorSupplier
.