relay_base_schema::metrics

Struct MetricResourceIdentifier

source
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:

  1. 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.
  2. 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.
  3. 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>

source

pub fn parse(name: &'a str) -> Result<Self, ParseMetricError>

Parses and validates an MRI.

source

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.

source

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>

source§

fn clone(&self) -> MetricResourceIdentifier<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for MetricResourceIdentifier<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for MetricResourceIdentifier<'static>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for MetricResourceIdentifier<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Hash for MetricResourceIdentifier<'a>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> PartialEq for MetricResourceIdentifier<'a>

source§

fn eq(&self, other: &MetricResourceIdentifier<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for MetricResourceIdentifier<'_>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'a> Eq for MetricResourceIdentifier<'a>

source§

impl<'a> StructuralPartialEq for MetricResourceIdentifier<'a>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T