@@ -74,9 +74,9 @@ type MiddlewareConfig struct {
74
74
75
75
timeNow func () time.Time
76
76
77
- // If DoNotUseURLFor404 is true, all 404 responses (due to non-matching route) will have the same `url` label and
77
+ // If DoNotUseRequestPathFor404 is true, all 404 responses (due to non-matching route) will have the same `url` label and
78
78
// thus won't generate new metrics.
79
- DoNotUseURLFor404 bool
79
+ DoNotUseRequestPathFor404 bool
80
80
}
81
81
82
82
type LabelValueFunc func (c echo.Context , err error ) string
@@ -250,7 +250,7 @@ func (conf MiddlewareConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
250
250
}
251
251
252
252
url := c .Path () // contains route path ala `/users/:id`
253
- if url == "" {
253
+ if url == "" && ! conf . DoNotUseRequestPathFor404 {
254
254
// as of Echo v4.10.1 path is empty for 404 cases (when router did not find any matching routes)
255
255
// in this case we use actual path from request to have some distinction in Prometheus
256
256
url = c .Request ().URL .Path
@@ -271,10 +271,7 @@ func (conf MiddlewareConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
271
271
values [0 ] = strconv .Itoa (status )
272
272
values [1 ] = c .Request ().Method
273
273
values [2 ] = c .Request ().Host
274
- // as of Echo v4.10.1 an empty c.Path() means the router did not find any matching routes (404)
275
- if c .Path () != "" || ! conf .DoNotUseURLFor404 {
276
- values [3 ] = url
277
- }
274
+ values [3 ] = url
278
275
for _ , cv := range customValuers {
279
276
values [cv .index ] = cv .valueFunc (c , err )
280
277
}
0 commit comments