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 <T extends Resultset> T preProcess(String sql, Statement interceptedStatement) {
// 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;
}
use of brave.propagation.ThreadLocalSpan in project brave by openzipkin.
the class TracingQueryInterceptor 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 <T extends Resultset> T preProcess(Supplier<String> sqlSupplier, Query interceptedQuery) {
// 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;
String sql = sqlSupplier.get();
// 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;
}
use of brave.propagation.ThreadLocalSpan in project brave by openzipkin.
the class TraceMongoCommandListener method commandStarted.
/**
* Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but
* all callbacks happen on the same thread.
*/
@Override
public void commandStarted(CommandStartedEvent event) {
String databaseName = event.getDatabaseName();
// don't trace commands like "endSessions"
if ("admin".equals(databaseName))
return;
Span span = threadLocalSpan.next();
if (span == null || span.isNoop())
return;
String commandName = event.getCommandName();
BsonDocument command = event.getCommand();
String collectionName = getCollectionName(command, commandName);
span.name(getSpanName(commandName, collectionName)).kind(CLIENT).remoteServiceName("mongodb-" + databaseName).tag("mongodb.command", commandName);
if (collectionName != null) {
span.tag("mongodb.collection", collectionName);
}
ConnectionDescription connectionDescription = event.getConnectionDescription();
if (connectionDescription != null) {
ConnectionId connectionId = connectionDescription.getConnectionId();
if (connectionId != null) {
span.tag("mongodb.cluster_id", connectionId.getServerId().getClusterId().getValue());
}
try {
InetSocketAddress socketAddress = connectionDescription.getServerAddress().getSocketAddress();
span.remoteIpAndPort(socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
} catch (MongoSocketException ignored) {
}
}
span.start();
}
use of brave.propagation.ThreadLocalSpan in project brave by openzipkin.
the class TracingExceptionInterceptor method interceptException.
/**
* Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but
* all callbacks happen on the same thread. The span will already have been created in {@link
* TracingQueryInterceptor}.
*
* <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before
* tracing.
*/
@Override
public Exception interceptException(Exception e) {
Span span = ThreadLocalSpan.CURRENT_TRACER.remove();
if (span == null || span.isNoop())
return null;
span.error(e);
if (e instanceof SQLException) {
span.tag("error", Integer.toString(((SQLException) e).getErrorCode()));
}
span.finish();
return null;
}
use of brave.propagation.ThreadLocalSpan in project brave by openzipkin.
the class TracingJdbcEventListener method onBeforeAnyExecute.
/**
* 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 void onBeforeAnyExecute(StatementInformation info) {
String sql = includeParameterValues ? info.getSqlWithValues() : info.getSql();
if (!isLoggable(sql))
return;
// 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;
// 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(info.getConnectionInformation().getConnection(), span);
span.start();
}
Aggregations