add requests/errors to stats
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/debug/stats"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"github.com/micro/go-micro/server"
|
||||
)
|
||||
|
||||
type clientWrapper struct {
|
||||
@@ -55,3 +57,19 @@ func FromService(name string, c client.Client) client.Client {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// HandlerStats wraps a server handler to generate request/error stats
|
||||
func HandlerStats(stats stats.Stats) server.HandlerWrapper {
|
||||
// return a handler wrapper
|
||||
return func(h server.HandlerFunc) server.HandlerFunc {
|
||||
// return a function that returns a function
|
||||
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||
// execute the handler
|
||||
err := h(ctx, req, rsp)
|
||||
// record the stats
|
||||
stats.Record(err)
|
||||
// return the error
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user