This repository has been archived by the owner on May 27, 2021. It is now read-only.
forked from DataDog/dd-trace-go
/
query.go
183 lines (159 loc) · 4.07 KB
/
query.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package mgo
import (
"time"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"github.com/globalsign/mgo"
)
// Query is an mgo.Query instance along with the data necessary for tracing.
type Query struct {
*mgo.Query
cfg mongoConfig
}
// Iter invokes and traces Query.Iter
func (q *Query) Iter() *Iter {
span := newChildSpanFromContext(q.cfg)
iter := q.Query.Iter()
span.Finish()
return &Iter{
Iter: iter,
cfg: q.cfg,
}
}
// All invokes and traces Query.All
func (q *Query) All(result interface{}) error {
span := newChildSpanFromContext(q.cfg)
err := q.All(result)
span.Finish(tracer.WithError(err))
return err
}
// Apply invokes and traces Query.Apply
func (q *Query) Apply(change mgo.Change, result interface{}) (info *mgo.ChangeInfo, err error) {
span := newChildSpanFromContext(q.cfg)
info, err = q.Apply(change, result)
span.Finish(tracer.WithError(err))
return info, err
}
// Batch invokes and traces Query.Batch
func (q *Query) Batch(n int) *Query {
return &Query{
Query: q.Query.Batch(n),
cfg: q.cfg,
}
}
// Collation invokes and traces Query.Collation
func (q *Query) Collation(collation *mgo.Collation) *Query {
return &Query{
Query: q.Query.Collation(collation),
cfg: q.cfg,
}
}
// Comment invokes and traces Query.Comment
func (q *Query) Comment(comment string) *Query {
return &Query{
Query: q.Query.Comment(comment),
cfg: q.cfg,
}
}
// Count invokes and traces Query.Count
func (q *Query) Count() (n int, err error) {
span := newChildSpanFromContext(q.cfg)
n, err = q.Count()
span.Finish(tracer.WithError(err))
return n, err
}
// Distinct invokes and traces Query.Distinct
func (q *Query) Distinct(key string, result interface{}) error {
span := newChildSpanFromContext(q.cfg)
err := q.Distinct(key, result)
span.Finish(tracer.WithError(err))
return err
}
// Explain invokes and traces Query.Explain
func (q *Query) Explain(result interface{}) error {
span := newChildSpanFromContext(q.cfg)
err := q.Explain(result)
span.Finish(tracer.WithError(err))
return err
}
// For invokes and traces Query.For
func (q *Query) For(result interface{}, f func() error) error {
span := newChildSpanFromContext(q.cfg)
err := q.For(result, f)
span.Finish(tracer.WithError(err))
return err
}
// MapReduce invokes and traces Query.MapReduce
func (q *Query) MapReduce(job *mgo.MapReduce, result interface{}) (info *mgo.MapReduceInfo, err error) {
span := newChildSpanFromContext(q.cfg)
info, err = q.MapReduce(job, result)
span.Finish(tracer.WithError(err))
return info, err
}
// One invokes and traces Query.One
func (q *Query) One(result interface{}) error {
span := newChildSpanFromContext(q.cfg)
err := q.One(result)
span.Finish(tracer.WithError(err))
return err
}
// Prefetch invokes Query.Prefetch and configures the
// returned *Query for tracing.
func (q *Query) Prefetch(p float64) *Query {
return &Query{
Query: q.Query.Prefetch(p),
cfg: q.cfg,
}
}
// Select invokes Query.Select and configures the
// returned *Query for tracing.
func (q *Query) Select(selector interface{}) *Query {
return &Query{
Query: q.Query.Select(selector),
cfg: q.cfg,
}
}
// SetMaxScan invokes and traces Query.SetMaxScan
func (q *Query) SetMaxScan(n int) *Query {
return &Query{
Query: q.Query.SetMaxScan(n),
cfg: q.cfg,
}
}
// SetMaxTime invokes and traces Query.SetMaxTime
func (q *Query) SetMaxTime(d time.Duration) *Query {
return &Query{
Query: q.Query.SetMaxTime(d),
cfg: q.cfg,
}
}
// Skip invokes and traces Query.Skip
func (q *Query) Skip(n int) *Query {
return &Query{
Query: q.Query.Skip(n),
cfg: q.cfg,
}
}
// Snapshot invokes and traces Query.Snapshot
func (q *Query) Snapshot() *Query {
return &Query{
Query: q.Query.Snapshot(),
cfg: q.cfg,
}
}
// Sort invokes and traces Query.Sort
func (q *Query) Sort(fields ...string) *Query {
return &Query{
Query: q.Query.Sort(fields...),
cfg: q.cfg,
}
}
// Tail invokes and traces Query.Tail
func (q *Query) Tail(timeout time.Duration) *Iter {
span := newChildSpanFromContext(q.cfg)
iter := q.Query.Tail(timeout)
span.Finish()
return &Iter{
Iter: iter,
cfg: q.cfg,
}
}