breaking: Add Tracing.Enabled to toggle whether we do opentracing

Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.
This commit is contained in:
Kegan Dougal 2020-03-05 11:48:24 +00:00
parent cfe97cd874
commit 09719cf3b7
2 changed files with 11 additions and 8 deletions

View file

@ -64,11 +64,10 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
common.SetupStdLogging()
common.SetupHookLogging(cfg.Logging, componentName)
// TODO: Make this optional
//closer, err := cfg.SetupTracing("Dendrite" + componentName)
//if err != nil {
// logrus.WithError(err).Panicf("failed to start opentracing")
//}
closer, err := cfg.SetupTracing("Dendrite" + componentName)
if err != nil {
logrus.WithError(err).Panicf("failed to start opentracing")
}
var kafkaConsumer sarama.Consumer
var kafkaProducer sarama.SyncProducer
@ -80,7 +79,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
return &BaseDendrite{
componentName: componentName,
//tracerCloser: closer,
tracerCloser: closer,
Cfg: cfg,
APIMux: mux.NewRouter().UseEncodedPath(),
KafkaConsumer: kafkaConsumer,
@ -90,8 +89,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
// Close implements io.Closer
func (b *BaseDendrite) Close() error {
return nil
// return b.tracerCloser.Close()
return b.tracerCloser.Close()
}
// CreateHTTPAppServiceAPIs returns the QueryAPI for hitting the appservice

View file

@ -224,6 +224,8 @@ type Dendrite struct {
// The config for tracing the dendrite servers.
Tracing struct {
// Set to true to enable tracer hooks. If false, no tracing is set up.
Enabled bool `yaml:"enabled"`
// The config for the jaeger opentracing reporter.
Jaeger jaegerconfig.Configuration `yaml:"jaeger"`
} `yaml:"tracing"`
@ -703,6 +705,9 @@ func (config *Dendrite) FederationSenderURL() string {
// SetupTracing configures the opentracing using the supplied configuration.
func (config *Dendrite) SetupTracing(serviceName string) (closer io.Closer, err error) {
if !config.Tracing.Enabled {
return ioutil.NopCloser(bytes.NewReader([]byte{})), nil
}
return config.Tracing.Jaeger.InitGlobalTracer(
serviceName,
jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}),