Created
April 28, 2022 20:43
-
-
Save mehmetcemyucel/42685e8b6b931afb5d754e6f1a2994ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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