From 35e62fbeb0d23bb311dce59f6965d9ddac5d6a8b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 6 Jul 2024 00:09:27 +0300 Subject: [PATCH] tracer: add default context attr funcs option Signed-off-by: Vasiliy Tolstov --- logger/logger.go | 2 +- logger/options.go | 2 +- tracer/options.go | 7 +++++-- tracer/tracer.go | 3 +++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index 71dcc2d2..175311bc 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -1,5 +1,5 @@ // Package logger provides a log interface -package logger // import "go.unistack.org/micro/v3/logger" +package logger import ( "context" diff --git a/logger/options.go b/logger/options.go index cd3b9f26..a7008868 100644 --- a/logger/options.go +++ b/logger/options.go @@ -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...) diff --git a/tracer/options.go b/tracer/options.go index 98c4d3a7..1c67e1e8 100644 --- a/tracer/options.go +++ b/tracer/options.go @@ -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) diff --git a/tracer/tracer.go b/tracer/tracer.go index a5100dca..8951da8a 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -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{} {