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
95    /// Enables metric extraction from spans for addon modules.
96    ///
97    /// Serialized as `projects:span-metrics-extraction-addons`.
98    #[serde(rename = "projects:span-metrics-extraction-addons")]
99    ExtractAddonsSpanMetricsFromEvent,
100    /// When enabled, spans will be extracted from a transaction.
101    ///
102    /// Serialized as `organizations:indexed-spans-extraction`.
103    #[serde(rename = "organizations:indexed-spans-extraction")]
104    ExtractSpansFromEvent,
105    /// Indicate if the EAP consumers should ingest a span for a given organization.
106    ///
107    /// Serialized as `organizations:ingest-spans-in-eap`
108    #[serde(rename = "organizations:ingest-spans-in-eap")]
109    IngestSpansInEapForOrganization,
110    /// Indicate if the EAP consumers should ingest a span for a given project.
111    ///
112    /// Serialized as `projects:ingest-spans-in-eap`
113    #[serde(rename = "projects:ingest-spans-in-eap")]
114    IngestSpansInEapForProject,
115    /// Enable log ingestion for our log product (this is not internal logging).
116    ///
117    /// Serialized as `organizations:ourlogs-ingestion`.
118    #[serde(rename = "organizations:ourlogs-ingestion")]
119    OurLogsIngestion,
120    /// This feature has graduated and is hard-coded for external Relays.
121    #[doc(hidden)]
122    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
123    IngestUnsampledProfiles,
124    /// This feature has graduated and is hard-coded for external Relays.
125    #[doc(hidden)]
126    #[serde(rename = "organizations:user-feedback-ingest")]
127    UserReportV2Ingest,
128    /// This feature has graduated and is hard-coded for external Relays.
129    #[doc(hidden)]
130    #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
131    ScrubMongoDbDescriptions,
132    #[doc(hidden)]
133    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
134    ViewHierarchyScrubbing,
135    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
136    #[serde(rename = "organizations:performance-issues-spans")]
137    PerformanceIssuesSpans,
138    /// Forward compatibility.
139    #[doc(hidden)]
140    #[serde(other)]
141    Unknown,
142}
143
144/// A set of [`Feature`]s.
145#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
146pub struct FeatureSet(pub BTreeSet<Feature>);
147
148impl FeatureSet {
149    /// Returns `true` if the set of features is empty.
150    pub fn is_empty(&self) -> bool {
151        self.0.is_empty()
152    }
153
154    /// Returns `true` if the given feature is in the set.
155    pub fn has(&self, feature: Feature) -> bool {
156        self.0.contains(&feature)
157    }
158
159    /// Returns `true` if any spans are produced for this project.
160    pub fn produces_spans(&self) -> bool {
161        self.has(Feature::ExtractSpansFromEvent)
162            || self.has(Feature::StandaloneSpanIngestion)
163            || self.has(Feature::ExtractCommonSpanMetricsFromEvent)
164    }
165}
166
167impl FromIterator<Feature> for FeatureSet {
168    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
169        Self(BTreeSet::from_iter(iter))
170    }
171}
172
173impl<'de> Deserialize<'de> for FeatureSet {
174    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
175    where
176        D: serde::Deserializer<'de>,
177    {
178        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
179        set.remove(&Feature::Unknown);
180        Ok(Self(set))
181    }
182}
183
184#[cfg(test)]
185mod tests {
186    use super::*;
187
188    #[test]
189    fn roundtrip() {
190        let features: FeatureSet =
191            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
192        assert_eq!(
193            &features,
194            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
195        );
196        assert_eq!(
197            serde_json::to_string(&features).unwrap(),
198            r#"["organizations:session-replay"]"#
199        );
200    }
201}