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 = "organizations:relay-otlp-traces-endpoint")]
57 OtelEndpoint,
58 #[serde(rename = "organizations:relay-otel-logs-endpoint")]
62 OtelLogsEndpoint,
63 #[serde(rename = "organizations:relay-vercel-log-drain-endpoint")]
67 VercelLogDrainEndpoint,
68 #[serde(rename = "organizations:relay-playstation-ingestion")]
72 PlaystationIngestion,
73 #[serde(rename = "projects:discard-transaction")]
77 DiscardTransaction,
78 #[serde(rename = "organizations:continuous-profiling")]
82 ContinuousProfiling,
83 #[serde(rename = "organizations:continuous-profiling-beta")]
87 ContinuousProfilingBeta,
88 #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
92 ContinuousProfilingBetaIngest,
93 #[serde(rename = "organizations:indexed-spans-extraction")]
97 ExtractSpansFromEvent,
98 #[serde(rename = "organizations:ourlogs-ingestion")]
102 OurLogsIngestion,
103 #[serde(rename = "organizations:tracemetrics-ingestion")]
107 TraceMetricsIngestion,
108 #[doc(hidden)]
110 #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
111 IngestUnsampledProfiles,
112 #[doc(hidden)]
114 #[serde(rename = "organizations:user-feedback-ingest")]
115 UserReportV2Ingest,
116 #[doc(hidden)]
118 #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
119 ScrubMongoDbDescriptions,
120 #[doc(hidden)]
121 #[serde(rename = "organizations:view-hierarchy-scrubbing")]
122 ViewHierarchyScrubbing,
123 #[serde(rename = "organizations:performance-issues-spans")]
125 PerformanceIssuesSpans,
126 #[serde(rename = "projects:span-v2-experimental-processing")]
128 SpanV2ExperimentalProcessing,
129 #[doc(hidden)]
131 #[serde(rename = "projects:span-metrics-extraction")]
132 DeprecatedExtractCommonSpanMetricsFromEvent,
133 #[doc(hidden)]
135 #[serde(rename = "projects:span-metrics-extraction-addons")]
136 DeprecatedExtractAddonsSpanMetricsFromEvent,
137 #[doc(hidden)]
139 #[serde(other)]
140 Unknown,
141}
142
143#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
145pub struct FeatureSet(pub BTreeSet<Feature>);
146
147impl FeatureSet {
148 pub fn is_empty(&self) -> bool {
150 self.0.is_empty()
151 }
152
153 pub fn has(&self, feature: Feature) -> bool {
155 self.0.contains(&feature)
156 }
157
158 pub fn produces_spans(&self) -> bool {
160 self.has(Feature::ExtractSpansFromEvent) || self.has(Feature::StandaloneSpanIngestion)
161 }
162}
163
164impl FromIterator<Feature> for FeatureSet {
165 fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
166 Self(BTreeSet::from_iter(iter))
167 }
168}
169
170impl<'de> Deserialize<'de> for FeatureSet {
171 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
172 where
173 D: serde::Deserializer<'de>,
174 {
175 let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
176 set.remove(&Feature::Unknown);
177 Ok(Self(set))
178 }
179}
180
181#[cfg(test)]
182mod tests {
183 use super::*;
184
185 #[test]
186 fn roundtrip() {
187 let features: FeatureSet =
188 serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
189 assert_eq!(
190 &features,
191 &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
192 );
193 assert_eq!(
194 serde_json::to_string(&features).unwrap(),
195 r#"["organizations:session-replay"]"#
196 );
197 }
198}