Expand description
Metric protocol, aggregation and processing for Sentry.
Metrics are high-volume values sent from Sentry clients, integrations, or extracted from errors and transactions, that can be aggregated and queried over large time windows. As opposed to rich errors and transactions, metrics carry relatively little context information in tags with low cardinality.
§Protocol
Clients submit metrics in a text-based protocol based on StatsD. See the field
documentation on Bucket
for more information on the components. A sample
submission looks like this:
endpoint.response_time@millisecond:36:49:57:68|d|#route:user_index|T1615889440
endpoint.hits:4|c|#route:user_index|T1615889440
endpoint.parallel_requests:25:17:42:220:85|g|#route:user_index|T1615889440
endpoint.users:3182887624:4267882815|s|#route:user_index|T1615889440
The metric type is part of its signature just like the unit. Therefore, it is allowed to reuse a metric name for multiple metric types, which will result in multiple metrics being recorded.
§Metric Envelopes
To send one or more metrics to Relay, the raw protocol is enclosed in an envelope item of type
metrics
:
{}
{"type": "statsd", ...}
endpoint.response_time@millisecond:36:49:57:68|d|#route:user_index|T1615889440
endpoint.hits:4|c|#route:user_index|T1615889440
endpoint.parallel_requests:25:17:42:220:85|g|#route:user_index|T1615889440
endpoint.users:3182887624:4267882815|s|#route:user_index|T1615889440
...
Note that the name format used in the statsd protocol is different from the MRI: Metric names
are not prefixed with <ty>:
as the type is somewhere else in the protocol. If no metric
namespace is specified, the "custom"
namespace is assumed.
Optionally, a timestamp can be added to every line of the submitted envelope. The timestamp has
to be a valid Unix timestamp (UTC) and must be prefixed with T
. If it is omitted, the
received
time of the envelope is assumed.
§Aggregation
Relay accumulates all metrics in time buckets before sending them onwards. Aggregation
is handled by the aggregator::Aggregator
, which should be created once for the entire system. It flushes
aggregates in regular intervals, either shortly after their original time window has passed or
with a debounce delay for backdated submissions.
Warning: With chained Relays submission delays accumulate.
Aggregate buckets are encoded in JSON with the following schema:
[
{
"timestamp": 1615889440,
"width": 0,
"name": "d:custom/endpoint.response_time@millisecond",
"type": "d",
"value": [
36.0,
49.0,
57.0,
68.0
],
"tags": {
"route": "user_index"
}
},
{
"timestamp": 1615889440,
"width": 0,
"name": "c:custom/endpoint.hits@none",
"type": "c",
"value": 4.0,
"tags": {
"route": "user_index"
}
},
{
"timestamp": 1615889440,
"width": 0,
"name": "g:custom/endpoint.parallel_requests@none",
"type": "g",
"value": {
"last": 25.0,
"min": 17.0,
"max": 42.0,
"sum": 220.0,
"count": 85
},
"tags": {
"route": "user_index"
}
},
{
"timestamp": 1615889440,
"width": 0,
"name": "s:custom/endpoint.users@none",
"type": "s",
"value": [
3182887624,
4267882815
],
"tags": {
"route": "user_index"
}
}
]
§Ingestion
Processing Relays write aggregate buckets into the ingestion Kafka stream. The schema is similar to the aggregation payload, with the addition of scoping information. Each bucket is sent in a separate message:
{
"org_id": 1,
"project_id": 42,
"name": "endpoint.response_time",
"unit": "millisecond",
"value": [
36.0,
49.0,
57.0,
68.0
],
"type": "d",
"timestamp": 1615889440,
"tags": {
"route": "user_index"
}
}
Modules§
- aggregator
- Core functionality of metrics aggregation.
- cogs
- COGS related metric utilities.
Macros§
- dist
- Creates a
DistributionValue
containing the given arguments.
Structs§
- Bucket
- An aggregation of metric values.
- Bucket
Metadata - Relay internal metadata for a metric bucket.
- Bucket
View - A view into a metrics bucket. Sometimes also called a partial bucket. A view contains a subset of datapoints of the original bucket.
- Buckets
View - A view into a slice of metric buckets.
- Buckets
View BySize Iter - Iterator slicing a
BucketsView
into smaller views constrained by a given size in bytes. - Buckets
View Iter - Iterator yielding all items contained in a
BucketsView
. - ByNamespace
- Utility to store information for each
MetricNamespace
. - Custom
Unit - Custom user-defined units without builtin conversion.
- Finite
F64 - A finite 64-bit floating point type.
- Gauge
Value - A snapshot of values within a
Bucket
. - Metric
Name - Optimized string represenation of a metric name.
- Metric
Resource Identifier - A unique identifier for metrics including typing and namespacing.
- Parse
Buckets - Iterator over parsed metrics returned from
Bucket::parse_all
. - Parse
Finite Float Error - Error type returned when parsing
FiniteF64
fails. - Parse
Metric Error - An error returned when metrics or MRIs cannot be parsed.
- Parse
Metric Unit Error - An error parsing a
MetricUnit
or one of its variants. - SetView
- A view into the datapoints of a set metric.
- TryFrom
Float Error - Error type returned when conversion to
FiniteF64
fails. - Unix
Timestamp - A unix timestamp (full seconds elapsed since 1970-01-01 00:00 UTC).
Enums§
- Bucket
Value - The aggregated value of a metric bucket.
- Bucket
View Value - A view into the datapoints of a
BucketValue
. - Duration
Unit - Time duration units used in
MetricUnit::Duration
. - Fraction
Unit - Units of fraction used in
MetricUnit::Fraction
. - Information
Unit - Size of information derived from bytes, used in
MetricUnit::Information
. - Metric
Namespace - The namespace of a metric.
- Metric
Type - The type of a
MetricResourceIdentifier
, determining its aggregation and evaluation. - Metric
Unit - The unit of measurement of a metric value.
- Normalization
Error - Error returned from
normalize_bucket
. - Unescape
Error - Unescaper’s
Error
.
Functions§
- normalize_
bucket - Normalizes a bucket.
Type Aliases§
- Counter
Type - Type used for Counter metric
- Distribution
Type - Type of distribution entries
- Distribution
Value - A distribution of values within a
Bucket
. - Gauge
Type - Type used for Gauge entries
- Metric
Tags - Type of
Bucket::tags
. - SetType
- Type used for set elements in Set metric
- SetValue
- A set of unique values.