@ -4,6 +4,7 @@ import (
"context"
"context"
"net/http"
"net/http"
"strconv"
"strconv"
"strings"
"sync"
"sync"
"time"
"time"
@ -108,7 +109,10 @@ func newMetricsInstrumentedHandler(handler string, mh MiddlewareHandler) *metric
func ( h * metricsInstrumentedHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request , next Handler ) error {
func ( h * metricsInstrumentedHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request , next Handler ) error {
server := serverNameFromContext ( r . Context ( ) )
server := serverNameFromContext ( r . Context ( ) )
labels := prometheus . Labels { "server" : server , "handler" : h . handler }
labels := prometheus . Labels { "server" : server , "handler" : h . handler }
statusLabels := prometheus . Labels { "server" : server , "handler" : h . handler , "method" : r . Method , "code" : "" }
method := strings . ToUpper ( r . Method )
// the "code" value is set later, but initialized here to eliminate the possibility
// of a panic
statusLabels := prometheus . Labels { "server" : server , "handler" : h . handler , "method" : method , "code" : "" }
inFlight := httpMetrics . requestInFlight . With ( labels )
inFlight := httpMetrics . requestInFlight . With ( labels )
inFlight . Inc ( )
inFlight . Inc ( )
@ -154,7 +158,6 @@ func sanitizeCode(code int) string {
return "200"
return "200"
}
}
return strconv . Itoa ( code )
return strconv . Itoa ( code )
}
}
// taken from https://github.com/prometheus/client_golang/blob/6007b2b5cae01203111de55f753e76d8dac1f529/prometheus/promhttp/instrument_server.go#L298
// taken from https://github.com/prometheus/client_golang/blob/6007b2b5cae01203111de55f753e76d8dac1f529/prometheus/promhttp/instrument_server.go#L298