Skip to content

Commit f8708d6

Browse files
committed
Add IgnoredPaths option
Close #100
1 parent c01eb77 commit f8708d6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ This setting will disable measuring the size of the responses. By default measur
155155

156156
This settings will disable measuring the number of requests being handled concurrently by the handlers.
157157

158+
### IgnoredPaths
159+
160+
This setting is a list of paths that will not be measured for the request duration and the response size. They will still be counted in the RequestsInflight metric.
161+
158162
#### Custom handler ID
159163

160164
One of the options that you need to pass when wrapping the handler with the middleware is `handlerID`, this has 2 working ways.

middleware/middleware.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ type Config struct {
3232
// DisableMeasureInflight will disable the recording metrics about the inflight requests number,
3333
// by default measuring inflights is enabled (`DisableMeasureInflight` is false).
3434
DisableMeasureInflight bool
35+
// IgnoredPaths is a list of paths that will not be measured for the request duration
36+
// and the response size. They will still be counted in the RequestsInflight metric.
37+
IgnoredPaths []string
3538
}
3639

3740
func (c *Config) defaults() {
@@ -87,6 +90,12 @@ func (m Middleware) Measure(handlerID string, reporter Reporter, next func()) {
8790
// Start the timer and when finishing measure the duration.
8891
start := time.Now()
8992
defer func() {
93+
for _, path := range m.cfg.IgnoredPaths {
94+
if path == reporter.URLPath() {
95+
return
96+
}
97+
}
98+
9099
duration := time.Since(start)
91100

92101
// If we need to group the status code, it uses the

0 commit comments

Comments
 (0)