-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.go
70 lines (61 loc) · 1.57 KB
/
builder.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
package bjaeger
import (
"container/list"
"github.com/go-masonry/mortar/interfaces/trace"
"github.com/uber/jaeger-client-go/config"
)
// JaegerBuilder is a builder that will help you configure jaeger
type JaegerBuilder interface {
SetServiceName(name string) JaegerBuilder
AddOptions(options ...config.Option) JaegerBuilder
SetCustomConfig(custom *config.Configuration) JaegerBuilder
Build() (trace.OpenTracer, error)
}
type jaegerConfig struct {
name string
options []config.Option
conf *config.Configuration
}
type jaegerBuilder struct {
ll *list.List
}
// Builder start building Jaeger instance
func Builder() JaegerBuilder {
return &jaegerBuilder{
ll: list.New(),
}
}
func (jb *jaegerBuilder) SetServiceName(name string) JaegerBuilder {
jb.ll.PushBack(func(cfg *jaegerConfig) {
cfg.name = name
})
return jb
}
func (jb *jaegerBuilder) AddOptions(options ...config.Option) JaegerBuilder {
jb.ll.PushBack(func(cfg *jaegerConfig) {
cfg.options = append(cfg.options, options...)
})
return jb
}
func (jb *jaegerBuilder) SetCustomConfig(custom *config.Configuration) JaegerBuilder {
jb.ll.PushBack(func(cfg *jaegerConfig) {
cfg.conf = custom
})
return jb
}
func (jb *jaegerBuilder) Build() (instance trace.OpenTracer, err error) {
cfg := new(jaegerConfig)
for e := jb.ll.Front(); e != nil; e = e.Next() {
f := e.Value.(func(config *jaegerConfig))
f(cfg)
}
if cfg.conf == nil {
if cfg.conf, err = config.FromEnv(); err != nil {
return nil, err
}
}
if len(cfg.name) > 0 {
cfg.conf.ServiceName = cfg.name // set name
}
return newWrapper(cfg), nil
}