Skip to content

Commit

Permalink
use gin.Context.FullPath method instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Sniper91 committed Nov 17, 2022
1 parent 2199a42 commit ea3ba12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,7 @@ func main() {
p := ginprometheus.NewPrometheus("gin")

p.ReqCntURLLabelMappingFn = func(c *gin.Context) string {
url := c.Request.URL.Path
for _, p := range c.Params {
if p.Key == "name" {
url = strings.Replace(url, p.Value, ":name", 1)
break
}
}
return url
return c.FullPath()
}

p.Use(r)
Expand Down
12 changes: 3 additions & 9 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
var defaultMetricPath = "/metrics"

// Standard default metrics
//
// counter, counter_vec, gauge, gauge_vec,
// histogram, histogram_vec, summary, summary_vec
var reqCnt = &Metric{
Expand Down Expand Up @@ -59,16 +60,9 @@ the cardinality of the request counter's "url" label, which might be required in
For instance, if for a "/customer/:name" route you don't want to generate a time series for every
possible customer name, you could use this function:
func(c *gin.Context) string {
url := c.Request.URL.Path
for _, p := range c.Params {
if p.Key == "name" {
url = strings.Replace(url, p.Value, ":name", 1)
break
}
func(c *gin.Context) string {
return c.FullPath()
}
return url
}
which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".
*/
Expand Down

0 comments on commit ea3ba12

Please sign in to comment.