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-playstation-ingestion")]
62 PlaystationIngestion,
63 #[serde(rename = "projects:discard-transaction")]
67 DiscardTransaction,
68 #[serde(rename = "organizations:continuous-profiling")]
72 ContinuousProfiling,
73 #[serde(rename = "organizations:continuous-profiling-beta")]
77 ContinuousProfilingBeta,
78 #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
82 ContinuousProfilingBetaIngest,
83 #[serde(rename = "projects:span-metrics-extraction")]
87 ExtractCommonSpanMetricsFromEvent,
88 #[serde(rename = "projects:span-metrics-extraction-addons")]
92 ExtractAddonsSpanMetricsFromEvent,
93 #[serde(rename = "organizations:indexed-spans-extraction")]
97 ExtractSpansFromEvent,
98 #[serde(rename = "organizations:ourlogs-ingestion")]
102 OurLogsIngestion,
103 #[serde(rename = "organizations:ourlogs-calculated-byte-count")]
105 OurLogsCalculatedByteCount,
106 #[doc(hidden)]
108 #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
109 IngestUnsampledProfiles,
110 #[doc(hidden)]
112 #[serde(rename = "organizations:user-feedback-ingest")]
113 UserReportV2Ingest,
114 #[doc(hidden)]
116 #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
117 ScrubMongoDbDescriptions,
118 #[doc(hidden)]
119 #[serde(rename = "organizations:view-hierarchy-scrubbing")]
120 ViewHierarchyScrubbing,
121 #[serde(rename = "organizations:performance-issues-spans")]
123 PerformanceIssuesSpans,
124 #[doc(hidden)]
126 #[serde(other)]
127 Unknown,
128}
129
130#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
132pub struct FeatureSet(pub BTreeSet<Feature>);
133
134impl FeatureSet {
135 pub fn is_empty(&self) -> bool {
137 self.0.is_empty()
138 }
139
140 pub fn has(&self, feature: Feature) -> bool {
142 self.0.contains(&feature)
143 }
144
145 pub fn produces_spans(&self) -> bool {
147 self.has(Feature::ExtractSpansFromEvent)
148 || self.has(Feature::StandaloneSpanIngestion)
149 || self.has(Feature::ExtractCommonSpanMetricsFromEvent)
150 }
151}
152
153impl FromIterator<Feature> for FeatureSet {
154 fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
155 Self(BTreeSet::from_iter(iter))
156 }
157}
158
159impl<'de> Deserialize<'de> for FeatureSet {
160 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
161 where
162 D: serde::Deserializer<'de>,
163 {
164 let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
165 set.remove(&Feature::Unknown);
166 Ok(Self(set))
167 }
168}
169
170#[cfg(test)]
171mod tests {
172 use super::*;
173
174 #[test]
175 fn roundtrip() {
176 let features: FeatureSet =
177 serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
178 assert_eq!(
179 &features,
180 &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
181 );
182 assert_eq!(
183 serde_json::to_string(&features).unwrap(),
184 r#"["organizations:session-replay"]"#
185 );
186 }
187}