From 5c234016e38d5373681fa750aba9264d3df972f0 Mon Sep 17 00:00:00 2001 From: guanwenbo Date: Fri, 18 Dec 2020 20:08:57 +0800 Subject: [PATCH] feat: costume tracer randomNumber func on config.New() called --- config/config.go | 4 ++++ config/options.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/config/config.go b/config/config.go index 165754b2..26b461d2 100644 --- a/config/config.go +++ b/config/config.go @@ -277,6 +277,10 @@ func (c Configuration) NewTracer(options ...Option) (opentracing.Tracer, io.Clos tracerOptions = append(tracerOptions, jaeger.TracerOptions.Gen128Bit(true)) } + if opts.randomNumber != nil { + tracerOptions = append(tracerOptions, jaeger.TracerOptions.RandomNumber(opts.randomNumber)) + } + for _, tag := range opts.tags { tracerOptions = append(tracerOptions, jaeger.TracerOptions.Tag(tag.Key, tag.Value)) } diff --git a/config/options.go b/config/options.go index e0e50e83..27c23777 100644 --- a/config/options.go +++ b/config/options.go @@ -40,6 +40,7 @@ type Options struct { tags []opentracing.Tag injectors map[interface{}]jaeger.Injector extractors map[interface{}]jaeger.Extractor + randomNumber func() uint64 } // Metrics creates an Option that initializes Metrics in the tracer, @@ -147,6 +148,13 @@ func Extractor(format interface{}, extractor jaeger.Extractor) Option { } } +// WithRandonNunmber set the Tracer random number func +func WithRandonNunmber(f func() uint64) Option { + return func(c *Options) { + c.randomNumber = f + } +} + func applyOptions(options ...Option) Options { opts := Options{ injectors: make(map[interface{}]jaeger.Injector),