2020-04-29 21:32:39 +00:00
|
|
|
// Package tracing sets up jaeger as an opentracing tool
|
|
|
|
// for services in Prysm.
|
2019-02-28 03:55:47 +00:00
|
|
|
package tracing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2019-04-25 15:59:18 +00:00
|
|
|
"contrib.go.opencensus.io/exporter/jaeger"
|
2019-05-11 21:43:55 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
2019-02-28 03:55:47 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"go.opencensus.io/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
var log = logrus.WithField("prefix", "tracing")
|
|
|
|
|
|
|
|
// Setup creates and initializes a new tracing configuration..
|
2019-05-11 21:43:55 +00:00
|
|
|
func Setup(serviceName, processName, endpoint string, sampleFraction float64, enable bool) error {
|
2019-02-28 03:55:47 +00:00
|
|
|
if !enable {
|
|
|
|
trace.ApplyConfig(trace.Config{DefaultSampler: trace.NeverSample()})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-11 21:43:55 +00:00
|
|
|
if serviceName == "" {
|
2019-02-28 03:55:47 +00:00
|
|
|
return errors.New("tracing service name cannot be empty")
|
|
|
|
}
|
|
|
|
|
2019-05-11 21:43:55 +00:00
|
|
|
trace.ApplyConfig(trace.Config{
|
|
|
|
DefaultSampler: trace.ProbabilitySampler(sampleFraction),
|
|
|
|
MaxMessageEventsPerSpan: 500,
|
|
|
|
})
|
2019-02-28 03:55:47 +00:00
|
|
|
|
|
|
|
log.Infof("Starting Jaeger exporter endpoint at address = %s", endpoint)
|
|
|
|
exporter, err := jaeger.NewExporter(jaeger.Options{
|
2019-05-11 21:43:55 +00:00
|
|
|
CollectorEndpoint: endpoint,
|
2019-02-28 03:55:47 +00:00
|
|
|
Process: jaeger.Process{
|
2019-05-11 21:43:55 +00:00
|
|
|
ServiceName: serviceName,
|
|
|
|
Tags: []jaeger.Tag{
|
|
|
|
jaeger.StringTag("process_name", processName),
|
|
|
|
jaeger.StringTag("version", version.GetVersion()),
|
|
|
|
},
|
|
|
|
},
|
2019-08-13 02:50:47 +00:00
|
|
|
BufferMaxCount: 10000,
|
2019-05-11 21:43:55 +00:00
|
|
|
OnError: func(err error) {
|
|
|
|
log.WithError(err).Error("Failed to process span")
|
2019-02-28 03:55:47 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
trace.RegisterExporter(exporter)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|