tracer: add default context attr funcs option
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
00b3ceb468
commit
35e62fbeb0
@ -1,5 +1,5 @@
|
||||
// Package logger provides a log interface
|
||||
package logger // import "go.unistack.org/micro/v3/logger"
|
||||
package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -74,7 +74,7 @@ func NewOptions(opts ...Option) Options {
|
||||
return options
|
||||
}
|
||||
|
||||
// WithContextAttrFuncs appends default funcs for the context arrts filler
|
||||
// WithContextAttrFuncs appends default funcs for the context attrs filler
|
||||
func WithContextAttrFuncs(fncs ...ContextAttrFunc) Option {
|
||||
return func(o *Options) {
|
||||
o.ContextAttrFuncs = append(o.ContextAttrFuncs, fncs...)
|
||||
|
@ -140,6 +140,8 @@ type Options struct {
|
||||
Logger logger.Logger
|
||||
// Name of the tracer
|
||||
Name string
|
||||
// ContextAttrFuncs contains funcs that provides tracing
|
||||
ContextAttrFuncs []ContextAttrFunc
|
||||
}
|
||||
|
||||
// Option func signature
|
||||
@ -176,8 +178,9 @@ func NewSpanOptions(opts ...SpanOption) SpanOptions {
|
||||
// NewOptions returns default options
|
||||
func NewOptions(opts ...Option) Options {
|
||||
options := Options{
|
||||
Logger: logger.DefaultLogger,
|
||||
Context: context.Background(),
|
||||
Logger: logger.DefaultLogger,
|
||||
Context: context.Background(),
|
||||
ContextAttrFuncs: DefaultContextAttrFuncs,
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
|
@ -21,8 +21,11 @@ var (
|
||||
"HealthService.Ready",
|
||||
"HealthService.Version",
|
||||
}
|
||||
DefaultContextAttrFuncs []ContextAttrFunc
|
||||
)
|
||||
|
||||
type ContextAttrFunc func(ctx context.Context) []interface{}
|
||||
|
||||
func init() {
|
||||
logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs,
|
||||
func(ctx context.Context) []interface{} {
|
||||
|
Loading…
Reference in New Issue
Block a user