summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/tx.go
blob: c4bd55e1322e404f3271b414a27d973d16f5970a (plain)
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
package otelsql

import (
	"context"
	"database/sql/driver"

	"go.opentelemetry.io/otel/trace"
)

type otelTx struct {
	ctx     context.Context
	tx      driver.Tx
	instrum *dbInstrum
}

var _ driver.Tx = (*otelTx)(nil)

func newTx(ctx context.Context, tx driver.Tx, instrum *dbInstrum) *otelTx {
	return &otelTx{
		ctx:     ctx,
		tx:      tx,
		instrum: instrum,
	}
}

func (tx *otelTx) Commit() error {
	return tx.instrum.withSpan(tx.ctx, "tx.Commit", "",
		func(ctx context.Context, span trace.Span) error {
			return tx.tx.Commit()
		})
}

func (tx *otelTx) Rollback() error {
	return tx.instrum.withSpan(tx.ctx, "tx.Rollback", "",
		func(ctx context.Context, span trace.Span) error {
			return tx.tx.Rollback()
		})
}