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    /// Enables metric extraction from spans for common modules.
84    ///
85    /// Serialized as `projects:span-metrics-extraction`.
86    #[serde(rename = "projects:span-metrics-extraction")]
87    ExtractCommonSpanMetricsFromEvent,
88    /// Enables metric extraction from spans for addon modules.
89    ///
90    /// Serialized as `projects:span-metrics-extraction-addons`.
91    #[serde(rename = "projects:span-metrics-extraction-addons")]
92    ExtractAddonsSpanMetricsFromEvent,
93    /// When enabled, spans will be extracted from a transaction.
94    ///
95    /// Serialized as `organizations:indexed-spans-extraction`.
96    #[serde(rename = "organizations:indexed-spans-extraction")]
97    ExtractSpansFromEvent,
98    /// Enable log ingestion for our log product (this is not internal logging).
99    ///
100    /// Serialized as `organizations:ourlogs-ingestion`.
101    #[serde(rename = "organizations:ourlogs-ingestion")]
102    OurLogsIngestion,
103    /// Use a new/alternative way of counting bytes per log.
104    #[serde(rename = "organizations:ourlogs-calculated-byte-count")]
105    OurLogsCalculatedByteCount,
106    /// This feature has graduated and is hard-coded for external Relays.
107    #[doc(hidden)]
108    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
109    IngestUnsampledProfiles,
110    /// This feature has graduated and is hard-coded for external Relays.
111    #[doc(hidden)]
112    #[serde(rename = "organizations:user-feedback-ingest")]
113    UserReportV2Ingest,
114    /// This feature has graduated and is hard-coded for external Relays.
115    #[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    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
122    #[serde(rename = "organizations:performance-issues-spans")]
123    PerformanceIssuesSpans,
124    /// Forward compatibility.
125    #[doc(hidden)]
126    #[serde(other)]
127    Unknown,
128}
129
130/// A set of [`Feature`]s.
131#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
132pub struct FeatureSet(pub BTreeSet<Feature>);
133
134impl FeatureSet {
135    /// Returns `true` if the set of features is empty.
136    pub fn is_empty(&self) -> bool {
137        self.0.is_empty()
138    }
139
140    /// Returns `true` if the given feature is in the set.
141    pub fn has(&self, feature: Feature) -> bool {
142        self.0.contains(&feature)
143    }
144
145    /// Returns `true` if any spans are produced for this project.
146    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}