11package ocsql
22
3- // TraceOption allows for functional options.
3+ // TraceOption allows for managing ocsql configuration using functional options.
44type TraceOption func (o * TraceOptions )
55
66// TraceOptions holds configuration of our ocsql tracing middleware.
7+ // By default all options are set to false intentionally when creating a wrapped
8+ // driver and provide the most sensible default with both performance and
9+ // security in mind.
710type TraceOptions struct {
8- AllowRoot bool
9- Transaction bool
10- Ping bool
11- RowsNext bool
12- RowsClose bool
11+ // AllowRoot, if set to true, will allow ocsql to create root spans in
12+ // absence of exisiting spans or even context.
13+ // Default is to not trace ocsql calls if no existing parent span is found
14+ // in context or when using methods not taking context.
15+ AllowRoot bool
16+
17+ // Transaction, if set to true, will create spans for the duration of db
18+ // transactions. All spans created by the transaction's scoped queries will
19+ // become children of the transaction span.
20+ Transaction bool
21+
22+ // Ping, if set to true, will enable the creation of spans on Ping requests.
23+ Ping bool
24+
25+ // RowsNext, if set to true, will enable the creation of spans on RowsNext
26+ // calls. This can result in many spans.
27+ RowsNext bool
28+
29+ // RowsClose, if set to true, will enable the creation of spans on RowsClose
30+ // calls.
31+ RowsClose bool
32+
33+ // RowsAffected, if set to true, will enable the creation of spans on
34+ // RowsAffected calls.
1335 RowsAffected bool
36+
37+ // LastInsertID, if set to true, will enable the creation of spans on
38+ // LastInsertId calls.
1439 LastInsertID bool
15- Query bool
16- QueryParams bool
40+
41+ // Query, if set to true, will enable recording of sql queries in spans.
42+ // Only allow this if it is safe to have queries recorded with respect to
43+ // security.
44+ Query bool
45+
46+ // QueryParams, if set to true, will enable recording of parameters used
47+ // with parametrized queries. Only allow this if it is safe to have
48+ // parameters recorded with respect to security.
49+ // This setting is a noop if the Query option is set to false.
50+ QueryParams bool
1751}
1852
1953// TraceAll has all tracing options enabled.
@@ -37,65 +71,77 @@ func WithOptions(options TraceOptions) TraceOption {
3771 }
3872}
3973
40- // WithAllowRoot when set to true will allow ocsql to create root spans. If
41- // no context is provided to (the majority) of database/sql commands this will
42- // result in many single span traces.
74+ // WithAllowRoot if set to true, will allow ocsql to create root spans in
75+ // absence of exisiting spans or even context.
76+ // Default is to not trace ocsql calls if no existing parent span is found
77+ // in context or when using methods not taking context.
4378func WithAllowRoot (b bool ) TraceOption {
4479 return func (o * TraceOptions ) {
4580 o .AllowRoot = b
4681 }
4782}
4883
49- // WithTransaction enables / disables creation of transaction spans.
84+ // WithTransaction if set to true, will create spans for the duration of db
85+ // transactions. All spans created by the transaction's scoped queries will
86+ // become children of the transaction span.
5087func WithTransaction (b bool ) TraceOption {
5188 return func (o * TraceOptions ) {
5289 o .Transaction = b
5390 }
5491}
5592
56- // WithPing enables / disables tracing of database Ping calls .
93+ // WithPing if set to true, will enable the creation of spans on Ping requests .
5794func WithPing (b bool ) TraceOption {
5895 return func (o * TraceOptions ) {
5996 o .Ping = b
6097 }
6198}
6299
63- // WithRowsNext enables / disables tracing of database Rows.Next calls.
100+ // WithRowsNext if set to true, will enable the creation of spans on RowsNext
101+ // calls. This can result in many spans.
64102func WithRowsNext (b bool ) TraceOption {
65103 return func (o * TraceOptions ) {
66104 o .RowsNext = b
67105 }
68106}
69107
70- // WithRowsClose enables / disables tracing of database Rows.Close calls.
108+ // WithRowsClose if set to true, will enable the creation of spans on RowsClose
109+ // calls.
71110func WithRowsClose (b bool ) TraceOption {
72111 return func (o * TraceOptions ) {
73112 o .RowsClose = b
74113 }
75114}
76115
77- // WithRowsAffected enables / disables tracing of database Result.RowsAffected calls.
116+ // WithRowsAffected if set to true, will enable the creation of spans on
117+ // RowsAffected calls.
78118func WithRowsAffected (b bool ) TraceOption {
79119 return func (o * TraceOptions ) {
80120 o .RowsAffected = b
81121 }
82122}
83123
84- // WithLastInsertID enables / disables tracing of database Result.LastInsertId calls.
124+ // WithLastInsertID if set to true, will enable the creation of spans on
125+ // LastInsertId calls.
85126func WithLastInsertID (b bool ) TraceOption {
86127 return func (o * TraceOptions ) {
87128 o .LastInsertID = b
88129 }
89130}
90131
91- // WithQuery enables / disables annotating of database sql queries.
132+ // WithQuery if set to true, will enable recording of sql queries in spans.
133+ // Only allow this if it is safe to have queries recorded with respect to
134+ // security.
92135func WithQuery (b bool ) TraceOption {
93136 return func (o * TraceOptions ) {
94137 o .Query = b
95138 }
96139}
97140
98- // WithQueryParams enables / disables tracing of database query parameters.
141+ // WithQueryParams if set to true, will enable recording of parameters used
142+ // with parametrized queries. Only allow this if it is safe to have
143+ // parameters recorded with respect to security.
144+ // This setting is a noop if the Query option is set to false.
99145func WithQueryParams (b bool ) TraceOption {
100146 return func (o * TraceOptions ) {
101147 o .QueryParams = b
0 commit comments