-
Notifications
You must be signed in to change notification settings - Fork 3
/
sender_dummy.go
72 lines (59 loc) · 1.36 KB
/
sender_dummy.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
package main
import (
"context"
"sync"
)
type DummySender struct {
nspans int
rootspans int
log Logger
}
func NewDummySender(log Logger) *DummySender {
return &DummySender{log: log}
}
func (h *DummySender) Run(wg *sync.WaitGroup, spans chan *Span, stop chan struct{}) {
wg.Add(1)
defer wg.Done()
go func() {
for {
select {
case span := <-spans:
h.send(span)
case <-stop:
h.log.Warn("dummysender sent %d spans with %d root spans\n", h.nspans, h.rootspans)
return
}
}
}()
}
func (h *DummySender) send(span *Span) {
if span.IsRootSpan() {
h.rootspans++
}
h.nspans++
}
type DummySendable struct{}
func (s DummySendable) Send() {
}
type SenderDummy struct {
tracecount int
nspans int
log Logger
}
// make sure it implements Sender
var _ Sender = (*SenderDummy)(nil)
func NewSenderDummy(log Logger, opts *Options) Sender {
return &SenderDummy{log: log}
}
func (t *SenderDummy) Close() {
t.log.Warn("sender sent %d traces with %d spans\n", t.tracecount, t.nspans)
}
func (t *SenderDummy) CreateTrace(ctx context.Context, name string, fielder *Fielder, count int64) (context.Context, Sendable) {
t.tracecount++
t.nspans++
return ctx, DummySendable{}
}
func (t *SenderDummy) CreateSpan(ctx context.Context, name string, level int, fielder *Fielder) (context.Context, Sendable) {
t.nspans++
return ctx, DummySendable{}
}