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 = "organizations:indexed-spans-extraction")]
87 ExtractSpansFromEvent,
88 #[serde(rename = "organizations:ourlogs-ingestion")]
92 OurLogsIngestion,
93 #[doc(hidden)]
95 #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
96 IngestUnsampledProfiles,
97 #[doc(hidden)]
99 #[serde(rename = "organizations:user-feedback-ingest")]
100 UserReportV2Ingest,
101 #[doc(hidden)]
103 #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
104 ScrubMongoDbDescriptions,
105 #[doc(hidden)]
106 #[serde(rename = "organizations:view-hierarchy-scrubbing")]
107 ViewHierarchyScrubbing,
108 #[serde(rename = "organizations:performance-issues-spans")]
110 PerformanceIssuesSpans,
111 #[doc(hidden)]
113 #[serde(rename = "projects:span-metrics-extraction")]
114 DeprecatedExtractCommonSpanMetricsFromEvent,
115 #[doc(hidden)]
117 #[serde(rename = "projects:span-metrics-extraction-addons")]
118 DeprecatedExtractAddonsSpanMetricsFromEvent,
119 #[doc(hidden)]
121 #[serde(other)]
122 Unknown,
123}
124
125#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
127pub struct FeatureSet(pub BTreeSet<Feature>);
128
129impl FeatureSet {
130 pub fn is_empty(&self) -> bool {
132 self.0.is_empty()
133 }
134
135 pub fn has(&self, feature: Feature) -> bool {
137 self.0.contains(&feature)
138 }
139
140 pub fn produces_spans(&self) -> bool {
142 self.has(Feature::ExtractSpansFromEvent) || self.has(Feature::StandaloneSpanIngestion)
143 }
144}
145
146impl FromIterator<Feature> for FeatureSet {
147 fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
148 Self(BTreeSet::from_iter(iter))
149 }
150}
151
152impl<'de> Deserialize<'de> for FeatureSet {
153 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
154 where
155 D: serde::Deserializer<'de>,
156 {
157 let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
158 set.remove(&Feature::Unknown);
159 Ok(Self(set))
160 }
161}
162
163#[cfg(test)]
164mod tests {
165 use super::*;
166
167 #[test]
168 fn roundtrip() {
169 let features: FeatureSet =
170 serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
171 assert_eq!(
172 &features,
173 &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
174 );
175 assert_eq!(
176 serde_json::to_string(&features).unwrap(),
177 r#"["organizations:session-replay"]"#
178 );
179 }
180}