Skip to content

Commit 6bef4b9

Browse files
authored
feat: add req method to http metrics middleware (#153)
1 parent a88a708 commit 6bef4b9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

http/middleware/middleware.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ func WithStats(name string, s *statter.Statter, h http.Handler) http.Handler {
7272
)
7373

7474
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
75-
t := make([]statter.Tag, 1, 3)
75+
t := make([]statter.Tag, 2, 4)
7676
if name == "" {
7777
name = req.URL.Path
7878
}
7979
t[0] = tags.Str("handler", name)
80+
t[1] = tags.Str("method", req.Method)
8081

8182
s.Counter("requests", t...).Inc(1)
8283

http/middleware/middleware_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ func TestStats(t *testing.T) {
9696
name: "with handler name",
9797
handlerName: "my-handler",
9898
path: "/test",
99-
wantTags: [][2]string{{"handler", "my-handler"}},
99+
wantTags: [][2]string{{"handler", "my-handler"}, {"method", "GET"}},
100100
},
101101
{
102102
name: "without handler name",
103103
path: "/test",
104-
wantTags: [][2]string{{"handler", "/test"}},
104+
wantTags: [][2]string{{"handler", "/test"}, {"method", "GET"}},
105105
},
106106
}
107107

0 commit comments

Comments
 (0)