-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
jaeger.go
47 lines (38 loc) · 1.02 KB
/
jaeger.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
package jaeger
import (
"io"
"github.com/opentracing/opentracing-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
)
// NewTracer returns a new Jaeger tracer based on the current configuration,
// using the given options, and a closer func that can be used to flush buffers
// before shutdown.
func NewTracer(opts ...Option) (opentracing.Tracer, io.Closer, error) {
options := newOptions(opts...)
cfg := &jaegercfg.Configuration{}
if options.FromEnv {
c, err := jaegercfg.FromEnv()
if err != nil {
return nil, nil, err
}
cfg = c
}
if options.Name != "" {
cfg.ServiceName = options.Name
}
var jOptions []jaegercfg.Option
if options.Logger != nil {
jOptions = append(jOptions, jaegercfg.Logger(options.Logger))
}
if options.Metrics != nil {
jOptions = append(jOptions, jaegercfg.Metrics(options.Metrics))
}
tracer, closer, err := cfg.NewTracer(jOptions...)
if err != nil {
return nil, nil, err
}
if options.GlobalTracer {
opentracing.SetGlobalTracer(tracer)
}
return tracer, closer, nil
}