aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/http/middleware.go
diff options
context:
space:
mode:
authorElad <theman@elad.im>2018-12-11 16:21:58 +0800
committerAnton Evangelatov <anton.evangelatov@gmail.com>2018-12-11 16:21:58 +0800
commitbb724080cac9fa36ec6b638cfd5cf0e54bc23362 (patch)
tree355425051728e3c3dd89565feefc46a81a3302f7 /swarm/api/http/middleware.go
parentb2aac658b0e366f128eda5e057e8e1bf5ec4e427 (diff)
downloadgo-tangerine-bb724080cac9fa36ec6b638cfd5cf0e54bc23362.tar
go-tangerine-bb724080cac9fa36ec6b638cfd5cf0e54bc23362.tar.gz
go-tangerine-bb724080cac9fa36ec6b638cfd5cf0e54bc23362.tar.bz2
go-tangerine-bb724080cac9fa36ec6b638cfd5cf0e54bc23362.tar.lz
go-tangerine-bb724080cac9fa36ec6b638cfd5cf0e54bc23362.tar.xz
go-tangerine-bb724080cac9fa36ec6b638cfd5cf0e54bc23362.tar.zst
go-tangerine-bb724080cac9fa36ec6b638cfd5cf0e54bc23362.zip
cmd/swarm, metrics, swarm/api/client, swarm/storage, swarm/metrics, swarm/api/http: add instrumentation (#18274)
Diffstat (limited to 'swarm/api/http/middleware.go')
-rw-r--r--swarm/api/http/middleware.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/swarm/api/http/middleware.go b/swarm/api/http/middleware.go
index 115a00856..f7f819eab 100644
--- a/swarm/api/http/middleware.go
+++ b/swarm/api/http/middleware.go
@@ -74,13 +74,15 @@ func ParseURI(h http.Handler) http.Handler {
func InitLoggingResponseWriter(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- startTime := time.Now()
- defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.time", r.Method), nil).UpdateSince(startTime)
+ tn := time.Now()
writer := newLoggingResponseWriter(w)
h.ServeHTTP(writer, r)
- log.Info("request served", "ruid", GetRUID(r.Context()), "code", writer.statusCode)
- metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.%d.time", r.Method, writer.statusCode), nil).UpdateSince(startTime)
+
+ ts := time.Since(tn)
+ log.Info("request served", "ruid", GetRUID(r.Context()), "code", writer.statusCode, "time", ts*time.Millisecond)
+ metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.time", r.Method), nil).Update(ts)
+ metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.%d.time", r.Method, writer.statusCode), nil).Update(ts)
})
}
@@ -93,6 +95,7 @@ func InstrumentOpenTracing(h http.Handler) http.Handler {
}
spanName := fmt.Sprintf("http.%s.%s", r.Method, uri.Scheme)
ctx, sp := spancontext.StartSpan(r.Context(), spanName)
+
defer sp.Finish()
h.ServeHTTP(w, r.WithContext(ctx))
})