mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-28 14:17:17 +00:00
40 lines
887 B
Go
40 lines
887 B
Go
package tracing
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"go.opencensus.io/exporter/jaeger"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
var log = logrus.WithField("prefix", "tracing")
|
|
|
|
// Setup creates and initializes a new tracing configuration..
|
|
func Setup(name, endpoint string, sampleFraction float64, enable bool) error {
|
|
if !enable {
|
|
trace.ApplyConfig(trace.Config{DefaultSampler: trace.NeverSample()})
|
|
return nil
|
|
}
|
|
|
|
if name == "" {
|
|
return errors.New("tracing service name cannot be empty")
|
|
}
|
|
|
|
trace.ApplyConfig(trace.Config{DefaultSampler: trace.ProbabilitySampler(sampleFraction)})
|
|
|
|
log.Infof("Starting Jaeger exporter endpoint at address = %s", endpoint)
|
|
exporter, err := jaeger.NewExporter(jaeger.Options{
|
|
Endpoint: endpoint,
|
|
Process: jaeger.Process{
|
|
ServiceName: name,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
trace.RegisterExporter(exporter)
|
|
|
|
return nil
|
|
}
|