ipld-eth-server/vendor/gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql/tx.go

36 lines
734 B
Go
Raw Normal View History

2018-09-04 16:35:38 +00:00
package sql
import (
"context"
"database/sql/driver"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
var _ driver.Tx = (*tracedTx)(nil)
// tracedTx is a traced version of sql.Tx
type tracedTx struct {
driver.Tx
*traceParams
ctx context.Context
}
// Commit sends a span at the end of the transaction
func (t *tracedTx) Commit() (err error) {
span := t.newChildSpanFromContext(t.ctx, "Commit", "")
defer func() {
span.Finish(tracer.WithError(err))
}()
return t.Tx.Commit()
}
// Rollback sends a span if the connection is aborted
func (t *tracedTx) Rollback() (err error) {
span := t.newChildSpanFromContext(t.ctx, "Rollback", "")
defer func() {
span.Finish(tracer.WithError(err))
}()
return t.Tx.Rollback()
}