Skip to content

Commit

Permalink
Merge pull request #30 from arthur29/extend_echo_response_time_metric…
Browse files Browse the repository at this point in the history
…s_middleware_to_accept_custom_tags

Add function to customize tags on echo ResponseTimeMetricsMiddleware
  • Loading branch information
leohahn authored Nov 6, 2020
2 parents edb8313 + 09d17d1 commit b0762c3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion echo/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const metricName = "response_time_milliseconds"

// ResponseTimeMetricsMiddleware struct encapsulating DDStatsD
type ResponseTimeMetricsMiddleware struct {
DDStatsD *middleware.DogStatsD
DDStatsD *middleware.DogStatsD
AddCustomTags func(echo.Context) []string
}

//ResponseTimeMetricsMiddleware is a middleware to measure the response time
Expand All @@ -35,6 +36,10 @@ func (responseTimeMiddleware ResponseTimeMetricsMiddleware) Serve(next echo.Hand
if gameID != "" {
tags = append(tags, fmt.Sprintf("game:%s", gameID))
}
if responseTimeMiddleware.AddCustomTags != nil {
customizedTags := responseTimeMiddleware.AddCustomTags(c)
tags = append(tags, customizedTags...)
}

responseTimeMiddleware.DDStatsD.Timing(metricName, timeUsed, tags...)

Expand Down

0 comments on commit b0762c3

Please sign in to comment.