loading multiple sampling strategies when initialize a tracer
congim opened this issue · 8 comments
Is there an example of loading multiple sampling strategies when initialize a tracer?
like this
cfg.NewTracer(Sampler1, Sampler2, Sampler3.... )
thanks!
There is only one Sampler that Tracer interacts with. You can implement that interface to dispatch to different samplers, if you wish. For example:
jaeger-client-go/x/priority_sampler.go
Lines 78 to 80 in b1fe7fe
@yurishkuro Thanks! When was the priority policy loaded into tracer? Is there any sample code?
If you create a tracer directly you can pass it a sampler. If you create it via Configuration object, you can also pass a pre-instantiated sampler via config.Sampler(yourSampler)
functional option.
@yurishkuro
I try to initialize like this:
sampler2 := jaeger.NewRemotelyControlledSampler(c.ServiceName,
jaeger.SamplerOptions.SamplingRefreshInterval(time.Second*1),
jaeger.SamplerOptions.SamplingStrategyFetcher(&localFetcher{}),
)
tracer, closer := jaeger.NewTracer(
c.ServiceName,
sampler2,
jaeger.NewRemoteReporter(transport.NewIOTransport(write, 1)))
opentracing.SetGlobalTracer(tracer)
tracer, closer := jaeger.NewTracer(
c.ServiceName,
sampler2,
jaeger.NewRemoteReporter(transport.NewIOTransport(write, 1)))
opentracing.SetGlobalTracer(tracer)
// for localFetcher
type localFetcher struct {
}
func (l *localFetcher) Fetch(service string) ([]byte, error) {
log.Println("Fetch", service)
str := `{
"service_strategies": [{
"service": "kafka-demo",
"type": "probabilistic",
"param": 0.0,
"operation_strategies": [{
"operation": "span_root",
"type": "probabilistic",
"param": 0.0
}
]
}],
"default_strategy": {
"type": "probabilistic",
"param": 0.0
}
}`
return []byte(str), nil
}
But I found that the strategy didn't work!
tracer := opentracing.GlobalTracer()
for i := 0; i < 5; i++ {
span := tracer.StartSpan("span_root")
span.Finish()
}
It still outputs 5 span.
do I have to initialize a batch of sampler first and then overwrite them?
like this
sampler := jaeger.NewConstSampler(true)
sampler3, _ := jaeger.NewProbabilisticSampler(1)
sampler4 := jaeger.NewRateLimitingSampler(1)
updaters := []SamplerUpdater{new(ProbabilisticSamplerUpdater)}
sampler := NewRemotelyControlledSampler(
"test",
SamplerOptions.InitialSampler(sampler),
SamplerOptions.InitialSampler(sampler3),
SamplerOptions.InitialSampler(sampler4),
SamplerOptions.Updaters(updaters...),
)
it working ok whit this json
{
"strategyType": "PROBABILISTIC",
"probabilisticSampling": {
"samplingRate": 0.0
},
"operationSampling": {
"defaultSamplingProbability": 0.0,
"defaultLowerBoundTracesPerSecond": 0,
"perOperationStrategies": [{
"operation": "span_root",
"probabilisticSampling": {
"samplingRate": 0.6
}
}]
}
}
I don't recall if there is a delay before the remote sampler queries for a new set of strategies.
I don't understand what you're trying to do. If you want some hardcoded policies that you define in the code, then there is no need to use remote sampler, you should be able to construct PerOperationSampler
directly with the required policies.
Line 370 in b1fe7fe
You are right. Thank you very much!