relay_dynamic_config/
feature.rs1use std::collections::BTreeSet;
2
3use serde::{Deserialize, Serialize};
4
5pub const GRADUATED_FEATURE_FLAGS: &[Feature] = &[
8 Feature::UserReportV2Ingest,
9 Feature::IngestUnsampledProfiles,
10 Feature::ScrubMongoDbDescriptions,
11];
12
13#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
15pub enum Feature {
16 #[serde(rename = "organizations:session-replay")]
20 SessionReplay,
21 #[serde(rename = "organizations:session-replay-recording-scrubbing")]
25 SessionReplayRecordingScrubbing,
26 #[serde(rename = "organizations:session-replay-video-disabled")]
30 SessionReplayVideoDisabled,
31 #[serde(rename = "organizations:device-class-synthesis")]
37 DeviceClassSynthesis,
38 #[serde(rename = "organizations:custom-metrics")]
42 CustomMetrics,
43 #[serde(rename = "organizations:profiling")]
47 Profiling,
48 #[serde(rename = "organizations:standalone-span-ingestion")]
52 StandaloneSpanIngestion,
53 #[serde(rename = "projects:relay-otel-endpoint")]
57 OtelEndpoint,
58 #[serde(rename = "organizations:relay-otel-logs-endpoint")]
62 OtelLogsEndpoint,
63 #[serde(rename = "organizations:relay-playstation-ingestion")]
67 PlaystationIngestion,
68 #[serde(rename = "projects:discard-transaction")]
72 DiscardTransaction,
73 #[serde(rename = "organizations:continuous-profiling")]
77 ContinuousProfiling,
78 #[serde(rename = "organizations:continuous-profiling-beta")]
82 ContinuousProfilingBeta,
83 #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
87 ContinuousProfilingBetaIngest,
88 #[serde(rename = "organizations:indexed-spans-extraction")]
92 ExtractSpansFromEvent,
93 #[serde(rename = "organizations:ourlogs-ingestion")]
97 OurLogsIngestion,
98 #[doc(hidden)]
100 #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
101 IngestUnsampledProfiles,
102 #[doc(hidden)]
104 #[serde(rename = "organizations:user-feedback-ingest")]
105 UserReportV2Ingest,
106 #[doc(hidden)]
108 #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
109 ScrubMongoDbDescriptions,
110 #[doc(hidden)]
111 #[serde(rename = "organizations:view-hierarchy-scrubbing")]
112 ViewHierarchyScrubbing,
113 #[serde(rename = "organizations:performance-issues-spans")]
115 PerformanceIssuesSpans,
116 #[serde(rename = "projects:span-v2-experimental-processing")]
118 SpanV2ExperimentalProcessing,
119 #[doc(hidden)]
121 #[serde(rename = "projects:span-metrics-extraction")]
122 DeprecatedExtractCommonSpanMetricsFromEvent,
123 #[doc(hidden)]
125 #[serde(rename = "projects:span-metrics-extraction-addons")]
126 DeprecatedExtractAddonsSpanMetricsFromEvent,
127 #[doc(hidden)]
129 #[serde(other)]
130 Unknown,
131}
132
133#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
135pub struct FeatureSet(pub BTreeSet<Feature>);
136
137impl FeatureSet {
138 pub fn is_empty(&self) -> bool {
140 self.0.is_empty()
141 }
142
143 pub fn has(&self, feature: Feature) -> bool {
145 self.0.contains(&feature)
146 }
147
148 pub fn produces_spans(&self) -> bool {
150 self.has(Feature::ExtractSpansFromEvent) || self.has(Feature::StandaloneSpanIngestion)
151 }
152}
153
154impl FromIterator<Feature> for FeatureSet {
155 fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
156 Self(BTreeSet::from_iter(iter))
157 }
158}
159
160impl<'de> Deserialize<'de> for FeatureSet {
161 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
162 where
163 D: serde::Deserializer<'de>,
164 {
165 let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
166 set.remove(&Feature::Unknown);
167 Ok(Self(set))
168 }
169}
170
171#[cfg(test)]
172mod tests {
173 use super::*;
174
175 #[test]
176 fn roundtrip() {
177 let features: FeatureSet =
178 serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
179 assert_eq!(
180 &features,
181 &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
182 );
183 assert_eq!(
184 serde_json::to_string(&features).unwrap(),
185 r#"["organizations:session-replay"]"#
186 );
187 }
188}