Skip to main content

Module sentry_policy

Module sentry_policy 

Source
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_FLUSHES flushes;
  • at most HISTOGRAM_CAP of 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§

CounterValue 🔒
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.
DropWarning 🔒
Decides when the policy warns that it dropped values.
Dropped 🔒
The values the policy didn’t send, by why.
FlushState 🔒
The state that each flush updates.
GaugeValue 🔒
A gauge’s latest value, and the value and flush it was last sent at. Values are f64 bits.
LabelSets 🔒
How many label sets the SentryPolicy registry keeps for each metric name.
NameLabelSets 🔒
PolicyStorage 🔒
Creates the values the SentryPolicy registry keeps for each label set.
Sample 🔒
A uniform sample of at most HISTOGRAM_CAP values, kept with Algorithm R.
SentryMetric 🔒
A value for the adapter to send to Sentry.
SentryPolicy 🔒
A [Recorder] that keeps every metric for SentryPolicy::flush_if to send to Sentry.
Untracked 🔒
Stands in for every label set over LABEL_SET_CAP, and counts the values recorded for them.

Enums§

AttributeValue 🔒
The value of a SentryMetric attribute.
GaugeDue 🔒
Why a flush sends a gauge.
MetricType 🔒
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 value under key, with the key’s labels as attributes.
sample_slot 🔒
Returns the slot of a HISTOGRAM_CAP-value sample that the value numbered index in 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 probability HISTOGRAM_CAP / (index + 1).
take_turns 🔒
Takes the due metrics that fit in room, starting at *next and wrapping around, and moves *next past them, so that metrics left out go first in a later flush. Returns the metrics taken, and how many were left out.