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