relay_dynamic_config/
feature.rs

1use std::collections::BTreeSet;
2
3use serde::{Deserialize, Serialize};
4
5/// Feature flags of graduated features are no longer sent by sentry, but Relay needs to insert them
6/// for outdated downstream Relays that may still rely on the feature flag.
7pub const GRADUATED_FEATURE_FLAGS: &[Feature] = &[
8    Feature::UserReportV2Ingest,
9    Feature::IngestUnsampledProfiles,
10    Feature::ScrubMongoDbDescriptions,
11];
12
13/// Features exposed by project config.
14#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
15pub enum Feature {
16    /// Enables ingestion of Session Replays (Replay Recordings and Replay Events).
17    ///
18    /// Serialized as `organizations:session-replay`.
19    #[serde(rename = "organizations:session-replay")]
20    SessionReplay,
21    /// Enables data scrubbing of replay recording payloads.
22    ///
23    /// Serialized as `organizations:session-replay-recording-scrubbing`.
24    #[serde(rename = "organizations:session-replay-recording-scrubbing")]
25    SessionReplayRecordingScrubbing,
26    /// Enables combining session replay envelope items (Replay Recordings and Replay Events).
27    /// into one Kafka message.
28    ///
29    /// Serialized as `organizations:session-replay-combined-envelope-items`.
30    #[serde(rename = "organizations:session-replay-combined-envelope-items")]
31    SessionReplayCombinedEnvelopeItems,
32    /// Disables select organizations from processing mobile replay events.
33    ///
34    /// Serialized as `organizations:session-replay-video-disabled`.
35    #[serde(rename = "organizations:session-replay-video-disabled")]
36    SessionReplayVideoDisabled,
37    /// Enables device.class synthesis
38    ///
39    /// Enables device.class tag synthesis on mobile events.
40    ///
41    /// Serialized as `organizations:device-class-synthesis`.
42    #[serde(rename = "organizations:device-class-synthesis")]
43    DeviceClassSynthesis,
44    /// Allow ingestion of metrics in the "custom" namespace.
45    ///
46    /// Serialized as `organizations:custom-metrics`.
47    #[serde(rename = "organizations:custom-metrics")]
48    CustomMetrics,
49    /// Enable processing profiles.
50    ///
51    /// Serialized as `organizations:profiling`.
52    #[serde(rename = "organizations:profiling")]
53    Profiling,
54    /// Enable standalone span ingestion.
55    ///
56    /// Serialized as `organizations:standalone-span-ingestion`.
57    #[serde(rename = "organizations:standalone-span-ingestion")]
58    StandaloneSpanIngestion,
59    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
60    ///
61    /// Serialized as `projects:relay-otel-endpoint`.
62    #[serde(rename = "projects:relay-otel-endpoint")]
63    OtelEndpoint,
64    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
65    ///
66    /// Serialized as `project:relay-playstation-ingestion`.
67    #[serde(rename = "projects:relay-playstation-ingestion")]
68    PlaystationIngestion,
69    /// Discard transactions in a spans-only world.
70    ///
71    /// Serialized as `projects:discard-transaction`.
72    #[serde(rename = "projects:discard-transaction")]
73    DiscardTransaction,
74    /// Enable continuous profiling.
75    ///
76    /// Serialized as `organizations:continuous-profiling`.
77    #[serde(rename = "organizations:continuous-profiling")]
78    ContinuousProfiling,
79    /// Enabled for beta orgs
80    ///
81    /// Serialized as `organizations:continuous-profiling-beta`.
82    #[serde(rename = "organizations:continuous-profiling-beta")]
83    ContinuousProfilingBeta,
84    /// Enabled when only beta orgs are allowed to send continuous profiles.
85    ///
86    /// Serialized as `organizations:continuous-profiling-beta-ingest`.
87    #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
88    ContinuousProfilingBetaIngest,
89    /// Enables metric extraction from spans for common modules.
90    ///
91    /// Serialized as `projects:span-metrics-extraction`.
92    #[serde(rename = "projects:span-metrics-extraction")]
93    ExtractCommonSpanMetricsFromEvent,
94    /// Enables metric extraction from spans for addon modules.
95    ///
96    /// Serialized as `projects:span-metrics-extraction-addons`.
97    #[serde(rename = "projects:span-metrics-extraction-addons")]
98    ExtractAddonsSpanMetricsFromEvent,
99    /// When enabled, spans will be extracted from a transaction.
100    ///
101    /// Serialized as `organizations:indexed-spans-extraction`.
102    #[serde(rename = "organizations:indexed-spans-extraction")]
103    ExtractSpansFromEvent,
104    /// Enable log ingestion for our log product (this is not internal logging).
105    ///
106    /// Serialized as `organizations:ourlogs-ingestion`.
107    #[serde(rename = "organizations:ourlogs-ingestion")]
108    OurLogsIngestion,
109    /// This feature has graduated and is hard-coded for external Relays.
110    #[doc(hidden)]
111    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
112    IngestUnsampledProfiles,
113    /// This feature has graduated and is hard-coded for external Relays.
114    #[doc(hidden)]
115    #[serde(rename = "organizations:user-feedback-ingest")]
116    UserReportV2Ingest,
117    /// This feature has graduated and is hard-coded for external Relays.
118    #[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    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
125    #[serde(rename = "organizations:performance-issues-spans")]
126    PerformanceIssuesSpans,
127    /// Forward compatibility.
128    #[doc(hidden)]
129    #[serde(other)]
130    Unknown,
131}
132
133/// A set of [`Feature`]s.
134#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
135pub struct FeatureSet(pub BTreeSet<Feature>);
136
137impl FeatureSet {
138    /// Returns `true` if the set of features is empty.
139    pub fn is_empty(&self) -> bool {
140        self.0.is_empty()
141    }
142
143    /// Returns `true` if the given feature is in the set.
144    pub fn has(&self, feature: Feature) -> bool {
145        self.0.contains(&feature)
146    }
147
148    /// Returns `true` if any spans are produced for this project.
149    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}