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-combined-envelope-items")]
31 SessionReplayCombinedEnvelopeItems,
32 #[serde(rename = "organizations:session-replay-video-disabled")]
36 SessionReplayVideoDisabled,
37 #[serde(rename = "organizations:device-class-synthesis")]
43 DeviceClassSynthesis,
44 #[serde(rename = "organizations:custom-metrics")]
48 CustomMetrics,
49 #[serde(rename = "organizations:profiling")]
53 Profiling,
54 #[serde(rename = "organizations:standalone-span-ingestion")]
58 StandaloneSpanIngestion,
59 #[serde(rename = "projects:relay-otel-endpoint")]
63 OtelEndpoint,
64 #[serde(rename = "projects:relay-playstation-ingestion")]
68 PlaystationIngestion,
69 #[serde(rename = "projects:discard-transaction")]
73 DiscardTransaction,
74 #[serde(rename = "organizations:continuous-profiling")]
78 ContinuousProfiling,
79 #[serde(rename = "organizations:continuous-profiling-beta")]
83 ContinuousProfilingBeta,
84 #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
88 ContinuousProfilingBetaIngest,
89 #[serde(rename = "projects:span-metrics-extraction")]
93 ExtractCommonSpanMetricsFromEvent,
94 #[serde(rename = "projects:span-metrics-extraction-addons")]
98 ExtractAddonsSpanMetricsFromEvent,
99 #[serde(rename = "organizations:indexed-spans-extraction")]
103 ExtractSpansFromEvent,
104 #[serde(rename = "organizations:ourlogs-ingestion")]
108 OurLogsIngestion,
109 #[doc(hidden)]
111 #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
112 IngestUnsampledProfiles,
113 #[doc(hidden)]
115 #[serde(rename = "organizations:user-feedback-ingest")]
116 UserReportV2Ingest,
117 #[doc(hidden)]
119 #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
120 ScrubMongoDbDescriptions,
121 #[doc(hidden)]
122 #[serde(rename = "organizations:view-hierarchy-scrubbing")]
123 ViewHierarchyScrubbing,
124 #[serde(rename = "organizations:performance-issues-spans")]
126 PerformanceIssuesSpans,
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)
151 || self.has(Feature::StandaloneSpanIngestion)
152 || self.has(Feature::ExtractCommonSpanMetricsFromEvent)
153 }
154}
155
156impl FromIterator<Feature> for FeatureSet {
157 fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
158 Self(BTreeSet::from_iter(iter))
159 }
160}
161
162impl<'de> Deserialize<'de> for FeatureSet {
163 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
164 where
165 D: serde::Deserializer<'de>,
166 {
167 let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
168 set.remove(&Feature::Unknown);
169 Ok(Self(set))
170 }
171}
172
173#[cfg(test)]
174mod tests {
175 use super::*;
176
177 #[test]
178 fn roundtrip() {
179 let features: FeatureSet =
180 serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
181 assert_eq!(
182 &features,
183 &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
184 );
185 assert_eq!(
186 serde_json::to_string(&features).unwrap(),
187 r#"["organizations:session-replay"]"#
188 );
189 }
190}