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 9d20dfec..f092c549 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 @@ -31,13 +31,6 @@ func main() { federation := base.CreateFederationClient() - /* TODO delete - err = tracers.InitGlobalTracer("Dendrite - Federation Sender") - if err != nil { - log.WithError(err).Fatalf("Failed to start tracer") - } - */ - _, _, query := base.CreateHTTPRoomserverAPIs() federationsender.SetupFederationSenderComponent( diff --git a/src/github.com/matrix-org/dendrite/common/httpapi.go b/src/github.com/matrix-org/dendrite/common/httpapi.go index 327b4d33..5a584f20 100644 --- a/src/github.com/matrix-org/dendrite/common/httpapi.go +++ b/src/github.com/matrix-org/dendrite/common/httpapi.go @@ -18,7 +18,7 @@ type statusCodeResponseWriter struct { statusCode int } -func NewStatusCodeResponseWriter(w http.ResponseWriter) *statusCodeResponseWriter { +func newStatusCodeResponseWriter(w http.ResponseWriter) *statusCodeResponseWriter { return &statusCodeResponseWriter{w, http.StatusOK} } @@ -60,7 +60,7 @@ func MakeExternalAPI(tracer opentracing.Tracer, metricsName string, f func(*http ext.HTTPMethod.Set(span, req.Method) req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span)) - rw := NewStatusCodeResponseWriter(w) + rw := newStatusCodeResponseWriter(w) h.ServeHTTP(w, req) ext.HTTPStatusCode.Set(span, uint16(rw.statusCode)) @@ -91,7 +91,7 @@ func MakeInternalAPI(tracer opentracing.Tracer, metricsName string, f func(*http ext.HTTPUrl.Set(span, req.URL.String()) ext.HTTPMethod.Set(span, req.Method) - // TODO: Do we need to do the NewStatusCodeResponseWriter stuff? + // TODO: Do we need to do the newStatusCodeResponseWriter stuff? req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span)) h.ServeHTTP(w, req) diff --git a/src/github.com/matrix-org/dendrite/common/tracers.go b/src/github.com/matrix-org/dendrite/common/tracers.go index 9536bc8e..a6ab6955 100644 --- a/src/github.com/matrix-org/dendrite/common/tracers.go +++ b/src/github.com/matrix-org/dendrite/common/tracers.go @@ -24,43 +24,29 @@ import ( jaegermetrics "github.com/uber/jaeger-lib/metrics" ) +// Tracers is a collection of Jaeger OpenTracing tracers. There is one tracer +// per Dendrite component, and each is kept track of with a single Tracers +// object. Upon shutdown, each tracer is closed by calling the Tracers' Close() +// method. type Tracers struct { cfg *config.Dendrite closers []io.Closer } +// NoopTracers is a Tracers object that will never contain any tracers. Disables tracing. func NoopTracers() *Tracers { return &Tracers{} } +// NewTracers creates a new Tracers object with the given Dendrite config. func NewTracers(cfg *config.Dendrite) *Tracers { return &Tracers{ cfg: cfg, } } -func (t *Tracers) InitGlobalTracer(serviceName string) error { - if t.cfg == nil { - return nil - } - - // Set up GlobalTracer - closer, err := t.cfg.Tracing.Jaeger.InitGlobalTracer( - serviceName, - jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}), - jaegerconfig.Metrics(jaegermetrics.NullFactory), - ) - - if err != nil { - return err - } - - t.closers = append(t.closers, closer) - - return nil -} - -// SetupTracing configures the opentracing using the supplied configuration. +// SetupNewTracer creates a new tracer and adds it to those being kept track of +// on the linked Tracers object. func (t *Tracers) SetupNewTracer(serviceName string) opentracing.Tracer { if t.cfg == nil { return opentracing.NoopTracer{} @@ -81,6 +67,7 @@ func (t *Tracers) SetupNewTracer(serviceName string) opentracing.Tracer { return tracer } +// Close will close all Jaeger OpenTracing tracers associated with the Tracers object. func (t *Tracers) Close() error { for _, c := range t.closers { c.Close() // nolint: errcheck @@ -94,10 +81,12 @@ type logrusLogger struct { l *logrus.Logger } +// Error prints an error message to the logger func (l logrusLogger) Error(msg string) { l.l.Error(msg) } +// Infof prints an info message with printf formatting to the logger func (l logrusLogger) Infof(msg string, args ...interface{}) { l.l.Infof(msg, args...) } diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/input.go b/src/github.com/matrix-org/dendrite/roomserver/input/input.go index 698794ed..d5fd704c 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/input.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/input.go @@ -95,17 +95,14 @@ func (r *RoomserverInputAPI) SetupHTTP(servMux *http.ServeMux, tracer opentracin ) } +// InProcessRoomServerInput is a RoomserverInput database linked with a +// OpenTracing tracer, providing metrics type InProcessRoomServerInput struct { db RoomserverInputAPI tracer opentracing.Tracer } -func NewInProcessRoomServerInput(db RoomserverInputAPI, tracer opentracing.Tracer) *InProcessRoomServerInput { - return &InProcessRoomServerInput{ - db: db, tracer: tracer, - } -} - +// InputRoomEvents is a wrapper providing opentracing metrics data around room events func (r *InProcessRoomServerInput) InputRoomEvents( ctx context.Context, request *api.InputRoomEventsRequest, diff --git a/src/github.com/matrix-org/dendrite/roomserver/query/query.go b/src/github.com/matrix-org/dendrite/roomserver/query/query.go index 80aa711e..8e36b3c6 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/query/query.go +++ b/src/github.com/matrix-org/dendrite/roomserver/query/query.go @@ -711,11 +711,14 @@ func (r *RoomserverQueryAPI) SetupHTTP(servMux *http.ServeMux, tracer opentracin ) } +// InProcessRoomServerQueryAPI is a RoomserverQueryAPI database linked with a +// OpenTracing tracer, providing metrics type InProcessRoomServerQueryAPI struct { db RoomserverQueryAPI tracer opentracing.Tracer } +// NewInProcessRoomServerQueryAPI creates a new InProcessRoomServerQueryAPI func NewInProcessRoomServerQueryAPI(db RoomserverQueryAPI, tracer opentracing.Tracer) InProcessRoomServerQueryAPI { return InProcessRoomServerQueryAPI{ db: db,