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 `organizations:relay-otlp-traces-endpoint`.
56    #[serde(rename = "organizations:relay-otlp-traces-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 logs ingestion via the Vercel Log Drain endpoint.
64    ///
65    /// Serialized as `organizations:relay-vercel-log-drain-endpoint`.
66    #[serde(rename = "organizations:relay-vercel-log-drain-endpoint")]
67    VercelLogDrainEndpoint,
68    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
69    ///
70    /// Serialized as `organizations:relay-playstation-ingestion`.
71    #[serde(rename = "organizations:relay-playstation-ingestion")]
72    PlaystationIngestion,
73    /// Discard transactions in a spans-only world.
74    ///
75    /// Serialized as `projects:discard-transaction`.
76    #[serde(rename = "projects:discard-transaction")]
77    DiscardTransaction,
78    /// Enable continuous profiling.
79    ///
80    /// Serialized as `organizations:continuous-profiling`.
81    #[serde(rename = "organizations:continuous-profiling")]
82    ContinuousProfiling,
83    /// Enabled for beta orgs
84    ///
85    /// Serialized as `organizations:continuous-profiling-beta`.
86    #[serde(rename = "organizations:continuous-profiling-beta")]
87    ContinuousProfilingBeta,
88    /// Enabled when only beta orgs are allowed to send continuous profiles.
89    ///
90    /// Serialized as `organizations:continuous-profiling-beta-ingest`.
91    #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
92    ContinuousProfilingBetaIngest,
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    /// Enable trace metric ingestion for our trace metric product.
104    ///
105    /// Serialized as `organizations:tracemetrics-ingestion`.
106    #[serde(rename = "organizations:tracemetrics-ingestion")]
107    TraceMetricsIngestion,
108    /// This feature has graduated ant is hard-coded for external Relays.
109    #[doc(hidden)]
110    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
111    IngestUnsampledProfiles,
112    /// This feature has graduated and is hard-coded for external Relays.
113    #[doc(hidden)]
114    #[serde(rename = "organizations:user-feedback-ingest")]
115    UserReportV2Ingest,
116    /// This feature has graduated and is hard-coded for external Relays.
117    #[doc(hidden)]
118    #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
119    ScrubMongoDbDescriptions,
120    #[doc(hidden)]
121    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
122    ViewHierarchyScrubbing,
123    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
124    #[serde(rename = "organizations:performance-issues-spans")]
125    PerformanceIssuesSpans,
126    /// Enables the experimental Span V2 processing pipeline in Relay.
127    #[serde(rename = "projects:span-v2-experimental-processing")]
128    SpanV2ExperimentalProcessing,
129    /// This feature has deprecated and is kept for external Relays.
130    #[doc(hidden)]
131    #[serde(rename = "projects:span-metrics-extraction")]
132    DeprecatedExtractCommonSpanMetricsFromEvent,
133    /// This feature has been deprecated and is kept for external Relays.
134    #[doc(hidden)]
135    #[serde(rename = "projects:span-metrics-extraction-addons")]
136    DeprecatedExtractAddonsSpanMetricsFromEvent,
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    /// Returns `true` if any spans are produced for this project.
159    pub fn produces_spans(&self) -> bool {
160        self.has(Feature::ExtractSpansFromEvent) || self.has(Feature::StandaloneSpanIngestion)
161    }
162}
163
164impl FromIterator<Feature> for FeatureSet {
165    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
166        Self(BTreeSet::from_iter(iter))
167    }
168}
169
170impl<'de> Deserialize<'de> for FeatureSet {
171    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
172    where
173        D: serde::Deserializer<'de>,
174    {
175        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
176        set.remove(&Feature::Unknown);
177        Ok(Self(set))
178    }
179}
180
181#[cfg(test)]
182mod tests {
183    use super::*;
184
185    #[test]
186    fn roundtrip() {
187        let features: FeatureSet =
188            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
189        assert_eq!(
190            &features,
191            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
192        );
193        assert_eq!(
194            serde_json::to_string(&features).unwrap(),
195            r#"["organizations:session-replay"]"#
196        );
197    }
198}