metrics: add context option

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-15 22:47:28 +03:00
parent 49d54f7fe6
commit 77f517a9f6

View File

@ -1,6 +1,8 @@
package metrics
import (
"context"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/metadata"
)
@ -24,6 +26,7 @@ type Options struct {
DefaultTags metadata.Metadata
TimingObjectives map[float64]float64
Logger logger.Logger
Context context.Context
}
// NewOptions prepares a set of options:
@ -33,6 +36,7 @@ func NewOptions(opt ...Option) Options {
DefaultTags: metadata.New(2),
Path: defaultPath,
TimingObjectives: defaultTimingObjectives,
Context: context.Background(),
}
for _, o := range opt {
@ -42,6 +46,13 @@ func NewOptions(opt ...Option) Options {
return opts
}
// Cntext sets the metrics context
func Context(ctx context.Context) Option {
return func(o *Options) {
o.Context = ctx
}
}
// Path used to serve metrics over HTTP:
func Path(value string) Option {
return func(o *Options) {