/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
cloud/tasks/tracing/sampling.go
54 строки
1 KB
Grigoriy Yurgin
[Disk Manager] tracing: add sampling of tasks generations (#2228)
09 окт 2024, 23:22
Не верифицирован
09 окт 2024, 23:22
bdb7914
Код
Авторство
О чём код?
package tracing import ( "go.opentelemetry.io/otel/attribute" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) //////////////////////////////////////////////////////////////////////////////// const ( sampledAttributeKey = "sampled" ) //////////////////////////////////////////////////////////////////////////////// type sampler struct{} func newSampler() sdktrace.Sampler { return &sampler{} } //////////////////////////////////////////////////////////////////////////////// func (s *sampler) ShouldSample( params sdktrace.SamplingParameters, ) sdktrace.SamplingResult { if !hasSampledAttribute(params) { return sdktrace.SamplingResult{Decision: sdktrace.Drop} } return sdktrace.SamplingResult{Decision: sdktrace.RecordAndSample} } func (s *sampler) Description() string { return "Basic cloud.tasks sampler. " + "Uses attribute 'sampled' of a span for sampling decision." } //////////////////////////////////////////////////////////////////////////////// func newSampledAttribute(sampled bool) attribute.KeyValue { return attribute.Bool(sampledAttributeKey, sampled) } func hasSampledAttribute(params sdktrace.SamplingParameters) bool { for _, attr := range params.Attributes { if attr.Key == sampledAttributeKey { return attr.Value.AsBool() } } return true }