Example #1
0
func timedHandler(fn func(w http.ResponseWriter, r *http.Request), stats statsd.Statter) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()
		fn(w, r)
		stats.TimingDuration("request", time.Since(start), 1)
	}
}
// Emit successful actions as `$action.success.$event-name`
func EmitActionSuccessTiming(stats statsd.Statter, action, eventName string, took time.Duration) (err error) {
	action = CleanStatsdComponent(action)
	eventName = CleanStatsdComponent(eventName)
	if stats != nil {
		err = stats.TimingDuration(StatsdEventName(action, eventName), took, StatsSampleRate)
	}
	return
}