pub struct MetricResourceIdentifier<'a> {
pub ty: MetricType,
pub namespace: MetricNamespace,
pub name: Cow<'a, str>,
pub unit: MetricUnit,
}
Expand description
A unique identifier for metrics including typing and namespacing.
MRIs have the format <type>:<namespace>/<name>[@<unit>]
. The unit is optional and defaults to
MetricUnit::None
.
§Statsd Format
In the statsd submission payload, MRIs are sent in a more relaxed format:
[<namespace>/]<name>[@<unit>]
. The differences to the internal MRI format are:
- Types are not part of metric naming. Instead, the type is declared in a separate field following the value.
- The namespace is optional. If missing,
"custom"
is assumed.
§Background
MRIs follow three core principles:
- Robustness: Metrics must be addressed via a stable identifier. During ingestion in Relay and Snuba, metrics are preaggregated and bucketed based on this identifier, so it cannot change over time without breaking bucketing.
- Uniqueness: The identifier for metrics must be unique across variations of units and metric types, within and across use cases, as well as between projects and organizations.
- Abstraction: The user-facing product changes its terminology over time, and splits concepts into smaller parts. The internal metric identifiers must abstract from that, and offer sufficient granularity to allow for such changes.
§Example
use relay_base_schema::metrics::MetricResourceIdentifier;
let string = "c:custom/test@second";
let mri = MetricResourceIdentifier::parse(string).expect("should parse");
assert_eq!(mri.to_string(), string);
Fields§
§ty: MetricType
The type of a metric, determining its aggregation and evaluation.
In MRIs, the type is specified with its short name: counter (c
), set (s
), distribution
(d
), and gauge (g
). See MetricType
for more information.
namespace: MetricNamespace
The namespace for this metric.
In statsd submissions payloads, the namespace is optional and defaults to "custom"
.
Otherwise, the namespace must be declared explicitly.
Note that in Sentry the namespace is also referred to as “use case” or “usecase”. There is a list of known and enabled namespaces. Metrics of unknown or disabled namespaces are dropped during ingestion.
name: Cow<'a, str>
The display name of the metric in the allowed character set.
unit: MetricUnit
The verbatim unit name of the metric value.
The unit is optional and defaults to MetricUnit::None
("none"
).
Implementations§
source§impl<'a> MetricResourceIdentifier<'a>
impl<'a> MetricResourceIdentifier<'a>
sourcepub fn parse(name: &'a str) -> Result<Self, ParseMetricError>
pub fn parse(name: &'a str) -> Result<Self, ParseMetricError>
Parses and validates an MRI.
sourcepub fn parse_with_type(
string: &'a str,
ty: MetricType,
) -> Result<Self, ParseMetricError>
pub fn parse_with_type( string: &'a str, ty: MetricType, ) -> Result<Self, ParseMetricError>
Parses an MRI from a string and a separate type.
The given string must be a part of the MRI, including the following components:
- (optional) The namespace. If missing, it is defaulted to
"custom"
- (required) The metric name.
- (optional) The unit. If missing, it is defaulted to “none”.
The metric type is never part of this string and must be supplied separately.
sourcepub fn into_owned(self) -> MetricResourceIdentifier<'static>
pub fn into_owned(self) -> MetricResourceIdentifier<'static>
Converts the MRI into an owned version with a static lifetime.
Trait Implementations§
source§impl<'a> Clone for MetricResourceIdentifier<'a>
impl<'a> Clone for MetricResourceIdentifier<'a>
source§fn clone(&self) -> MetricResourceIdentifier<'a>
fn clone(&self) -> MetricResourceIdentifier<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for MetricResourceIdentifier<'a>
impl<'a> Debug for MetricResourceIdentifier<'a>
source§impl<'de> Deserialize<'de> for MetricResourceIdentifier<'static>
impl<'de> Deserialize<'de> for MetricResourceIdentifier<'static>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<'a> Display for MetricResourceIdentifier<'a>
impl<'a> Display for MetricResourceIdentifier<'a>
source§impl<'a> Hash for MetricResourceIdentifier<'a>
impl<'a> Hash for MetricResourceIdentifier<'a>
source§impl<'a> PartialEq for MetricResourceIdentifier<'a>
impl<'a> PartialEq for MetricResourceIdentifier<'a>
source§fn eq(&self, other: &MetricResourceIdentifier<'a>) -> bool
fn eq(&self, other: &MetricResourceIdentifier<'a>) -> bool
self
and other
values to be equal, and is used by ==
.source§impl Serialize for MetricResourceIdentifier<'_>
impl Serialize for MetricResourceIdentifier<'_>
impl<'a> Eq for MetricResourceIdentifier<'a>
impl<'a> StructuralPartialEq for MetricResourceIdentifier<'a>
Auto Trait Implementations§
impl<'a> Freeze for MetricResourceIdentifier<'a>
impl<'a> RefUnwindSafe for MetricResourceIdentifier<'a>
impl<'a> Send for MetricResourceIdentifier<'a>
impl<'a> Sync for MetricResourceIdentifier<'a>
impl<'a> Unpin for MetricResourceIdentifier<'a>
impl<'a> UnwindSafe for MetricResourceIdentifier<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)