prysm-pulse/shared/tracing/tracer.go

54 lines
1.3 KiB
Go
Raw Normal View History

// 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"
"contrib.go.opencensus.io/exporter/jaeger"
"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..
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
}
if serviceName == "" {
2019-02-28 03:55:47 +00:00
return errors.New("tracing service name cannot be empty")
}
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{
CollectorEndpoint: endpoint,
2019-02-28 03:55:47 +00:00
Process: jaeger.Process{
ServiceName: serviceName,
Tags: []jaeger.Tag{
jaeger.StringTag("process_name", processName),
jaeger.StringTag("version", version.GetVersion()),
},
},
BufferMaxCount: 10000,
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
}