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    /// Disables select organizations from processing mobile replay events.
27    ///
28    /// Serialized as `organizations:session-replay-video-disabled`.
29    #[serde(rename = "organizations:session-replay-video-disabled")]
30    SessionReplayVideoDisabled,
31    /// Enables device.class synthesis
32    ///
33    /// Enables device.class tag synthesis on mobile events.
34    ///
35    /// Serialized as `organizations:device-class-synthesis`.
36    #[serde(rename = "organizations:device-class-synthesis")]
37    DeviceClassSynthesis,
38    /// Allow ingestion of metrics in the "custom" namespace.
39    ///
40    /// Serialized as `organizations:custom-metrics`.
41    #[serde(rename = "organizations:custom-metrics")]
42    CustomMetrics,
43    /// Enable processing profiles.
44    ///
45    /// Serialized as `organizations:profiling`.
46    #[serde(rename = "organizations:profiling")]
47    Profiling,
48    /// Enable standalone span ingestion.
49    ///
50    /// Serialized as `organizations:standalone-span-ingestion`.
51    #[serde(rename = "organizations:standalone-span-ingestion")]
52    StandaloneSpanIngestion,
53    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
54    ///
55    /// Serialized as `projects:relay-otel-endpoint`.
56    #[serde(rename = "projects:relay-otel-endpoint")]
57    OtelEndpoint,
58    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
59    ///
60    /// Serialized as `organizations:relay-playstation-ingestion`.
61    #[serde(rename = "organizations:relay-playstation-ingestion")]
62    PlaystationIngestion,
63    /// Discard transactions in a spans-only world.
64    ///
65    /// Serialized as `projects:discard-transaction`.
66    #[serde(rename = "projects:discard-transaction")]
67    DiscardTransaction,
68    /// Enable continuous profiling.
69    ///
70    /// Serialized as `organizations:continuous-profiling`.
71    #[serde(rename = "organizations:continuous-profiling")]
72    ContinuousProfiling,
73    /// Enabled for beta orgs
74    ///
75    /// Serialized as `organizations:continuous-profiling-beta`.
76    #[serde(rename = "organizations:continuous-profiling-beta")]
77    ContinuousProfilingBeta,
78    /// Enabled when only beta orgs are allowed to send continuous profiles.
79    ///
80    /// Serialized as `organizations:continuous-profiling-beta-ingest`.
81    #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
82    ContinuousProfilingBetaIngest,
83    /// When enabled, spans will be extracted from a transaction.
84    ///
85    /// Serialized as `organizations:indexed-spans-extraction`.
86    #[serde(rename = "organizations:indexed-spans-extraction")]
87    ExtractSpansFromEvent,
88    /// Enable log ingestion for our log product (this is not internal logging).
89    ///
90    /// Serialized as `organizations:ourlogs-ingestion`.
91    #[serde(rename = "organizations:ourlogs-ingestion")]
92    OurLogsIngestion,
93    /// This feature has graduated ant is hard-coded for external Relays.
94    #[doc(hidden)]
95    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
96    IngestUnsampledProfiles,
97    /// This feature has graduated and is hard-coded for external Relays.
98    #[doc(hidden)]
99    #[serde(rename = "organizations:user-feedback-ingest")]
100    UserReportV2Ingest,
101    /// This feature has graduated and is hard-coded for external Relays.
102    #[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    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
109    #[serde(rename = "organizations:performance-issues-spans")]
110    PerformanceIssuesSpans,
111    /// This feature has deprecated and is kept for external Relays.
112    #[doc(hidden)]
113    #[serde(rename = "projects:span-metrics-extraction")]
114    DeprecatedExtractCommonSpanMetricsFromEvent,
115    /// This feature has been deprecated and is kept for external Relays.
116    #[doc(hidden)]
117    #[serde(rename = "projects:span-metrics-extraction-addons")]
118    DeprecatedExtractAddonsSpanMetricsFromEvent,
119    /// Forward compatibility.
120    #[doc(hidden)]
121    #[serde(other)]
122    Unknown,
123}
124
125/// A set of [`Feature`]s.
126#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
127pub struct FeatureSet(pub BTreeSet<Feature>);
128
129impl FeatureSet {
130    /// Returns `true` if the set of features is empty.
131    pub fn is_empty(&self) -> bool {
132        self.0.is_empty()
133    }
134
135    /// Returns `true` if the given feature is in the set.
136    pub fn has(&self, feature: Feature) -> bool {
137        self.0.contains(&feature)
138    }
139
140    /// Returns `true` if any spans are produced for this project.
141    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}