Crate relay_cogs

source ·
Expand description

Break down the cost of Relay by its components and individual features it handles.

Relay is a one stop shop for all different kinds of events Sentry supports, Errors, Performance, Metrics, Replays, Crons and more. A single shared resource.

This module intends to make it possible to give insights how much time and resources Relay spends processing individual features. The measurements collected can be later used for increased observability and accounting purposes.

relay-cogs provides a way to give an answer to the questions:

  • What portion of Relay’s costs can be attributed to feature X?
  • How much does feature X cost?

§Collecting COGs Measurements

Measurements are collected through Cogs which attributes the measurement to either a single or to multiple different app features belonging to a resource.

Collected and attributed measurements then are recorded by a CogsRecorder.

use relay_cogs::{AppFeature, Cogs, FeatureWeights, ResourceId};

enum Message {
    Span,
    Transaction,
    TransactionWithSpans { num_spans: usize },
}

struct Processor {
    cogs: Cogs
}

impl From<&Message> for FeatureWeights {
    fn from(value: &Message) -> Self {
        match value {
            Message::Span => FeatureWeights::new(AppFeature::Spans),
            Message::Transaction => FeatureWeights::new(AppFeature::Transactions),
            Message::TransactionWithSpans { num_spans } => FeatureWeights::builder()
                .weight(AppFeature::Spans, *num_spans)
                .weight(AppFeature::Transactions, 1)
                .build(),
        }
    }
}

impl Processor {
    fn handle_message(&self, mut message: Message) {
        let _cogs = self.cogs.timed(ResourceId::Relay, &message);

        self.step1(&mut message);
        self.step2(&mut message);

        // Measurement automatically recorded here.
    }
}

Structs§

Enums§

  • App feature a COGS measurement is related to.
  • Resource ID as tracked in COGS.
  • A COGS measurement value.

Traits§