Expand description
Shapes every metric for Sentry, which stores each value it receives.
Recording a counter or gauge only updates atomics in a sharded registry: there is no lock on a
kept handle, no allocation for an existing label set, and no call into the Sentry SDK. A
histogram value takes a short lock for its label set’s sample. Once per
FLUSH_INTERVAL, SentryPolicy::flush_if turns what was recorded into one batch of
SentryMetrics and gives it to an adapter that sends it:
- each counter’s increase since it was last sent, for each label set that increased;
- each gauge’s latest value, for each label set whose value changed since it was last sent, or
that hasn’t been sent for
GAUGE_REFRESH_FLUSHESflushes; - at most
HISTOGRAM_CAPof each histogram’s values for each label set, chosen uniformly at random from the values recorded since the previous flush. Each label set only keeps that sample, so its memory doesn’t grow with how often it is recorded.
A batch holds at most FLUSH_BUDGET metrics. When more are due, counters go first, then
gauges that changed, then gauges due for a refresh, then histogram values. Counters and gauges
that don’t fit stay due and take turns in later flushes, so a counter’s increase is delayed,
not lost. Histogram values that don’t fit are dropped.
A flush sends nothing while the Sentry transport is still sending what earlier flushes queued. Its counters and gauges stay due, and its histogram values are dropped, so metrics never take more than their share of a slow or stalled transport’s queue.
The policy keeps at most LABEL_SET_CAP label sets for each metric name, and doesn’t send
the values recorded for any others, so a label that keeps taking new values can’t grow the
policy’s memory or volume without bound. Other backends keep every label set.
The zebrad.sentry.metrics.dropped.total counter counts the due values left out of a full
flush or of a flush the transport wasn’t ready for, and the values recorded for label sets over
the cap. The policy records it through the metrics facade, so every backend receives it, and
logs a warning when it starts dropping values.
The histograms in SENT_DIRECTLY are skipped, because their callers send each value to Sentry
themselves.
Structs§
- Counter
Value 🔒 - A counter’s total, and its total when a flush last took its increase.
- Distribution 🔒
- A uniform sample of the values one histogram label set recorded since the previous flush.
- Drop
Warning 🔒 - Decides when the policy warns that it dropped values.
- Dropped 🔒
- The values the policy didn’t send, by why.
- Flush
State 🔒 - The state that each flush updates.
- Gauge
Value 🔒 - A gauge’s latest value, and the value and flush it was last sent at. Values are
f64bits. - Label
Sets 🔒 - How many label sets the
SentryPolicyregistry keeps for each metric name. - Name
Label 🔒Sets - Policy
Storage 🔒 - Creates the values the
SentryPolicyregistry keeps for each label set. - Sample 🔒
- A uniform sample of at most
HISTOGRAM_CAPvalues, kept with Algorithm R. - Sentry
Metric 🔒 - A value for the adapter to send to Sentry.
- Sentry
Policy 🔒 - A [
Recorder] that keeps every metric forSentryPolicy::flush_ifto send to Sentry. - Untracked 🔒
- Stands in for every label set over
LABEL_SET_CAP, and counts the values recorded for them.
Enums§
- Attribute
Value 🔒 - The value of a
SentryMetricattribute. - Gauge
Due 🔒 - Why a flush sends a gauge.
- Metric
Type 🔒 - How Sentry stores a
SentryMetric.
Constants§
- DROP_
WARNING_ 🔒INTERVAL - The least time between two warnings that the policy dropped values.
- ENVELOPE_
METRICS 🔒 - The most metrics the Sentry SDK puts in one envelope. Its batcher queues the envelope for sending as soon as it holds this many, on the thread that captured the last one.
- FLUSH_
BUDGET 🔒 - The most metrics one flush sends.
- FLUSH_
INTERVAL 🔒 - How often the policy sends what was recorded to Sentry.
- GAUGE_
REFRESH_ 🔒FLUSHES - How many flushes an unchanged gauge waits before it is sent again, so that Sentry charts show steady values: every 5 minutes.
- HISTOGRAM_
CAP 🔒 - The most values one histogram label set sends per
FLUSH_INTERVAL. - IN_
FLUSH 🔒 - Whether this thread is in a
SentryPolicy::flush_if, so that the panic hook’s flush returns instead of waiting for a flush that panicked on the same thread. - LABEL_
SET_ 🔒CAP - The most label sets the policy keeps for one metric name.
- SENT_
DIRECTLY 🔒 - Histograms that the policy doesn’t send, because their callers send each value to Sentry with attributes that would make a new Prometheus series for every value, such as a block height.
- TRANSPORT_
QUEUE_ 🔒ENVELOPES - How many envelopes the Sentry SDK’s transport queues for sending. Events, logs, sessions, and metrics share this queue, and the SDK drops an envelope that arrives while it is full.
Functions§
- metric 🔒
- Returns the metric to send for
valueunderkey, with the key’s labels as attributes. - sample_
slot 🔒 - Returns the slot of a
HISTOGRAM_CAP-value sample that the value numberedindexin an interval replaces, if it is sampled: each of the first values takes the next slot, then each later value replaces a random slot with probabilityHISTOGRAM_CAP / (index + 1). - take_
turns 🔒 - Takes the
duemetrics that fit inroom, starting at*nextand wrapping around, and moves*nextpast them, so that metrics left out go first in a later flush. Returns the metrics taken, and how many were left out.