Skip to content

Commit

Permalink
adding should send metrics key
Browse files Browse the repository at this point in the history
  • Loading branch information
vamshiaruru32 committed Oct 25, 2024
1 parent 5caad9f commit 4eca2bd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ type Config struct {
// by default measuring inflights is enabled (`DisableMeasureInflight` is false).
DisableMeasureInflight bool
// UseChi will use the chi router to get the handler ID, by default it will be false.
UseChi bool
OrgSlugPathParamKey string
UseChi bool
OrgSlugPathParamKey string
ShouldReportMetricsKey *string
}

func (c *Config) defaults() {
Expand Down Expand Up @@ -96,6 +97,13 @@ func (m Middleware) Measure(handlerID string, reporter Reporter, next func()) {
start := time.Now()
defer func() {
duration := time.Since(start)
if m.cfg.ShouldReportMetricsKey != nil {
shouldShow, ok := reporter.Context().Value(*m.cfg.ShouldReportMetricsKey).(bool)
if ok && !shouldShow {
// no need to send metrics
return
}
}

// If we need to group the status code, it uses the
// first number of the status code because is the least
Expand Down

0 comments on commit 4eca2bd

Please sign in to comment.