Skip to content

Commit 46e2b98

Browse files
authored
fix(metrics): Re-introduce transactions namespace (#5808)
1 parent 2dcfced commit 46e2b98

8 files changed

Lines changed: 39 additions & 8 deletions

File tree

relay-base-schema/src/metrics/mri.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ pub enum MetricNamespace {
110110
Sessions,
111111
/// Metrics extracted from spans.
112112
Spans,
113+
/// Metrics extracted from transactions.
114+
Transactions,
113115
/// User-defined metrics directly sent by SDKs and applications.
114116
Custom,
115117
/// An unknown and unsupported metric.
@@ -126,15 +128,22 @@ pub enum MetricNamespace {
126128

127129
impl MetricNamespace {
128130
/// Returns all namespaces/variants of this enum.
129-
pub fn all() -> [Self; 4] {
130-
[Self::Sessions, Self::Spans, Self::Custom, Self::Unsupported]
131+
pub fn all() -> [Self; 5] {
132+
[
133+
Self::Sessions,
134+
Self::Spans,
135+
Self::Transactions,
136+
Self::Custom,
137+
Self::Unsupported,
138+
]
131139
}
132140

133141
/// Returns the string representation for this metric type.
134142
pub fn as_str(&self) -> &'static str {
135143
match self {
136144
Self::Sessions => "sessions",
137145
Self::Spans => "spans",
146+
Self::Transactions => "transactions",
138147
Self::Custom => "custom",
139148
Self::Unsupported => "unsupported",
140149
}
@@ -148,6 +157,7 @@ impl std::str::FromStr for MetricNamespace {
148157
match ns {
149158
"sessions" => Ok(Self::Sessions),
150159
"spans" => Ok(Self::Spans),
160+
"transactions" => Ok(Self::Transactions),
151161
"custom" => Ok(Self::Custom),
152162
_ => Ok(Self::Unsupported),
153163
}

relay-cogs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ pub enum AppFeature {
176176

177177
/// Metrics in the spans namespace.
178178
MetricsSpans,
179+
/// Metrics in the transactions namespace.
180+
MetricsTransactions,
179181
/// Metrics in the sessions namespace.
180182
MetricsSessions,
181183
/// Metrics in the custom namespace.
@@ -207,6 +209,7 @@ impl AppFeature {
207209
Self::Replays => "replays",
208210
Self::UserReports => "user_reports",
209211
Self::MetricsSpans => "metrics_spans",
212+
Self::MetricsTransactions => "metrics_transactions",
210213
Self::MetricsSessions => "metrics_sessions",
211214
Self::MetricsCustom => "metrics_custom",
212215
Self::MetricsUnsupported => "metrics_unsupported",

relay-dynamic-config/src/global.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub enum CardinalityLimiterMode {
207207
#[serde(default)]
208208
pub struct BucketEncodings {
209209
spans: BucketEncoding,
210+
transactions: BucketEncoding,
210211
profiles: BucketEncoding,
211212
custom: BucketEncoding,
212213
}
@@ -216,6 +217,7 @@ impl BucketEncodings {
216217
pub fn for_namespace(&self, namespace: MetricNamespace) -> BucketEncoding {
217218
match namespace {
218219
MetricNamespace::Spans => self.spans,
220+
MetricNamespace::Transactions => self.transactions,
219221
MetricNamespace::Custom => self.custom,
220222
// Always force the legacy encoding for sessions,
221223
// sessions are not part of the generic metrics platform with different
@@ -249,6 +251,7 @@ where
249251
let encoding = BucketEncoding::deserialize(de::value::StrDeserializer::new(v))?;
250252
Ok(BucketEncodings {
251253
spans: encoding,
254+
transactions: encoding,
252255
profiles: encoding,
253256
custom: encoding,
254257
})
@@ -451,6 +454,7 @@ mod tests {
451454
o.metric_bucket_set_encodings,
452455
BucketEncodings {
453456
spans: BucketEncoding::Legacy,
457+
transactions: BucketEncoding::Legacy,
454458
profiles: BucketEncoding::Legacy,
455459
custom: BucketEncoding::Legacy,
456460
}
@@ -459,6 +463,7 @@ mod tests {
459463
o.metric_bucket_dist_encodings,
460464
BucketEncodings {
461465
spans: BucketEncoding::Zstd,
466+
transactions: BucketEncoding::Zstd,
462467
profiles: BucketEncoding::Zstd,
463468
custom: BucketEncoding::Zstd,
464469
}
@@ -469,6 +474,7 @@ mod tests {
469474
fn test_metric_bucket_encodings_de_from_obj() {
470475
let original = BucketEncodings {
471476
spans: BucketEncoding::Zstd,
477+
transactions: BucketEncoding::Zstd,
472478
profiles: BucketEncoding::Base64,
473479
custom: BucketEncoding::Zstd,
474480
};

relay-metrics/src/cogs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn to_app_feature(ns: MetricNamespace) -> AppFeature {
3939
match ns {
4040
MetricNamespace::Sessions => AppFeature::MetricsSessions,
4141
MetricNamespace::Spans => AppFeature::MetricsSpans,
42+
MetricNamespace::Transactions => AppFeature::MetricsTransactions,
4243
MetricNamespace::Custom => AppFeature::MetricsCustom,
4344
MetricNamespace::Unsupported => AppFeature::MetricsUnsupported,
4445
}

relay-metrics/src/utils.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct ByNamespace<T> {
1919
pub sessions: T,
2020
/// Value for the [`MetricNamespace::Spans`] namespace.
2121
pub spans: T,
22+
/// Value for the [`MetricNamespace::Transactions`] namespace.
23+
pub transactions: T,
2224
/// Value for the [`MetricNamespace::Custom`] namespace.
2325
pub custom: T,
2426
/// Value for the [`MetricNamespace::Unsupported`] namespace.
@@ -31,6 +33,7 @@ impl<T> ByNamespace<T> {
3133
match namespace {
3234
MetricNamespace::Sessions => &self.sessions,
3335
MetricNamespace::Spans => &self.spans,
36+
MetricNamespace::Transactions => &self.transactions,
3437
MetricNamespace::Custom => &self.custom,
3538
MetricNamespace::Unsupported => &self.unsupported,
3639
}
@@ -41,6 +44,7 @@ impl<T> ByNamespace<T> {
4144
match namespace {
4245
MetricNamespace::Sessions => &mut self.sessions,
4346
MetricNamespace::Spans => &mut self.spans,
47+
MetricNamespace::Transactions => &mut self.transactions,
4448
MetricNamespace::Custom => &mut self.custom,
4549
MetricNamespace::Unsupported => &mut self.unsupported,
4650
}
@@ -49,19 +53,21 @@ impl<T> ByNamespace<T> {
4953

5054
impl<T> IntoIterator for ByNamespace<T> {
5155
type Item = (MetricNamespace, T);
52-
type IntoIter = std::array::IntoIter<(MetricNamespace, T), 4>;
56+
type IntoIter = std::array::IntoIter<(MetricNamespace, T), 5>;
5357

5458
fn into_iter(self) -> Self::IntoIter {
5559
let Self {
5660
sessions,
5761
spans,
62+
transactions,
5863
custom,
5964
unsupported,
6065
} = self;
6166

6267
[
6368
(MetricNamespace::Sessions, sessions),
6469
(MetricNamespace::Spans, spans),
70+
(MetricNamespace::Transactions, transactions),
6571
(MetricNamespace::Custom, custom),
6672
(MetricNamespace::Unsupported, unsupported),
6773
]
@@ -104,12 +110,14 @@ macro_rules! impl_op {
104110
let Self {
105111
sessions,
106112
spans,
113+
transactions,
107114
custom,
108115
unsupported,
109116
} = self;
110117

111118
$op::$opfn(sessions, rhs.sessions);
112119
$op::$opfn(spans, rhs.spans);
120+
$op::$opfn(transactions, rhs.transactions);
113121
$op::$opfn(custom, rhs.custom);
114122
$op::$opfn(unsupported, rhs.unsupported);
115123
}

relay-server/src/services/processor/metrics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn is_valid_namespace(bucket: &Bucket) -> bool {
1515
match bucket.name.namespace() {
1616
MetricNamespace::Sessions => true,
1717
MetricNamespace::Spans => true,
18+
MetricNamespace::Transactions => true,
1819
MetricNamespace::Custom => true,
1920
MetricNamespace::Unsupported => false,
2021
}
@@ -56,6 +57,7 @@ fn is_metric_namespace_valid(state: &ProjectInfo, namespace: MetricNamespace) ->
5657
match namespace {
5758
MetricNamespace::Sessions => true,
5859
MetricNamespace::Spans => true,
60+
MetricNamespace::Transactions => true,
5961
MetricNamespace::Custom => state.has_feature(Feature::CustomMetrics),
6062
MetricNamespace::Unsupported => false,
6163
}

relay-server/src/services/store.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,7 @@ impl Message for KafkaMessage<'_> {
17381738
KafkaMessage::Metric { message, .. } => match message.name.namespace() {
17391739
MetricNamespace::Sessions => "metric_sessions",
17401740
MetricNamespace::Spans => "metric_spans",
1741+
MetricNamespace::Transactions => "metric_transactions",
17411742
MetricNamespace::Custom => "metric_custom",
17421743
MetricNamespace::Unsupported => "metric_unsupported",
17431744
},

tests/integration/test_metrics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_metrics(mini_sentry, relay):
169169
mini_sentry.add_basic_project_config(project_id)
170170

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

175175
envelope = mini_sentry.get_captured_envelope()
@@ -185,15 +185,15 @@ def test_metrics(mini_sentry, relay):
185185
{
186186
"timestamp": time_after(timestamp),
187187
"width": 1,
188-
"name": "c:spans/bar@none",
189-
"value": 17.0,
188+
"name": "c:spans/foo@none",
189+
"value": 42.0,
190190
"type": "c",
191191
},
192192
{
193193
"timestamp": time_after(timestamp),
194194
"width": 1,
195-
"name": "c:spans/foo@none",
196-
"value": 42.0,
195+
"name": "c:transactions/bar@none",
196+
"value": 17.0,
197197
"type": "c",
198198
},
199199
]

0 commit comments

Comments
 (0)