use of brave.propagation.ThreadLocalSpan in project brave by openzipkin.
the class TracingStatementInterceptor method preProcess.
/**
* Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but
* all callbacks happen on the same thread.
*
* <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before
* tracing.
*/
@Override
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) {
// Gets the next span (and places it in scope) so code between here and postProcess can read it
Span span = ThreadLocalSpan.CURRENT_TRACER.next();
if (span == null || span.isNoop())
return null;
// When running a prepared statement, sql will be null and we must fetch the sql from the statement itself
if (interceptedStatement instanceof PreparedStatement) {
sql = ((PreparedStatement) interceptedStatement).getPreparedSql();
}
// Allow span names of single-word statements like COMMIT
int spaceIndex = sql.indexOf(' ');
span.kind(CLIENT).name(spaceIndex == -1 ? sql : sql.substring(0, spaceIndex));
span.tag("sql.query", sql);
parseServerIpAndPort(connection, span);
span.start();
return null;
}
Aggregations