Package brave.mysql8

Class TracingQueryInterceptor

java.lang.Object
brave.mysql8.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 Summary

    Constructors 
    Constructor Description
    TracingQueryInterceptor()  
  • Method Summary

    Modifier and Type Method Description
    void destroy()  
    boolean executeTopLevelOnly()  
    com.mysql.cj.interceptors.QueryInterceptor init​(com.mysql.cj.MysqlConnection mysqlConnection, Properties properties, com.mysql.cj.log.Log log)  
    <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)  
    <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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.mysql.cj.interceptors.QueryInterceptor

    postProcess, preProcess
  • Constructor Details

  • Method Details

    • 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