Instrumentation: Start tracing database requests (#34572)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Carl Bergquist
2021-05-27 13:55:33 +02:00
committed by GitHub
parent 29d34974e7
commit a10fa5cad3
10 changed files with 71 additions and 31 deletions
+13 -4
View File
@@ -19,12 +19,17 @@ func (sess *DBSession) publishAfterCommit(msg interface{}) {
}
// NewSession returns a new DBSession
func (ss *SQLStore) NewSession() *DBSession {
return &DBSession{Session: ss.engine.NewSession()}
func (ss *SQLStore) NewSession(ctx context.Context) *DBSession {
sess := &DBSession{Session: ss.engine.NewSession()}
sess.Session = sess.Session.Context(ctx)
return sess
}
func newSession() *DBSession {
return &DBSession{Session: x.NewSession()}
func newSession(ctx context.Context) *DBSession {
sess := &DBSession{Session: x.NewSession()}
sess.Session = sess.Session.Context(ctx)
return sess
}
func startSession(ctx context.Context, engine *xorm.Engine, beginTran bool) (*DBSession, error) {
@@ -33,6 +38,7 @@ func startSession(ctx context.Context, engine *xorm.Engine, beginTran bool) (*DB
sess, ok := value.(*DBSession)
if ok {
sess.Session = sess.Session.Context(ctx)
return sess, nil
}
@@ -43,6 +49,8 @@ func startSession(ctx context.Context, engine *xorm.Engine, beginTran bool) (*DB
return nil, err
}
}
newSess.Session = newSess.Session.Context(ctx)
return newSess, nil
}
@@ -53,6 +61,7 @@ func (ss *SQLStore) WithDbSession(ctx context.Context, callback dbTransactionFun
func withDbSession(ctx context.Context, engine *xorm.Engine, callback dbTransactionFunc) error {
sess := &DBSession{Session: engine.NewSession()}
sess.Session = sess.Session.Context(ctx)
defer sess.Close()
return callback(sess)