-
Notifications
You must be signed in to change notification settings - Fork 846
/
tracer.go
107 lines (84 loc) · 2.95 KB
/
tracer.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package pgx
import (
"context"
"github.com/jackc/pgx/v5/pgconn"
)
// QueryTracer traces Query, QueryRow, and Exec.
type QueryTracer interface {
// TraceQueryStart is called at the beginning of Query, QueryRow, and Exec calls. The returned context is used for the
// rest of the call and will be passed to TraceQueryEnd.
TraceQueryStart(ctx context.Context, conn *Conn, data TraceQueryStartData) context.Context
TraceQueryEnd(ctx context.Context, conn *Conn, data TraceQueryEndData)
}
type TraceQueryStartData struct {
SQL string
Args []any
}
type TraceQueryEndData struct {
CommandTag pgconn.CommandTag
Err error
}
// BatchTracer traces SendBatch.
type BatchTracer interface {
// TraceBatchStart is called at the beginning of SendBatch calls. The returned context is used for the
// rest of the call and will be passed to TraceBatchQuery and TraceBatchEnd.
TraceBatchStart(ctx context.Context, conn *Conn, data TraceBatchStartData) context.Context
TraceBatchQuery(ctx context.Context, conn *Conn, data TraceBatchQueryData)
TraceBatchEnd(ctx context.Context, conn *Conn, data TraceBatchEndData)
}
type TraceBatchStartData struct {
Batch *Batch
}
type TraceBatchQueryData struct {
SQL string
Args []any
CommandTag pgconn.CommandTag
Err error
}
type TraceBatchEndData struct {
Err error
}
// CopyFromTracer traces CopyFrom.
type CopyFromTracer interface {
// TraceCopyFromStart is called at the beginning of CopyFrom calls. The returned context is used for the
// rest of the call and will be passed to TraceCopyFromEnd.
TraceCopyFromStart(ctx context.Context, conn *Conn, data TraceCopyFromStartData) context.Context
TraceCopyFromEnd(ctx context.Context, conn *Conn, data TraceCopyFromEndData)
}
type TraceCopyFromStartData struct {
TableName Identifier
ColumnNames []string
}
type TraceCopyFromEndData struct {
CommandTag pgconn.CommandTag
Err error
}
// PrepareTracer traces Prepare.
type PrepareTracer interface {
// TracePrepareStart is called at the beginning of Prepare calls. The returned context is used for the
// rest of the call and will be passed to TracePrepareEnd.
TracePrepareStart(ctx context.Context, conn *Conn, data TracePrepareStartData) context.Context
TracePrepareEnd(ctx context.Context, conn *Conn, data TracePrepareEndData)
}
type TracePrepareStartData struct {
Name string
SQL string
}
type TracePrepareEndData struct {
AlreadyPrepared bool
Err error
}
// ConnectTracer traces Connect and ConnectConfig.
type ConnectTracer interface {
// TraceConnectStart is called at the beginning of Connect and ConnectConfig calls. The returned context is used for
// the rest of the call and will be passed to TraceConnectEnd.
TraceConnectStart(ctx context.Context, data TraceConnectStartData) context.Context
TraceConnectEnd(ctx context.Context, data TraceConnectEndData)
}
type TraceConnectStartData struct {
ConnConfig *ConnConfig
}
type TraceConnectEndData struct {
Conn *Conn
Err error
}