Skip to main content

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