forked from DataDog/dd-trace-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
107 lines (92 loc) · 2.81 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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.
package mgo
import (
"time"
"github.com/zleague/dd-trace-go/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
tags map[string]string
}
// Iter invokes and traces Query.Iter
func (q *Query) Iter() *Iter {
span := newChildSpanFromContext(q.cfg, q.tags)
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, q.tags)
err := q.Query.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, q.tags)
info, err = q.Query.Apply(change, result)
span.Finish(tracer.WithError(err))
return info, err
}
// Count invokes and traces Query.Count
func (q *Query) Count() (n int, err error) {
span := newChildSpanFromContext(q.cfg, q.tags)
n, err = q.Query.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, q.tags)
err := q.Query.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, q.tags)
err := q.Query.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, q.tags)
err := q.Query.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, q.tags)
info, err = q.Query.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, q.tags)
err := q.Query.One(result)
span.Finish(tracer.WithError(err))
return err
}
// Tail invokes and traces Query.Tail
func (q *Query) Tail(timeout time.Duration) *Iter {
span := newChildSpanFromContext(q.cfg, q.tags)
iter := q.Query.Tail(timeout)
span.Finish()
return &Iter{
Iter: iter,
cfg: q.cfg,
}
}