Skip to content

Commit

Permalink
feat: costume tracer randomNumber func on config.New() called
Browse files Browse the repository at this point in the history
  • Loading branch information
guanwenbo committed Dec 18, 2020
1 parent 17fd3e8 commit 5c23401
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/config.go
Expand Up @@ -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))
}
Expand Down
8 changes: 8 additions & 0 deletions config/options.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 5c23401

Please sign in to comment.