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