File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,31 @@ import (
88 "github.com/prometheus/client_golang/prometheus"
99)
1010
11+ // responseWriterWrapper is a custom response writer that captures the status code
12+ type responseWriterWrapper struct {
13+ w http.ResponseWriter
14+ statusCode int
15+ }
16+
17+ func (rww * responseWriterWrapper ) Header () http.Header {
18+ return rww .w .Header ()
19+ }
20+
21+ func (rww * responseWriterWrapper ) Write (bytes []byte ) (int , error ) {
22+ return rww .w .Write (bytes )
23+ }
24+
25+ func (rww * responseWriterWrapper ) WriteHeader (statusCode int ) {
26+ rww .statusCode = statusCode
27+ rww .w .WriteHeader (statusCode )
28+ }
29+
30+ func (rww * responseWriterWrapper ) Flush () {
31+ if f , ok := rww .w .(http.Flusher ); ok {
32+ f .Flush ()
33+ }
34+ }
35+
1136// MetricsMiddleware adds Prometheus metrics to HTTP requests
1237func MetricsMiddleware (requestCounter * prometheus.CounterVec , requestDuration * prometheus.HistogramVec , activeRequests prometheus.Gauge ) func (http.Handler ) http.Handler {
1338 return func (next http.Handler ) http.Handler {
You can’t perform that action at this time.
0 commit comments