-
Notifications
You must be signed in to change notification settings - Fork 44
/
tx.go
executable file
·48 lines (41 loc) · 1008 Bytes
/
tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package instrumentedsql
import (
"context"
"database/sql/driver"
"time"
)
type wrappedTx struct {
opts
ctx context.Context
parent driver.Tx
}
// Compile time validation that our types implement the expected interfaces
var (
_ driver.Tx = wrappedTx{}
)
func (t wrappedTx) Commit() (err error) {
if !t.hasOpExcluded(OpSQLTxCommit) {
span := t.GetSpan(t.ctx).NewChild(OpSQLTxCommit)
span.SetLabel("component", "database/sql")
start := time.Now()
defer func() {
span.SetError(err)
span.Finish()
t.Log(t.ctx, OpSQLTxCommit, "err", err, "duration", time.Since(start))
}()
}
return t.parent.Commit()
}
func (t wrappedTx) Rollback() (err error) {
if !t.hasOpExcluded(OpSQLTxRollback) {
span := t.GetSpan(t.ctx).NewChild(OpSQLTxRollback)
span.SetLabel("component", "database/sql")
start := time.Now()
defer func() {
span.SetError(err)
span.Finish()
t.Log(t.ctx, OpSQLTxRollback, "err", err, "duration", time.Since(start))
}()
}
return t.parent.Rollback()
}