AddExponentialHistogram

data class AddExponentialHistogram(val key: MetricKey, val scale: Int, val zeroCount: Long, val positiveOffset: Int, val positiveCounts: List<Long>, val negativeOffset: Int, val negativeCounts: List<Long>) : MetricUpdate

Add one interval's already-bucketed measurements to the histogram for key, in the shape of an OTLP ExponentialHistogramDataPoint — what an OpenTelemetry SDK exports for an exponential histogram under delta temporality.

OTLP bucket offset + i at scale covers (base^(offset+i), base^(offset+i+1)] with base = 2^(2^−scale), and holds counts[i] values; zeroCount values were zero. Negative buckets index the magnitude, mirrored. The counts are added to the series, the weighted form of RecordHistogram, so applying the same update twice counts it twice, as with IncrementSum.

The exporter keeps one scale, WarpMetricExporter.histogramScale. A scale at or above it maps exactly: equal re-indexes, finer merges 2^(scale − histogramScale) buckets into one. A scale below it cannot be split without losing the sketch's accuracy guarantee, so WarpMetricExporter.record refuses the whole batch that holds one, applying nothing. That check needs the exporter, so it is not made here.

An OTLP point's sum, min, max and exemplars have no field here: a DDSketch does not keep them.

Throws

if zeroCount or any bucket count is negative, or scale is outside the OTLP data model's [-10, 20].

Samples

val exporter = WarpMetricExporter(
    replica = us.tractat.kuilt.crdt.ReplicaId("server-1"),
    store = InMemoryDurableStore(),
)
val latency = MetricKey("request.latency.ms", MetricKind.EXPONENTIAL_HISTOGRAM)

// OTLP buckets 160..162 at the exporter's own scale: 3 + 0 + 5 values, plus 2 zeros.
val interval = MetricUpdate.AddExponentialHistogram(
    latency,
    scale = exporter.histogramScale,
    zeroCount = 2L,
    positiveOffset = 160,
    positiveCounts = listOf(3L, 0L, 5L),
    negativeOffset = 0,
    negativeCounts = emptyList(),
)
exporter.record(listOf(interval))
exporter.record(listOf(interval)) // a delta: the next interval adds, it does not replace
check(exporter.histogramSnapshot(latency).count == 20L)

Constructors

Link copied to clipboard
constructor(key: MetricKey, scale: Int, zeroCount: Long, positiveOffset: Int, positiveCounts: List<Long>, negativeOffset: Int, negativeCounts: List<Long>)

Properties

Link copied to clipboard
open override val key: MetricKey

The series this update changes.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val scale: Int
Link copied to clipboard