OpenCensus is being archived! Read the blog post to learn more

Probabilistic

Probabilistic sampler

The probabilistic sampler probabilistically returns True or False for whether a span should be sampled depending on the results of a coin flip.

By default, the probabilistic sampling rate is 1 in 10,000

Code samples

import "go.opencensus.io/trace"

theSampler = trace.ProbabilitySampler(1/1000.0);
Samplers.probabilitySampler(1/1000.0);
from opencensus.trace.samplers import probability
from opencensus.trace import tracer as tracer_module

# Sampling the requests at the rate equals 0.5
sampler = probability.ProbabilitySampler(rate=0.5)
tracer = tracer_module.Tracer(sampler=sampler)
// Samplers are potentially expensive to construct. Use one long-lived
// sampler instead of constructing one for every Span.
static opencensus::trace::ProbabilitySampler sampler(1/1000.0);
const root = new RootSpan(tracer);
const sampler = SamplerBuilder.getSampler(0.01);
const samplerProbability = sampler.shouldSample(root.traceId);

Reference

Resource URL
Probability sampler in specs https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/Sampling.md#what-kind-of-samplers-does-opencensus-support
Go ProbabilitySample trace.ProbabilitySampler
Python samplers trace.samplers
Java ProbabilitySampler trace.ProbabilitySampler
C++ ProbabilitySampler trace.ProbabilitySampler
Node.js TracerConfig trace.TracerConfig