Package brave.mysql8

Class TracingQueryInterceptor

  • All Implemented Interfaces:
    com.mysql.cj.interceptors.QueryInterceptor

    public class TracingQueryInterceptor
    extends Object
    implements com.mysql.cj.interceptors.QueryInterceptor
    A MySQL query interceptor that will report to Zipkin how long each query takes.

    To use it, append ?queryInterceptors=brave.mysql8.TracingQueryInterceptor to the end of the connection url. It is also highly recommended to add &exceptionInterceptors=brave.mysql8.TracingExceptionInterceptor so errors are also included in spans.

    • Constructor Detail

      • TracingQueryInterceptor

        public TracingQueryInterceptor()
    • Method Detail

      • preProcess

        public <T extends com.mysql.cj.protocol.Resultset> T preProcess​(Supplier<String> sqlSupplier,
                                                                        com.mysql.cj.Query interceptedQuery)
        Uses ThreadLocalSpan as there's no attribute namespace shared between callbacks, but all callbacks happen on the same thread.

        Uses ThreadLocalSpan.CURRENT_TRACER and this interceptor initializes before tracing.

        Specified by:
        preProcess in interface com.mysql.cj.interceptors.QueryInterceptor
      • postProcess

        public <T extends com.mysql.cj.protocol.Resultset> T postProcess​(Supplier<String> sql,
                                                                         com.mysql.cj.Query interceptedQuery,
                                                                         T originalResultSet,
                                                                         com.mysql.cj.protocol.ServerSession serverSession)
        Specified by:
        postProcess in interface com.mysql.cj.interceptors.QueryInterceptor
      • executeTopLevelOnly

        public boolean executeTopLevelOnly()
        Specified by:
        executeTopLevelOnly in interface com.mysql.cj.interceptors.QueryInterceptor
      • init

        public com.mysql.cj.interceptors.QueryInterceptor init​(com.mysql.cj.MysqlConnection mysqlConnection,
                                                               Properties properties,
                                                               com.mysql.cj.log.Log log)
        Specified by:
        init in interface com.mysql.cj.interceptors.QueryInterceptor
      • destroy

        public void destroy()
        Specified by:
        destroy in interface com.mysql.cj.interceptors.QueryInterceptor