tx.go (723B)
1 package otelsql 2 3 import ( 4 "context" 5 "database/sql/driver" 6 7 "go.opentelemetry.io/otel/trace" 8 ) 9 10 type otelTx struct { 11 ctx context.Context 12 tx driver.Tx 13 instrum *dbInstrum 14 } 15 16 var _ driver.Tx = (*otelTx)(nil) 17 18 func newTx(ctx context.Context, tx driver.Tx, instrum *dbInstrum) *otelTx { 19 return &otelTx{ 20 ctx: ctx, 21 tx: tx, 22 instrum: instrum, 23 } 24 } 25 26 func (tx *otelTx) Commit() error { 27 return tx.instrum.withSpan(tx.ctx, "tx.Commit", "", 28 func(ctx context.Context, span trace.Span) error { 29 return tx.tx.Commit() 30 }) 31 } 32 33 func (tx *otelTx) Rollback() error { 34 return tx.instrum.withSpan(tx.ctx, "tx.Rollback", "", 35 func(ctx context.Context, span trace.Span) error { 36 return tx.tx.Rollback() 37 }) 38 }