Skip to main content

relay_metrics/
lib.rs

1//! Metric protocol, aggregation and processing for Sentry.
2//!
3//! Metrics are high-volume values sent from Sentry clients, integrations, or extracted from errors
4//! and transactions, that can be aggregated and queried over large time windows. As opposed to rich
5//! errors and transactions, metrics carry relatively little context information in tags with low
6//! cardinality.
7//!
8//! # Protocol
9//!
10//! Clients submit metrics in a [text-based protocol](Bucket) based on StatsD. See the [field
11//! documentation](Bucket#fields) on `Bucket` for more information on the components. A sample
12//! submission looks like this:
13//!
14//! ```text
15#![doc = include_str!("../tests/fixtures/buckets.statsd.txt")]
16//! ```
17//!
18//! The metric type is part of its signature just like the unit. Therefore, it is allowed to reuse a
19//! metric name for multiple metric types, which will result in multiple metrics being recorded.
20//!
21//! # Metric Envelopes
22//!
23//! To send one or more metrics to Relay, the raw protocol is enclosed in an envelope item of type
24//! `metrics`:
25//!
26//! ```text
27//! {}
28//! {"type": "statsd", ...}
29#![doc = include_str!("../tests/fixtures/buckets.statsd.txt")]
30//! ...
31//! ```
32//!
33//! Note that the name format used in the statsd protocol is different from the MRI: Metric names
34//! are not prefixed with `<ty>:` as the type is somewhere else in the protocol.
35//!
36//! Optionally, a timestamp can be added to every line of the submitted envelope. The timestamp has
37//! to be a valid Unix timestamp (UTC) and must be prefixed with `T`. If it is omitted, the
38//! `received` time of the envelope is assumed.
39//!
40//! # Aggregation
41//!
42//! Relay accumulates all metrics in [time buckets](Bucket) before sending them onwards. Aggregation
43//! is handled by the [`aggregator::Aggregator`], which should be created once for the entire system. It flushes
44//! aggregates in regular intervals, either shortly after their original time window has passed or
45//! with a debounce delay for backdated submissions.
46//!
47//! **Warning**: With chained Relays submission delays accumulate.
48//!
49//! Aggregate buckets are encoded in JSON with the following schema:
50//!
51//! ```json
52#![doc = include_str!("../tests/fixtures/buckets.json")]
53//! ```
54//!
55//! # Ingestion
56//!
57//! Processing Relays write aggregate buckets into the ingestion Kafka stream. The schema is similar
58//! to the aggregation payload, with the addition of scoping information. Each bucket is sent in a
59//! separate message:
60//!
61//! ```json
62#![doc = include_str!("../tests/fixtures/kafka.json")]
63//! ```
64#![warn(missing_docs)]
65#![doc(
66    html_logo_url = "https://raw.githubusercontent.com/getsentry/relay/master/artwork/relay-icon.png",
67    html_favicon_url = "https://raw.githubusercontent.com/getsentry/relay/master/artwork/relay-icon.png"
68)]
69
70pub mod aggregator;
71pub mod cogs;
72
73mod bucket;
74mod protocol;
75mod statsd;
76mod utils;
77mod view;
78
79pub use bucket::*;
80pub use protocol::*;
81pub use utils::ByNamespace;
82pub use view::*;