-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoptions.go
145 lines (124 loc) · 4.48 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
package zipkinsql
import (
"github.com/openzipkin/zipkin-go/model"
)
// TraceOption allows for managing zipkinsql configuration using functional options.
type TraceOption func(o *TraceOptions)
// TraceOptions holds configuration of our zipkinsql tracing middleware.
// By default all boolean options are set to false intentionally when creating
// a wrapped driver and provide the most sensible default with both performance
// and security in mind.
type TraceOptions struct {
// AllowRoot, if set to true, will allow zipkinsql to create root spans in
// absence of existing spans or even context.
// Default is to not trace zipkinsql calls if no existing parent span is found
// in context or when using methods not taking context.
AllowRootSpan bool
// LastInsertIDSpan, if set to true, will enable the creation of spans on
// LastInsertId calls.
LastInsertIDSpan bool
// RowsAffectedSpan, if set to true, will enable the creation of spans on
// RowsAffectedSpan calls.
RowsAffectedSpan bool
// TagQuery, if set to true, will enable recording of sql queries in spans.
// Only allow this if it is safe to have queries recorded with respect to
// security.
TagQuery bool
// TagQueryParams, if set to true, will enable recording of parameters used
// with parametrized queries. Only allow this if it is safe to have
// parameters recorded with respect to security and privacy.
// This setting is a noop if the TagQuery option is set to false.
TagQueryParams bool
// TagAffectedRows, if set to true, will enable the recording of the number of
// affected rows for the query. Some engines may include this in the response
// of the query but some require an extra query to obtain the number of affected
// rows.
TagAffectedRows bool
// DefaultTags will be set to each span as default.
DefaultTags map[string]string
// RemoteEndpoint will include the remote endpoint information into the client
// span.
RemoteEndpoint *model.Endpoint
}
// WithAllTraceOptions enables all available trace options.
func WithAllTraceOptions() TraceOption {
return func(o *TraceOptions) {
*o = AllTraceOptions
}
}
// AllTraceOptions has all tracing options enabled.
var AllTraceOptions = TraceOptions{
AllowRootSpan: true,
RowsAffectedSpan: true,
LastInsertIDSpan: true,
TagQuery: true,
TagQueryParams: true,
TagAffectedRows: true,
RemoteEndpoint: nil,
}
// WithOptions sets the zipkinsql tracing middleware options through a single
// TraceOptions object.
func WithOptions(options TraceOptions) TraceOption {
return func(o *TraceOptions) {
*o = options
}
}
// WithAllowRootSpan if set to true, will allow zipkinsql to create root spans in
// absence of exisiting spans or even context.
// Default is to not trace zipkinsql calls if no existing parent span is found
// in context or when using methods not taking context.
func WithAllowRootSpan(b bool) TraceOption {
return func(o *TraceOptions) {
o.AllowRootSpan = b
}
}
// WithRowsAffectedSpan if set to true, will enable the creation of spans on
// RowsAffected calls.
func WithRowsAffectedSpan(b bool) TraceOption {
return func(o *TraceOptions) {
o.RowsAffectedSpan = b
}
}
// WithLastInsertIDSpan if set to true, will enable the creation of spans on
// LastInsertId calls.
func WithLastInsertIDSpan(b bool) TraceOption {
return func(o *TraceOptions) {
o.LastInsertIDSpan = b
}
}
// WithTagQuery if set to true, will enable recording of SQL queries in spans.
// Only allow this if it is safe to have queries recorded with respect to
// security.
func WithTagQuery(b bool) TraceOption {
return func(o *TraceOptions) {
o.TagQuery = b
}
}
// WithTagQueryParams if set to true, will enable recording of parameters used
// with parametrized queries. Only allow this if it is safe to have
// parameters recorded with respect to security.
// This setting is a noop if the TagQuery option is set to false.
func WithTagQueryParams(b bool) TraceOption {
return func(o *TraceOptions) {
o.TagQueryParams = b
}
}
// WithTagAffectedRows if set to true, will enable recording of the affected rows
// number in spans.
func WithTagAffectedRows(b bool) TraceOption {
return func(o *TraceOptions) {
o.TagAffectedRows = b
}
}
// WithDefaultTags will be set to each span as default.
func WithDefaultTags(tags map[string]string) TraceOption {
return func(o *TraceOptions) {
o.DefaultTags = tags
}
}
// WithRemoteEndpoint will be set to each client span
func WithRemoteEndpoint(e model.Endpoint) TraceOption {
return func(o *TraceOptions) {
o.RemoteEndpoint = &e
}
}