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
95 #[serde(rename = "projects:span-metrics-extraction-addons")]
99 ExtractAddonsSpanMetricsFromEvent,
100 #[serde(rename = "organizations:indexed-spans-extraction")]
104 ExtractSpansFromEvent,
105 #[serde(rename = "organizations:ingest-spans-in-eap")]
109 IngestSpansInEapForOrganization,
110 #[serde(rename = "projects:ingest-spans-in-eap")]
114 IngestSpansInEapForProject,
115 #[serde(rename = "organizations:ourlogs-ingestion")]
119 OurLogsIngestion,
120 #[doc(hidden)]
122 #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
123 IngestUnsampledProfiles,
124 #[doc(hidden)]
126 #[serde(rename = "organizations:user-feedback-ingest")]
127 UserReportV2Ingest,
128 #[doc(hidden)]
130 #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
131 ScrubMongoDbDescriptions,
132 #[doc(hidden)]
133 #[serde(rename = "organizations:view-hierarchy-scrubbing")]
134 ViewHierarchyScrubbing,
135 #[serde(rename = "organizations:performance-issues-spans")]
137 PerformanceIssuesSpans,
138 #[doc(hidden)]
140 #[serde(other)]
141 Unknown,
142}
143
144#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
146pub struct FeatureSet(pub BTreeSet<Feature>);
147
148impl FeatureSet {
149 pub fn is_empty(&self) -> bool {
151 self.0.is_empty()
152 }
153
154 pub fn has(&self, feature: Feature) -> bool {
156 self.0.contains(&feature)
157 }
158
159 pub fn produces_spans(&self) -> bool {
161 self.has(Feature::ExtractSpansFromEvent)
162 || self.has(Feature::StandaloneSpanIngestion)
163 || self.has(Feature::ExtractCommonSpanMetricsFromEvent)
164 }
165}
166
167impl FromIterator<Feature> for FeatureSet {
168 fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
169 Self(BTreeSet::from_iter(iter))
170 }
171}
172
173impl<'de> Deserialize<'de> for FeatureSet {
174 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
175 where
176 D: serde::Deserializer<'de>,
177 {
178 let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
179 set.remove(&Feature::Unknown);
180 Ok(Self(set))
181 }
182}
183
184#[cfg(test)]
185mod tests {
186 use super::*;
187
188 #[test]
189 fn roundtrip() {
190 let features: FeatureSet =
191 serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
192 assert_eq!(
193 &features,
194 &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
195 );
196 assert_eq!(
197 serde_json::to_string(&features).unwrap(),
198 r#"["organizations:session-replay"]"#
199 );
200 }
201}