Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions relay-base-schema/src/metrics/mri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub enum MetricNamespace {
Sessions,
/// Metrics extracted from spans.
Spans,
/// Metrics extracted from transactions.
Transactions,
/// User-defined metrics directly sent by SDKs and applications.
Custom,
/// An unknown and unsupported metric.
Expand All @@ -126,15 +128,22 @@ pub enum MetricNamespace {

impl MetricNamespace {
/// Returns all namespaces/variants of this enum.
pub fn all() -> [Self; 4] {
[Self::Sessions, Self::Spans, Self::Custom, Self::Unsupported]
pub fn all() -> [Self; 5] {
[
Self::Sessions,
Self::Spans,
Self::Transactions,
Self::Custom,
Self::Unsupported,
]
}

/// Returns the string representation for this metric type.
pub fn as_str(&self) -> &'static str {
match self {
Self::Sessions => "sessions",
Self::Spans => "spans",
Self::Transactions => "transactions",
Self::Custom => "custom",
Self::Unsupported => "unsupported",
}
Expand All @@ -148,6 +157,7 @@ impl std::str::FromStr for MetricNamespace {
match ns {
"sessions" => Ok(Self::Sessions),
"spans" => Ok(Self::Spans),
"transactions" => Ok(Self::Transactions),
"custom" => Ok(Self::Custom),
_ => Ok(Self::Unsupported),
}
Expand Down
3 changes: 3 additions & 0 deletions relay-cogs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ pub enum AppFeature {

/// Metrics in the spans namespace.
MetricsSpans,
/// Metrics in the transactions namespace.
MetricsTransactions,
/// Metrics in the sessions namespace.
MetricsSessions,
/// Metrics in the custom namespace.
Expand Down Expand Up @@ -207,6 +209,7 @@ impl AppFeature {
Self::Replays => "replays",
Self::UserReports => "user_reports",
Self::MetricsSpans => "metrics_spans",
Self::MetricsTransactions => "metrics_transactions",
Self::MetricsSessions => "metrics_sessions",
Self::MetricsCustom => "metrics_custom",
Self::MetricsUnsupported => "metrics_unsupported",
Expand Down
6 changes: 6 additions & 0 deletions relay-dynamic-config/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub enum CardinalityLimiterMode {
#[serde(default)]
pub struct BucketEncodings {
spans: BucketEncoding,
transactions: BucketEncoding,
profiles: BucketEncoding,
custom: BucketEncoding,
}
Expand All @@ -216,6 +217,7 @@ impl BucketEncodings {
pub fn for_namespace(&self, namespace: MetricNamespace) -> BucketEncoding {
match namespace {
MetricNamespace::Spans => self.spans,
MetricNamespace::Transactions => self.transactions,
MetricNamespace::Custom => self.custom,
// Always force the legacy encoding for sessions,
// sessions are not part of the generic metrics platform with different
Expand Down Expand Up @@ -249,6 +251,7 @@ where
let encoding = BucketEncoding::deserialize(de::value::StrDeserializer::new(v))?;
Ok(BucketEncodings {
spans: encoding,
transactions: encoding,
profiles: encoding,
custom: encoding,
})
Expand Down Expand Up @@ -451,6 +454,7 @@ mod tests {
o.metric_bucket_set_encodings,
BucketEncodings {
spans: BucketEncoding::Legacy,
transactions: BucketEncoding::Legacy,
profiles: BucketEncoding::Legacy,
custom: BucketEncoding::Legacy,
}
Expand All @@ -459,6 +463,7 @@ mod tests {
o.metric_bucket_dist_encodings,
BucketEncodings {
spans: BucketEncoding::Zstd,
transactions: BucketEncoding::Zstd,
profiles: BucketEncoding::Zstd,
custom: BucketEncoding::Zstd,
}
Expand All @@ -469,6 +474,7 @@ mod tests {
fn test_metric_bucket_encodings_de_from_obj() {
let original = BucketEncodings {
spans: BucketEncoding::Zstd,
transactions: BucketEncoding::Zstd,
profiles: BucketEncoding::Base64,
custom: BucketEncoding::Zstd,
};
Expand Down
1 change: 1 addition & 0 deletions relay-metrics/src/cogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn to_app_feature(ns: MetricNamespace) -> AppFeature {
match ns {
MetricNamespace::Sessions => AppFeature::MetricsSessions,
MetricNamespace::Spans => AppFeature::MetricsSpans,
MetricNamespace::Transactions => AppFeature::MetricsTransactions,
MetricNamespace::Custom => AppFeature::MetricsCustom,
MetricNamespace::Unsupported => AppFeature::MetricsUnsupported,
}
Expand Down
10 changes: 9 additions & 1 deletion relay-metrics/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct ByNamespace<T> {
pub sessions: T,
/// Value for the [`MetricNamespace::Spans`] namespace.
pub spans: T,
/// Value for the [`MetricNamespace::Transactions`] namespace.
pub transactions: T,
/// Value for the [`MetricNamespace::Custom`] namespace.
pub custom: T,
/// Value for the [`MetricNamespace::Unsupported`] namespace.
Expand All @@ -31,6 +33,7 @@ impl<T> ByNamespace<T> {
match namespace {
MetricNamespace::Sessions => &self.sessions,
MetricNamespace::Spans => &self.spans,
MetricNamespace::Transactions => &self.transactions,
MetricNamespace::Custom => &self.custom,
MetricNamespace::Unsupported => &self.unsupported,
}
Expand All @@ -41,6 +44,7 @@ impl<T> ByNamespace<T> {
match namespace {
MetricNamespace::Sessions => &mut self.sessions,
MetricNamespace::Spans => &mut self.spans,
MetricNamespace::Transactions => &mut self.transactions,
MetricNamespace::Custom => &mut self.custom,
MetricNamespace::Unsupported => &mut self.unsupported,
}
Expand All @@ -49,19 +53,21 @@ impl<T> ByNamespace<T> {

impl<T> IntoIterator for ByNamespace<T> {
type Item = (MetricNamespace, T);
type IntoIter = std::array::IntoIter<(MetricNamespace, T), 4>;
type IntoIter = std::array::IntoIter<(MetricNamespace, T), 5>;

fn into_iter(self) -> Self::IntoIter {
let Self {
sessions,
spans,
transactions,
custom,
unsupported,
} = self;

[
(MetricNamespace::Sessions, sessions),
(MetricNamespace::Spans, spans),
(MetricNamespace::Transactions, transactions),
(MetricNamespace::Custom, custom),
(MetricNamespace::Unsupported, unsupported),
]
Expand Down Expand Up @@ -104,12 +110,14 @@ macro_rules! impl_op {
let Self {
sessions,
spans,
transactions,
custom,
unsupported,
} = self;

$op::$opfn(sessions, rhs.sessions);
$op::$opfn(spans, rhs.spans);
$op::$opfn(transactions, rhs.transactions);
$op::$opfn(custom, rhs.custom);
$op::$opfn(unsupported, rhs.unsupported);
}
Expand Down
2 changes: 2 additions & 0 deletions relay-server/src/services/processor/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn is_valid_namespace(bucket: &Bucket) -> bool {
match bucket.name.namespace() {
MetricNamespace::Sessions => true,
MetricNamespace::Spans => true,
MetricNamespace::Transactions => true,
MetricNamespace::Custom => true,
MetricNamespace::Unsupported => false,
}
Expand Down Expand Up @@ -56,6 +57,7 @@ fn is_metric_namespace_valid(state: &ProjectInfo, namespace: MetricNamespace) ->
match namespace {
MetricNamespace::Sessions => true,
MetricNamespace::Spans => true,
MetricNamespace::Transactions => true,
MetricNamespace::Custom => state.has_feature(Feature::CustomMetrics),
MetricNamespace::Unsupported => false,
}
Expand Down
1 change: 1 addition & 0 deletions relay-server/src/services/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,7 @@ impl Message for KafkaMessage<'_> {
KafkaMessage::Metric { message, .. } => match message.name.namespace() {
MetricNamespace::Sessions => "metric_sessions",
MetricNamespace::Spans => "metric_spans",
MetricNamespace::Transactions => "metric_transactions",
MetricNamespace::Custom => "metric_custom",
MetricNamespace::Unsupported => "metric_unsupported",
},
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_metrics(mini_sentry, relay):
mini_sentry.add_basic_project_config(project_id)

timestamp = int(datetime.now(tz=timezone.utc).timestamp())
metrics_payload = f"spans/foo:42|c|T{timestamp}\nspans/bar:17|c|T{timestamp}"
metrics_payload = f"spans/foo:42|c|T{timestamp}\ntransactions/bar:17|c|T{timestamp}"
relay.send_metrics(project_id, metrics_payload)

envelope = mini_sentry.get_captured_envelope()
Expand All @@ -185,15 +185,15 @@ def test_metrics(mini_sentry, relay):
{
"timestamp": time_after(timestamp),
"width": 1,
"name": "c:spans/bar@none",
"value": 17.0,
"name": "c:spans/foo@none",
"value": 42.0,
"type": "c",
},
{
"timestamp": time_after(timestamp),
"width": 1,
"name": "c:spans/foo@none",
"value": 42.0,
"name": "c:transactions/bar@none",
"value": 17.0,
"type": "c",
},
]
Expand Down
Loading