/
batch_results.go
71 lines (55 loc) · 1.68 KB
/
batch_results.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// (c) Copyright IBM Corp. 2022
package instapgx
import (
"context"
"sync"
instana "github.com/instana/go-sensor"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
)
// batchResults is a wrapper for pgx.batchResults
type batchResults struct {
pgx.BatchResults
ctx context.Context
sensor instana.TracerLogger
config *pgx.ConnConfig
}
// Exec wraps (*pgx.batchResults).Exec and adds tracing to it.
func (b *batchResults) Exec() (pgconn.CommandTag, error) {
_, span := contextWithChildSpan(b.ctx, "-- BatchResults EXEC", b.config, b.sensor)
defer span.Finish()
ct, err := b.BatchResults.Exec()
if err != nil {
recordAnError(span, err)
}
return ct, err
}
// Query wraps (*pgx.batchResults).Query and adds tracing to it.
func (b *batchResults) Query() (pgx.Rows, error) {
_, span := contextWithChildSpan(b.ctx, "-- BatchResults QUERY", b.config, b.sensor)
defer span.Finish()
rows, err := b.BatchResults.Query()
if err != nil {
recordAnError(span, err)
}
return rows, err
}
// QueryRow wraps (*pgx.batchResults).QueryRow and adds tracing to it.
func (b *batchResults) QueryRow() pgx.Row {
_, span := contextWithChildSpan(b.ctx, "-- BatchResults QUERY ROW", b.config, b.sensor)
return &row{
Row: b.BatchResults.QueryRow(),
span: span,
m: &sync.Mutex{},
}
}
// QueryFunc wraps (*pgx.batchResults).QueryFunc and adds tracing to it.
func (b *batchResults) QueryFunc(scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error) {
_, span := contextWithChildSpan(b.ctx, "-- BatchResults QUERY FUNC", b.config, b.sensor)
defer span.Finish()
ct, err := b.BatchResults.QueryFunc(scans, f)
if err != nil {
recordAnError(span, err)
}
return ct, err
}