Skip to content

Instantly share code, notes, and snippets.

@maplebed
Created August 26, 2019 20:38
Show Gist options
  • Save maplebed/fbc8504e2c110aea50f5dc0ce070fde2 to your computer and use it in GitHub Desktop.
Save maplebed/fbc8504e2c110aea50f5dc0ce070fde2 to your computer and use it in GitHub Desktop.
Sample traces at one rate, but within kept traces, drop specific spans at a higher rate. Can be confusing, but can also sometimes be useful.
const (
// beeline pre-sampling
shepherdOverallSampleRate = 3
triadSampleRate = 4
)
... initialization ...
// override the default sampler for the beeline
trace.GlobalConfig.SamplerHook = a.MakeSampler()
// MakeSampler manaages the beeline sampling for shepherd instrumentation. It
// will drop all traces at 1/2 and drop 75% of the per-event pairs of
// verify_schema and pass_to_kafka_writer
func (a *App) MakeSampler() func(map[string]interface{}) (bool, int) {
a.sampler, _ = sample.NewDeterministicSampler(shepherdOverallSampleRate)
return func(fields map[string]interface{}) (bool, int) {
if !a.sampler.Sample(fields["trace.trace_id"].(string)) {
return false, shepherdOverallSampleRate
}
// we should keep this trace.
// but if this event is one of the triad we should drop it at 1/4 (on top of the overall rate)
switch fields["name"] {
case "verify_schema", "pass_to_kafka_writer":
return rand.Intn(triadSampleRate) == 0, triadSampleRate * shepherdOverallSampleRate
default:
return true, shepherdOverallSampleRate
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment