-
Notifications
You must be signed in to change notification settings - Fork 0
/
observer.go
52 lines (44 loc) · 1.32 KB
/
observer.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
package zipkintracer
import (
otobserver "github.com/opentracing-contrib/go-observer"
opentracing "github.com/opentracing/opentracing-go"
)
// observer is a dispatcher to other observers
type observer struct {
observers []otobserver.Observer
}
// spanObserver is a dispatcher to other span observers
type spanObserver struct {
observers []otobserver.SpanObserver
}
func (o observer) OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (otobserver.SpanObserver, bool) {
var spanObservers []otobserver.SpanObserver
for _, obs := range o.observers {
spanObs, ok := obs.OnStartSpan(sp, operationName, options)
if ok {
if spanObservers == nil {
spanObservers = make([]otobserver.SpanObserver, 0, len(o.observers))
}
spanObservers = append(spanObservers, spanObs)
}
}
if len(spanObservers) == 0 {
return nil, false
}
return spanObserver{observers: spanObservers}, true
}
func (o spanObserver) OnSetOperationName(operationName string) {
for _, obs := range o.observers {
obs.OnSetOperationName(operationName)
}
}
func (o spanObserver) OnSetTag(key string, value interface{}) {
for _, obs := range o.observers {
obs.OnSetTag(key, value)
}
}
func (o spanObserver) OnFinish(options opentracing.FinishOptions) {
for _, obs := range o.observers {
obs.OnFinish(options)
}
}