Skip to content

Interceptors

Ohad Shai edited this page Jun 4, 2019 · 4 revisions

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.

Implementation

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.

Logging Support

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.

MDC Support

This allows passing the MDC context along with the request and back on the response. To add it, install the built-in MdcQueryInterceptorSupplier.

Clone this wiki locally