diff --git a/dendrite-config.yaml b/dendrite-config.yaml index c94960a44..1e92f0fd5 100644 --- a/dendrite-config.yaml +++ b/dendrite-config.yaml @@ -91,3 +91,11 @@ listen: media_api: "localhost:7774" public_rooms_api: "localhost:7775" federation_sender: "localhost:7776" + +# The configuration for tracing the dendrite components. +tracing: + # Config for the jaeger opentracing reporter. + # See https://godoc.org/github.com/uber/jaeger-client-go/config#Configuration + # for documtation. + jaeger: + disabled: true diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go index 630443d32..c53735aa6 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go @@ -51,6 +51,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteClientAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil) aliasAPI := api.NewRoomserverAliasAPIHTTP(cfg.RoomServerURL(), nil) inputAPI := api.NewRoomserverInputAPIHTTP(cfg.RoomServerURL(), nil) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go index b287ea629..83ac91eac 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go @@ -50,6 +50,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteFederationAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + federation := gomatrixserverlib.NewFederationClient( cfg.Matrix.ServerName, cfg.Matrix.KeyID, cfg.Matrix.PrivateKey, ) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go index dfc2dc2ff..0b5a73ee7 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go @@ -47,6 +47,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteFederationSender") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + kafkaConsumer, err := sarama.NewConsumer(cfg.Kafka.Addresses, nil) if err != nil { log.WithFields(log.Fields{ diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go index ccbc56813..1e8b86c45 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go @@ -48,6 +48,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteMediaAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + db, err := storage.Open(string(cfg.Database.MediaAPI)) if err != nil { log.WithError(err).Panic("Failed to open database") diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go index 11920b8df..811c708ac 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go @@ -83,6 +83,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteMonolith") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + m := newMonolith(cfg) m.setupDatabases() m.setupFederation() diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go index c8e705f91..807aa0ca5 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go @@ -47,6 +47,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendritePublicRoomsAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil) db, err := storage.NewPublicRoomsServerDatabase(string(cfg.Database.PublicRoomsAPI)) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go index 9da258c0e..02988838f 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go @@ -49,6 +49,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteRoomServer") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + db, err := storage.Open(string(cfg.Database.RoomServer)) if err != nil { panic(err) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go index b57786313..ec6eebb64 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go @@ -51,6 +51,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteSyncAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil) db, err := storage.NewSyncServerDatabase(string(cfg.Database.SyncAPI)) diff --git a/src/github.com/matrix-org/dendrite/common/config/config.go b/src/github.com/matrix-org/dendrite/common/config/config.go index 2324d5134..2d347b592 100644 --- a/src/github.com/matrix-org/dendrite/common/config/config.go +++ b/src/github.com/matrix-org/dendrite/common/config/config.go @@ -19,14 +19,19 @@ import ( "crypto/sha256" "encoding/pem" "fmt" + "io" "io/ioutil" "path/filepath" "strings" "time" + "github.com/Sirupsen/logrus" "github.com/matrix-org/gomatrixserverlib" "golang.org/x/crypto/ed25519" "gopkg.in/yaml.v2" + + jaegerconfig "github.com/uber/jaeger-client-go/config" + jaegermetrics "github.com/uber/jaeger-lib/metrics" ) // Version is the current version of the config format. @@ -156,6 +161,12 @@ type Dendrite struct { FederationSender Address `yaml:"federation_sender"` PublicRoomsAPI Address `yaml:"public_rooms_api"` } `yaml:"listen"` + + // The config for tracing the dendrite servers. + Tracing struct { + // The config for the jaeger opentracing reporter. + Jaeger jaegerconfig.Configuration `yaml:"jaeger"` + } } // A Path on the filesystem. @@ -429,3 +440,25 @@ func (config *Dendrite) RoomServerURL() string { // internet for an internal API. return "http://" + string(config.Listen.RoomServer) } + +// SetupTracing configures the opentracing using the supplied configuration. +func (config *Dendrite) SetupTracing(serviceName string) (closer io.Closer, err error) { + return config.Tracing.Jaeger.InitGlobalTracer( + serviceName, + jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}), + jaegerconfig.Metrics(jaegermetrics.NullFactory), + ) +} + +// logrusLogger is a small wrapper that implements jaeger.Logger using logrus. +type logrusLogger struct { + l *logrus.Logger +} + +func (l logrusLogger) Error(msg string) { + l.l.Error(msg) +} + +func (l logrusLogger) Infof(msg string, args ...interface{}) { + l.l.Infof(msg, args...) +}