提交 a328a3ba 编写于 作者: Q qxo 提交者: wu-sheng

jdbc-commons:reduce unnecessary call ThreadLocal with ContextManager#stopSpan(span) (#3244)

上级 8611124b
......@@ -36,8 +36,8 @@ public class CallableStatementTracing {
public static <R> R execute(java.sql.CallableStatement realStatement,
ConnectionInfo connectInfo, String method, String sql, Executable<R> exec)
throws SQLException {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer());
try {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer());
Tags.DB_TYPE.set(span, "sql");
SpanLayer.asDB(span);
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
......@@ -45,12 +45,11 @@ public class CallableStatementTracing {
span.setComponent(connectInfo.getComponent());
return exec.exe(realStatement, sql);
} catch (SQLException e) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(e);
throw e;
} finally {
ContextManager.stopSpan();
ContextManager.stopSpan(span);
}
}
......
......@@ -36,8 +36,8 @@ public class PreparedStatementTracing {
public static <R> R execute(java.sql.PreparedStatement realStatement,
ConnectionInfo connectInfo, String method, String sql, Executable<R> exec)
throws SQLException {
final AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, connectInfo.getDatabasePeer());
try {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, connectInfo.getDatabasePeer());
Tags.DB_TYPE.set(span, "sql");
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
......@@ -46,12 +46,11 @@ public class PreparedStatementTracing {
SpanLayer.asDB(span);
return exec.exe(realStatement, sql);
} catch (SQLException e) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(e);
throw e;
} finally {
ContextManager.stopSpan();
ContextManager.stopSpan(span);
}
}
......
......@@ -31,8 +31,8 @@ public class ConnectionTracing {
public static <R> R execute(java.sql.Connection realConnection,
ConnectionInfo connectInfo, String method, String sql, Executable<R> exec)
throws SQLException {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method, connectInfo.getDatabasePeer());
try {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method, connectInfo.getDatabasePeer());
Tags.DB_TYPE.set(span, "sql");
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
......@@ -40,12 +40,11 @@ public class ConnectionTracing {
SpanLayer.asDB(span);
return exec.exe(realConnection, sql);
} catch (SQLException e) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(e);
throw e;
} finally {
ContextManager.stopSpan();
ContextManager.stopSpan(span);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册