Created
August 26, 2019 20:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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