-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaeger.go
66 lines (55 loc) · 1.77 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package jaeger
import (
"context"
"github.com/google/wire"
"github.com/goriller/ginny-util/graceful"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-lib/metrics"
)
// ProviderSet
var (
ProviderSet = wire.NewSet(NewConfiguration, NewJaegerTracer)
ProviderSetWithOption = wire.NewSet(NewConfiguration, NewJaegerTracerWithOption)
)
// NewConfiguration
func NewConfiguration(v *viper.Viper) (*config.Configuration, error) {
var (
err error
c = new(config.Configuration)
)
if err = v.UnmarshalKey("jaeger", c); err != nil {
return nil, errors.Wrap(err, "unmarshal jaeger configuration error")
}
return c, nil
}
// NewJaegerTracer NewJaegerTracer for current service
func NewJaegerTracer(ctx context.Context, cfg *config.Configuration) (opentracing.Tracer, error) {
return NewJaegerTracerWithOption(ctx, cfg)
}
// NewJaegerTracerWithOption
func NewJaegerTracerWithOption(ctx context.Context, cfg *config.Configuration,
opt ...config.Option) (opentracing.Tracer, error) {
// Example logger and metrics factory. Use github.com/uber/jaeger-client-go/log
// and github.com/uber/jaeger-lib/metrics respectively to bind to real logging and metrics
// frameworks.
jLogger := &stdLog{}
jMetricsFactory := metrics.NullFactory
opts := []config.Option{
config.Logger(jLogger),
config.Metrics(jMetricsFactory),
}
opts = append(opts, opt...)
// Initialize tracer with a logger and a metrics factory
tracer, closer, err := cfg.NewTracer(opts...)
if err != nil {
return nil, errors.Wrap(err, "create jaeger tracer error")
}
opentracing.SetGlobalTracer(tracer)
graceful.AddCloser(func(ctx context.Context) error {
return closer.Close()
})
return tracer, nil
}