-
Notifications
You must be signed in to change notification settings - Fork 23
/
tracing.go
45 lines (38 loc) · 938 Bytes
/
tracing.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
package tracing
import (
"io"
"time"
"github.com/uber/jaeger-client-go"
jconfig "github.com/uber/jaeger-client-go/config"
"github.com/opentracing/opentracing-go"
)
type Options struct {
Enabled bool
Endpoint string
ServiceName string
}
// NewTracer creates a new Tracer and returns a closer which needs to be closed
// when the Tracer is no longer used to flush remaining traces.
func NewTracer(o *Options) (opentracing.Tracer, io.Closer, error) {
if o == nil {
o = new(Options)
}
cfg := jconfig.Configuration{
Disabled: !o.Enabled,
ServiceName: o.ServiceName,
Sampler: &jconfig.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jconfig.ReporterConfig{
LogSpans: true,
BufferFlushInterval: 1 * time.Second,
LocalAgentHostPort: o.Endpoint,
},
}
t, closer, err := cfg.NewTracer()
if err != nil {
return nil, nil, err
}
return t, closer, nil
}