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 playstation crash dump ingestion via the `/playstation/` endpoint.
65    ///
66    /// Serialized as `organizations:relay-playstation-ingestion`.
67    #[serde(rename = "organizations: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    /// Enable log ingestion for our log product (this is not internal logging).
90    ///
91    /// Serialized as `organizations:ourlogs-ingestion`.
92    #[serde(rename = "organizations:ourlogs-ingestion")]
93    OurLogsIngestion,
94    /// Enable trace metric ingestion for our trace metric product.
95    ///
96    /// Serialized as `organizations:tracemetrics-ingestion`.
97    #[serde(rename = "organizations:tracemetrics-ingestion")]
98    TraceMetricsIngestion,
99    /// This feature has graduated ant is hard-coded for external Relays.
100    #[doc(hidden)]
101    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
102    IngestUnsampledProfiles,
103    /// This feature has graduated and is hard-coded for external Relays.
104    #[doc(hidden)]
105    #[serde(rename = "organizations:user-feedback-ingest")]
106    UserReportV2Ingest,
107    /// This feature has graduated and is hard-coded for external Relays.
108    #[doc(hidden)]
109    #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
110    ScrubMongoDbDescriptions,
111    #[doc(hidden)]
112    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
113    ViewHierarchyScrubbing,
114    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
115    #[serde(rename = "organizations:performance-issues-spans")]
116    PerformanceIssuesSpans,
117    /// Enables the experimental Span V2 processing pipeline in Relay.
118    #[serde(rename = "projects:span-v2-experimental-processing")]
119    SpanV2ExperimentalProcessing,
120    /// This feature has deprecated and is kept for external Relays.
121    #[doc(hidden)]
122    #[serde(rename = "projects:span-metrics-extraction")]
123    DeprecatedExtractCommonSpanMetricsFromEvent,
124    /// This feature has been deprecated and is kept for external Relays.
125    #[doc(hidden)]
126    #[serde(rename = "projects:span-metrics-extraction-addons")]
127    DeprecatedExtractAddonsSpanMetricsFromEvent,
128    /// This feature has graduated and is hard-coded for external Relays.
129    #[doc(hidden)]
130    #[serde(rename = "organizations:indexed-spans-extraction")]
131    DeprecatedExtractSpansFromEvent,
132    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
133    #[serde(rename = "projects:span-v2-attachment-processing")]
134    SpanV2AttachmentProcessing,
135    /// Forward compatibility.
136    #[doc(hidden)]
137    #[serde(other)]
138    Unknown,
139}
140
141/// A set of [`Feature`]s.
142#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
143pub struct FeatureSet(pub BTreeSet<Feature>);
144
145impl FeatureSet {
146    /// Returns `true` if the set of features is empty.
147    pub fn is_empty(&self) -> bool {
148        self.0.is_empty()
149    }
150
151    /// Returns `true` if the given feature is in the set.
152    pub fn has(&self, feature: Feature) -> bool {
153        self.0.contains(&feature)
154    }
155}
156
157impl FromIterator<Feature> for FeatureSet {
158    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
159        Self(BTreeSet::from_iter(iter))
160    }
161}
162
163impl<'de> Deserialize<'de> for FeatureSet {
164    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
165    where
166        D: serde::Deserializer<'de>,
167    {
168        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
169        set.remove(&Feature::Unknown);
170        Ok(Self(set))
171    }
172}
173
174#[cfg(test)]
175mod tests {
176    use super::*;
177
178    #[test]
179    fn roundtrip() {
180        let features: FeatureSet =
181            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
182        assert_eq!(
183            &features,
184            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
185        );
186        assert_eq!(
187            serde_json::to_string(&features).unwrap(),
188            r#"["organizations:session-replay"]"#
189        );
190    }
191}