-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
147 lines (116 loc) · 3.02 KB
/
options.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package gormopentracing
import "github.com/opentracing/opentracing-go"
type options struct {
// logResult means log SQL operation result into span log which causes span size grows up.
// This is advised to only open in developing environment.
logResult bool
// tracer allows users to use customized and different tracer to makes tracing clearly.
tracer opentracing.Tracer
// Whether to log statement parameters or leave placeholders in the queries.
logSqlParameters bool
// errorTagHook allows users to customized error what kind of error tag should be tagged.
errorTagHook errorTagHook
// createOpName defines operation name for "create" span
createOpName operationName
// updateOpName defines operation name for "update" span
updateOpName operationName
// queryOpName defines operation name for "query" span
queryOpName operationName
// deleteOpName defines operation name for "delete" span
deleteOpName operationName
// rowOpName defines operation name for "row" span
rowOpName operationName
// rawOpName defines operation name for "raw" span
rawOpName operationName
}
func defaultOption() *options {
return &options{
logResult: false,
tracer: opentracing.GlobalTracer(),
logSqlParameters: true,
errorTagHook: defaultErrorTagHook,
createOpName: _createOp,
updateOpName: _updateOp,
queryOpName: _queryOp,
deleteOpName: _deleteOp,
rowOpName: _rowOp,
rawOpName: _rawOp,
}
}
type ApplyOption func(o *options)
// WithLogResult enable opentracingPlugin to log the result of each executed sql.
func WithLogResult(logResult bool) ApplyOption {
return func(o *options) {
o.logResult = logResult
}
}
// WithTracer allows to use customized tracer rather than the global one only.
func WithTracer(tracer opentracing.Tracer) ApplyOption {
return func(o *options) {
if tracer == nil {
return
}
o.tracer = tracer
}
}
func WithSqlParameters(logSqlParameters bool) ApplyOption {
return func(o *options) {
o.logSqlParameters = logSqlParameters
}
}
func WithErrorTagHook(errorTagHook errorTagHook) ApplyOption {
return func(o *options) {
if errorTagHook == nil {
return
}
o.errorTagHook = errorTagHook
}
}
func WithCreateOpName(name operationName) ApplyOption {
return func(o *options) {
if name == "" {
return
}
o.createOpName = name
}
}
func WithUpdateOpName(name operationName) ApplyOption {
return func(o *options) {
if name == "" {
return
}
o.updateOpName = name
}
}
func WithQueryOpName(name operationName) ApplyOption {
return func(o *options) {
if name == "" {
return
}
o.queryOpName = name
}
}
func WithDeleteOpName(name operationName) ApplyOption {
return func(o *options) {
if name == "" {
return
}
o.deleteOpName = name
}
}
func WithRowOpName(name operationName) ApplyOption {
return func(o *options) {
if name == "" {
return
}
o.rowOpName = name
}
}
func WithRawOpName(name operationName) ApplyOption {
return func(o *options) {
if name == "" {
return
}
o.rawOpName = name
}
}