Skip to content

Instantly share code, notes, and snippets.

@mehmetcemyucel
Created April 28, 2022 20:43
Show Gist options
  • Select an option

  • Save mehmetcemyucel/42685e8b6b931afb5d754e6f1a2994ca to your computer and use it in GitHub Desktop.

Select an option

Save mehmetcemyucel/42685e8b6b931afb5d754e6f1a2994ca to your computer and use it in GitHub Desktop.
package service
import (
"fmt"
"github.com/go-kit/kit/metrics"
"helloWorld/pkg/model/example/dto/request"
"helloWorld/pkg/model/example/entity"
"time"
)
type ExampleInstrumentingMiddleware struct {
RequestCount metrics.Counter
RequestLatency metrics.Histogram
CountResult metrics.Histogram
Next IExampleService
}
func (mw ExampleInstrumentingMiddleware) Check(trx request.ExampleReq) (output []entity.Example, err error) {
defer func(begin time.Time) {
lvs := []string{"method", "Check", "error", fmt.Sprint(err != nil)}
mw.RequestCount.With(lvs...).Add(1)
mw.RequestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
}(time.Now())
output, err = mw.Next.Check(trx)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment