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 logs ingestion via the `/logs/` OTel endpoint.
59    ///
60    /// Serialized as `organizations:relay-otel-logs-endpoint`.
61    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
62    OtelLogsEndpoint,
63    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
64    ///
65    /// Serialized as `organizations:relay-playstation-ingestion`.
66    #[serde(rename = "organizations:relay-playstation-ingestion")]
67    PlaystationIngestion,
68    /// Discard transactions in a spans-only world.
69    ///
70    /// Serialized as `projects:discard-transaction`.
71    #[serde(rename = "projects:discard-transaction")]
72    DiscardTransaction,
73    /// Enable continuous profiling.
74    ///
75    /// Serialized as `organizations:continuous-profiling`.
76    #[serde(rename = "organizations:continuous-profiling")]
77    ContinuousProfiling,
78    /// Enabled for beta orgs
79    ///
80    /// Serialized as `organizations:continuous-profiling-beta`.
81    #[serde(rename = "organizations:continuous-profiling-beta")]
82    ContinuousProfilingBeta,
83    /// Enabled when only beta orgs are allowed to send continuous profiles.
84    ///
85    /// Serialized as `organizations:continuous-profiling-beta-ingest`.
86    #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
87    ContinuousProfilingBetaIngest,
88    /// When enabled, spans will be extracted from a transaction.
89    ///
90    /// Serialized as `organizations:indexed-spans-extraction`.
91    #[serde(rename = "organizations:indexed-spans-extraction")]
92    ExtractSpansFromEvent,
93    /// Enable log ingestion for our log product (this is not internal logging).
94    ///
95    /// Serialized as `organizations:ourlogs-ingestion`.
96    #[serde(rename = "organizations:ourlogs-ingestion")]
97    OurLogsIngestion,
98    /// This feature has graduated ant is hard-coded for external Relays.
99    #[doc(hidden)]
100    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
101    IngestUnsampledProfiles,
102    /// This feature has graduated and is hard-coded for external Relays.
103    #[doc(hidden)]
104    #[serde(rename = "organizations:user-feedback-ingest")]
105    UserReportV2Ingest,
106    /// This feature has graduated and is hard-coded for external Relays.
107    #[doc(hidden)]
108    #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
109    ScrubMongoDbDescriptions,
110    #[doc(hidden)]
111    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
112    ViewHierarchyScrubbing,
113    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
114    #[serde(rename = "organizations:performance-issues-spans")]
115    PerformanceIssuesSpans,
116    /// Enables the experimental Span V2 processing pipeline in Relay.
117    #[serde(rename = "projects:span-v2-experimental-processing")]
118    SpanV2ExperimentalProcessing,
119    /// This feature has deprecated and is kept for external Relays.
120    #[doc(hidden)]
121    #[serde(rename = "projects:span-metrics-extraction")]
122    DeprecatedExtractCommonSpanMetricsFromEvent,
123    /// This feature has been deprecated and is kept for external Relays.
124    #[doc(hidden)]
125    #[serde(rename = "projects:span-metrics-extraction-addons")]
126    DeprecatedExtractAddonsSpanMetricsFromEvent,
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) || self.has(Feature::StandaloneSpanIngestion)
151    }
152}
153
154impl FromIterator<Feature> for FeatureSet {
155    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
156        Self(BTreeSet::from_iter(iter))
157    }
158}
159
160impl<'de> Deserialize<'de> for FeatureSet {
161    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
162    where
163        D: serde::Deserializer<'de>,
164    {
165        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
166        set.remove(&Feature::Unknown);
167        Ok(Self(set))
168    }
169}
170
171#[cfg(test)]
172mod tests {
173    use super::*;
174
175    #[test]
176    fn roundtrip() {
177        let features: FeatureSet =
178            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
179        assert_eq!(
180            &features,
181            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
182        );
183        assert_eq!(
184            serde_json::to_string(&features).unwrap(),
185            r#"["organizations:session-replay"]"#
186        );
187    }
188}