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    Feature::DeprecatedExtractSpansFromEvent,
12];
13
14/// Features exposed by project config.
15#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
16pub enum Feature {
17    /// Enables ingestion of Session Replays (Replay Recordings and Replay Events).
18    ///
19    /// Serialized as `organizations:session-replay`.
20    #[serde(rename = "organizations:session-replay")]
21    SessionReplay,
22    /// Enables data scrubbing of replay recording payloads.
23    ///
24    /// Serialized as `organizations:session-replay-recording-scrubbing`.
25    #[serde(rename = "organizations:session-replay-recording-scrubbing")]
26    SessionReplayRecordingScrubbing,
27    /// Disables select organizations from processing mobile replay events.
28    ///
29    /// Serialized as `organizations:session-replay-video-disabled`.
30    #[serde(rename = "organizations:session-replay-video-disabled")]
31    SessionReplayVideoDisabled,
32    /// Enables device.class synthesis
33    ///
34    /// Enables device.class tag synthesis on mobile events.
35    ///
36    /// Serialized as `organizations:device-class-synthesis`.
37    #[serde(rename = "organizations:device-class-synthesis")]
38    DeviceClassSynthesis,
39    /// Allow ingestion of metrics in the "custom" namespace.
40    ///
41    /// Serialized as `organizations:custom-metrics`.
42    #[serde(rename = "organizations:custom-metrics")]
43    CustomMetrics,
44    /// Enable processing profiles.
45    ///
46    /// Serialized as `organizations:profiling`.
47    #[serde(rename = "organizations:profiling")]
48    Profiling,
49    /// Enable standalone span ingestion.
50    ///
51    /// Serialized as `organizations:standalone-span-ingestion`.
52    #[serde(rename = "organizations:standalone-span-ingestion")]
53    StandaloneSpanIngestion,
54    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
55    ///
56    /// Serialized as `organizations:relay-otlp-traces-endpoint`.
57    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
58    OtelTracesEndpoint,
59    /// Enable logs ingestion via the `/logs/` OTel endpoint.
60    ///
61    /// Serialized as `organizations:relay-otel-logs-endpoint`.
62    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
63    OtelLogsEndpoint,
64    /// Enable logs ingestion via the Vercel Log Drain endpoint.
65    ///
66    /// Serialized as `organizations:relay-vercel-log-drain-endpoint`.
67    #[serde(rename = "organizations:relay-vercel-log-drain-endpoint")]
68    VercelLogDrainEndpoint,
69    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
70    ///
71    /// Serialized as `organizations:relay-playstation-ingestion`.
72    #[serde(rename = "organizations:relay-playstation-ingestion")]
73    PlaystationIngestion,
74    /// Discard transactions in a spans-only world.
75    ///
76    /// Serialized as `projects:discard-transaction`.
77    #[serde(rename = "projects:discard-transaction")]
78    DiscardTransaction,
79    /// Enable continuous profiling.
80    ///
81    /// Serialized as `organizations:continuous-profiling`.
82    #[serde(rename = "organizations:continuous-profiling")]
83    ContinuousProfiling,
84    /// Enabled for beta orgs
85    ///
86    /// Serialized as `organizations:continuous-profiling-beta`.
87    #[serde(rename = "organizations:continuous-profiling-beta")]
88    ContinuousProfilingBeta,
89    /// Enabled when only beta orgs are allowed to send continuous profiles.
90    ///
91    /// Serialized as `organizations:continuous-profiling-beta-ingest`.
92    #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
93    ContinuousProfilingBetaIngest,
94    /// Enable log ingestion for our log product (this is not internal logging).
95    ///
96    /// Serialized as `organizations:ourlogs-ingestion`.
97    #[serde(rename = "organizations:ourlogs-ingestion")]
98    OurLogsIngestion,
99    /// Enable trace metric ingestion for our trace metric product.
100    ///
101    /// Serialized as `organizations:tracemetrics-ingestion`.
102    #[serde(rename = "organizations:tracemetrics-ingestion")]
103    TraceMetricsIngestion,
104    /// This feature has graduated ant is hard-coded for external Relays.
105    #[doc(hidden)]
106    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
107    IngestUnsampledProfiles,
108    /// This feature has graduated and is hard-coded for external Relays.
109    #[doc(hidden)]
110    #[serde(rename = "organizations:user-feedback-ingest")]
111    UserReportV2Ingest,
112    /// This feature has graduated and is hard-coded for external Relays.
113    #[doc(hidden)]
114    #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
115    ScrubMongoDbDescriptions,
116    #[doc(hidden)]
117    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
118    ViewHierarchyScrubbing,
119    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
120    #[serde(rename = "organizations:performance-issues-spans")]
121    PerformanceIssuesSpans,
122    /// Enables the experimental Span V2 processing pipeline in Relay.
123    #[serde(rename = "projects:span-v2-experimental-processing")]
124    SpanV2ExperimentalProcessing,
125    /// This feature has deprecated and is kept for external Relays.
126    #[doc(hidden)]
127    #[serde(rename = "projects:span-metrics-extraction")]
128    DeprecatedExtractCommonSpanMetricsFromEvent,
129    /// This feature has been deprecated and is kept for external Relays.
130    #[doc(hidden)]
131    #[serde(rename = "projects:span-metrics-extraction-addons")]
132    DeprecatedExtractAddonsSpanMetricsFromEvent,
133    /// This feature has graduated and is hard-coded for external Relays.
134    #[doc(hidden)]
135    #[serde(rename = "organizations:indexed-spans-extraction")]
136    DeprecatedExtractSpansFromEvent,
137    /// Forward compatibility.
138    #[doc(hidden)]
139    #[serde(other)]
140    Unknown,
141}
142
143/// A set of [`Feature`]s.
144#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
145pub struct FeatureSet(pub BTreeSet<Feature>);
146
147impl FeatureSet {
148    /// Returns `true` if the set of features is empty.
149    pub fn is_empty(&self) -> bool {
150        self.0.is_empty()
151    }
152
153    /// Returns `true` if the given feature is in the set.
154    pub fn has(&self, feature: Feature) -> bool {
155        self.0.contains(&feature)
156    }
157}
158
159impl FromIterator<Feature> for FeatureSet {
160    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
161        Self(BTreeSet::from_iter(iter))
162    }
163}
164
165impl<'de> Deserialize<'de> for FeatureSet {
166    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
167    where
168        D: serde::Deserializer<'de>,
169    {
170        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
171        set.remove(&Feature::Unknown);
172        Ok(Self(set))
173    }
174}
175
176#[cfg(test)]
177mod tests {
178    use super::*;
179
180    #[test]
181    fn roundtrip() {
182        let features: FeatureSet =
183            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
184        assert_eq!(
185            &features,
186            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
187        );
188        assert_eq!(
189            serde_json::to_string(&features).unwrap(),
190            r#"["organizations:session-replay"]"#
191        );
192    }
193}