Skip to content

Commit

Permalink
feat(hook): use tx context inside Commit/Rollback after (#1)
Browse files Browse the repository at this point in the history
Fixes misplaced commit and rollback spans, which are traced inside own
span all the time.
  • Loading branch information
ancarebeca authored Dec 6, 2022
1 parent cc61ea0 commit 6a7f50b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ func (c otConn) Begin() (tx driver.Tx, err error) {
return wrapTx(ctx, c.connID, tx, c.Options), nil
}

func (c otConn) BeginTx(ctx context.Context, opts driver.TxOptions) (tx driver.Tx, err error) {
func (c otConn) BeginTx(spanCtx context.Context, opts driver.TxOptions) (tx driver.Tx, err error) {
evt := newEvent(c.Options, c.connID, MethodBegin, "", nil)
ctx = before(c.Hooks, ctx, evt)
ctx := before(c.Hooks, spanCtx, evt)
defer func() {
evt.Err = err
after(c.Hooks, ctx, evt)
Expand All @@ -179,7 +179,7 @@ func (c otConn) BeginTx(ctx context.Context, opts driver.TxOptions) (tx driver.T
return nil, err
}
}
return wrapTx(ctx, c.connID, tx, c.Options), nil
return wrapTx(spanCtx, c.connID, tx, c.Options), nil
}

func (c otConn) Close() (err error) {
Expand Down Expand Up @@ -534,7 +534,7 @@ type otTx struct {

func (t otTx) Commit() (err error) {
evt := newEvent(t.Options, t.connID, MethodCommit, "", nil)
ctx := before(t.Hooks, context.Background(), evt)
ctx := before(t.Hooks, t.ctx, evt)
defer func() {
evt.Err = err
after(t.Hooks, ctx, evt)
Expand All @@ -545,7 +545,7 @@ func (t otTx) Commit() (err error) {

func (t otTx) Rollback() (err error) {
evt := newEvent(t.Options, t.connID, MethodRollback, "", nil)
ctx := before(t.Hooks, context.Background(), evt)
ctx := before(t.Hooks, t.ctx, evt)
defer func() {
evt.Err = err
after(t.Hooks, ctx, evt)
Expand Down

0 comments on commit 6a7f50b

Please sign in to comment.