This is an adaptive sampler which can help prevent a surge in traffic from overwhelming the zipkin storage layer.

This works in scenarios where you can coordinate the collection tier with ZooKeeper 3.4.x or ZooKeeper 3.5.x.

zipkin.sampler.zookeeper.ZooKeeperSampler.Builder includes defaults that will against a given Curator client.


// The ZooKeeperSampler requires you to supply your own Curator.
client = CuratorFrameworkFactory.builder()
    .retryPolicy(new RetryOneTime(1))
client.blockUntilConnected(3, TimeUnit.SECONDS);

// This will sample spans based on the capacity of the storage layer.
// Capacity is spans/minute and set by an admin.
sampler = new ZooKeeperSampler.Builder()
    .id("kafka-" + topic + "@" + hostAndPort)

// Initialize a collector that will sample incoming spans based on
// a coordinated rate.
collector = new KafkaCollector.Builder()
    .writeTo(storage, sampler);

ZooKeeper Paths

The following paths are relative to zipkin.sampler.zookeeper.ZooKeeperSampler.basePath, which defaults to "/zipkin/sampler".

Path Owner Description
/targetStoreRate admin Admin changes this to no more than 95% capacity of the storage layer in spans/minute.
/sampleRate leader Each member of the sample group's isSampled(Span) method will pass based on this value. This is updated no more than {sampler.updateInterval} by the leader.
/storeRates/{} each sampler Updated per {sampler.updateInterval} to the amount of spans sampled per minute.
/election each sampler This path is used to determine or elect a new leader.

More information

More details are available in the javadoc The sampling implementation was initially based on zipkin-scala.