mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 12:59:31 +00:00
Changes: - Default diff-printer to hide details (#103) - da4c3ff - Improve logging of http errors (#115) - f5a1710 - Update httpgrpc to match weaveworks/cortex#910 (#117) - 80ff076 - Expose the HTTP server from the server struct. (#118) - 1a7a6b3 - Add HTTP tracing middleware (#119) - d442d08
28 lines
717 B
Go
28 lines
717 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/opentracing-contrib/go-stdlib/nethttp"
|
|
"github.com/opentracing/opentracing-go"
|
|
)
|
|
|
|
// Tracer is a middleware which traces incoming requests.
|
|
type Tracer struct{}
|
|
|
|
// Wrap implements Interface
|
|
func (t Tracer) Wrap(next http.Handler) http.Handler {
|
|
traceHandler := nethttp.Middleware(opentracing.GlobalTracer(), next)
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var maybeTracer http.Handler
|
|
// Don't try and trace websocket requests because nethttp.Middleware
|
|
// doesn't support http.Hijack yet
|
|
if IsWSHandshakeRequest(r) {
|
|
maybeTracer = next
|
|
} else {
|
|
maybeTracer = traceHandler
|
|
}
|
|
maybeTracer.ServeHTTP(w, r)
|
|
})
|
|
}
|