1// Unless explicitly stated otherwise all files in this repository are licensed
2// under the Apache License Version 2.0.
3// This product includes software developed at Datadog (https://www.datadoghq.com/).
4// Copyright 2016 Datadog, Inc.
5
6package mgo
7
8import (
9	"github.com/globalsign/mgo"
10	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
11)
12
13// Pipe is an mgo.Pipe instance along with the data necessary for tracing.
14type Pipe struct {
15	*mgo.Pipe
16	cfg  *mongoConfig
17	tags map[string]string
18}
19
20// Iter invokes and traces Pipe.Iter
21func (p *Pipe) Iter() *Iter {
22	span := newChildSpanFromContext(p.cfg, p.tags)
23	iter := p.Pipe.Iter()
24	span.Finish()
25	return &Iter{
26		Iter: iter,
27		cfg:  p.cfg,
28		tags: p.tags,
29	}
30}
31
32// All invokes and traces Pipe.All
33func (p *Pipe) All(result interface{}) error {
34	return p.Iter().All(result)
35}
36
37// One invokes and traces Pipe.One
38func (p *Pipe) One(result interface{}) (err error) {
39	span := newChildSpanFromContext(p.cfg, p.tags)
40	defer span.Finish(tracer.WithError(err))
41	err = p.Pipe.One(result)
42	return
43}
44
45// Explain invokes and traces Pipe.Explain
46func (p *Pipe) Explain(result interface{}) (err error) {
47	span := newChildSpanFromContext(p.cfg, p.tags)
48	defer span.Finish(tracer.WithError(err))
49	err = p.Pipe.Explain(result)
50	return
51}
52