forked from gomods/athens
/
tracing.go
41 lines (36 loc) · 1.07 KB
/
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
package actions
import (
"log"
"time"
"github.com/bketelsen/buffet"
"github.com/gobuffalo/buffalo"
opentracing "github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-client-go/rpcmetrics"
"github.com/uber/jaeger-lib/metrics/prometheus"
)
func initializeTracing(app *buffalo.App) {
cfg := config.Configuration{
Sampler: &config.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: &config.ReporterConfig{
LogSpans: true,
BufferFlushInterval: 1 * time.Second,
LocalAgentHostPort: "0.0.0.0:6831", //hostPort,
},
}
// TODO(ys) a quick hack to ensure random generators get different seeds, which are based on current time.
time.Sleep(100 * time.Millisecond)
metricsFactory := prometheus.New()
tracer, _, err := cfg.New(
"athens", //serviceName,
config.Observer(rpcmetrics.NewObserver(metricsFactory, rpcmetrics.DefaultNameNormalizer)),
)
if err != nil {
log.Fatal("cannot initialize Jaeger Tracer", err)
}
opentracing.SetGlobalTracer(tracer)
app.Use(buffet.OpenTracing(tracer))
}