DdDataStreams.Sketch (DD Data Streams v0.3.0)

Copy Markdown View Source

A DDSketch distribution: values are counted in logarithmically sized bins so that a whole distribution serialises into a compact protobuf message.

Only what the datastreams wire format needs is implemented: new/0, add/2 and to_proto/1. The mapping is the one dd-trace-go v2.11.2 and dd-trace-java 1.67.1 emit, gamma 1.015625 with index offset 1.8761281912861705; the mapping is self-describing in the payload (gamma and offset travel with it). dd-trace-py uses offset 1338.5, so its bins do not line up with Go/Java. The store is dense, so the encoded bin counts are contiguous with empty bins written as zeros.

Values whose magnitude is too small to map count as zero, and negative values are counted in a second store, indexed by their magnitude.

Summary

Functions

Adds value to the distribution and returns the updated distribution.

Returns an empty distribution.

Encodes the distribution as a protobuf DDSketch message.

Types

t()

@type t() :: %DdDataStreams.Sketch{
  negative: %{optional(integer()) => float()},
  positive: %{optional(integer()) => float()},
  zero_count: float()
}

Functions

add(sketch, value)

@spec add(t(), number()) :: t()

Adds value to the distribution and returns the updated distribution.

new()

@spec new() :: t()

Returns an empty distribution.

to_proto(sketch)

@spec to_proto(t()) :: binary()

Encodes the distribution as a protobuf DDSketch message.