/
pipe.go
46 lines (40 loc) · 1.01 KB
/
pipe.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
package mgo
import (
"github.com/globalsign/mgo"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
// Pipe is an mgo.Pipe instance along with the data necessary for tracing.
type Pipe struct {
*mgo.Pipe
cfg *mongoConfig
tags map[string]string
}
// Iter invokes and traces Pipe.Iter
func (p *Pipe) Iter() *Iter {
span := newChildSpanFromContext(p.cfg, p.tags)
iter := p.Pipe.Iter()
span.Finish()
return &Iter{
Iter: iter,
cfg: p.cfg,
tags: p.tags,
}
}
// All invokes and traces Pipe.All
func (p *Pipe) All(result interface{}) error {
return p.Iter().All(result)
}
// One invokes and traces Pipe.One
func (p *Pipe) One(result interface{}) (err error) {
span := newChildSpanFromContext(p.cfg, p.tags)
defer span.Finish(tracer.WithError(err))
err = p.Pipe.One(result)
return
}
// Explain invokes and traces Pipe.Explain
func (p *Pipe) Explain(result interface{}) (err error) {
span := newChildSpanFromContext(p.cfg, p.tags)
defer span.Finish(tracer.WithError(err))
err = p.Pipe.Explain(result)
return
}