-
Notifications
You must be signed in to change notification settings - Fork 3
/
jaeger.go
47 lines (40 loc) · 1.06 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 trace
import (
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
)
type Config struct {
Agent string `yaml:"agent"`
Sampling string `yaml:"sampling"`
ServiceName string `yaml:"serviceName"`
LogSpan bool `yaml:"logSpan"`
Type string `yaml:"type"`
Param float64 `yaml:"param"`
}
func New(config *Config) (opentracing.Tracer, func(), error) {
cfg := jaegercfg.Configuration{
Sampler: &jaegercfg.SamplerConfig{
SamplingServerURL: config.Sampling,
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jaegercfg.ReporterConfig{
LocalAgentHostPort: config.Agent,
LogSpans: config.LogSpan,
},
}
if config.Type != "" {
cfg.Sampler.Type = config.Type
cfg.Sampler.Param = config.Param
}
cfg.ServiceName = config.ServiceName
tracer, closer, err := cfg.NewTracer()
if err != nil {
return nil, nil, err
}
opentracing.SetGlobalTracer(tracer)
return tracer, func() {
closer.Close()
}, nil
}