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    /// Enable processing profiles.
35    ///
36    /// Serialized as `organizations:profiling`.
37    #[serde(rename = "organizations:profiling")]
38    Profiling,
39    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
40    ///
41    /// Serialized as `organizations:relay-playstation-ingestion`.
42    #[serde(rename = "organizations:relay-playstation-ingestion")]
43    PlaystationIngestion,
44    /// Discard transactions in a spans-only world.
45    ///
46    /// Serialized as `projects:discard-transaction`.
47    #[serde(rename = "projects:discard-transaction")]
48    DiscardTransaction,
49    /// Enable continuous profiling.
50    ///
51    /// Serialized as `organizations:continuous-profiling`.
52    #[serde(rename = "organizations:continuous-profiling")]
53    ContinuousProfiling,
54    /// Enable Perfetto binary trace processing for continuous profiling.
55    ///
56    /// When enabled, compound profile chunk items with `content_type: "perfetto"` are
57    /// expanded from binary Perfetto format into the Sample v2 JSON format.
58    ///
59    /// Serialized as `organizations:continuous-profiling-perfetto`.
60    #[serde(rename = "organizations:continuous-profiling-perfetto")]
61    ContinuousProfilingPerfetto,
62    /// Enable log ingestion for our log product (this is not internal logging).
63    ///
64    /// Serialized as `organizations:ourlogs-ingestion`.
65    #[serde(rename = "organizations:ourlogs-ingestion")]
66    OurLogsIngestion,
67    /// Enable trace metric ingestion for our trace metric product.
68    ///
69    /// Serialized as `organizations:tracemetrics-ingestion`.
70    #[serde(rename = "organizations:tracemetrics-ingestion")]
71    TraceMetricsIngestion,
72    /// This feature has graduated ant is hard-coded for external Relays.
73    #[doc(hidden)]
74    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
75    IngestUnsampledProfiles,
76    /// This feature has graduated and is hard-coded for external Relays.
77    #[doc(hidden)]
78    #[serde(rename = "organizations:user-feedback-ingest")]
79    UserReportV2Ingest,
80    #[doc(hidden)]
81    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
82    ViewHierarchyScrubbing,
83    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
84    #[serde(rename = "organizations:performance-issues-spans")]
85    PerformanceIssuesSpans,
86    /// Enables the experimental Span V2 processing pipeline in Relay.
87    #[serde(rename = "projects:span-v2-experimental-processing")]
88    SpanV2ExperimentalProcessing,
89    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
90    #[serde(rename = "projects:span-v2-attachment-processing")]
91    SpanV2AttachmentProcessing,
92    /// Enable the experimental Trace Attachment pipeline in Relay.
93    #[serde(rename = "projects:trace-attachment-processing")]
94    TraceAttachmentProcessing,
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 minidumps to objectstore.
103    #[serde(rename = "projects:relay-minidump-uploads")]
104    MinidumpUploads,
105    /// Use objectstore multipart for upload requests.
106    ///
107    /// See <https://getsentry.github.io/objectstore/rust/objectstore_service/multipart/>.
108    #[serde(rename = "projects:relay-upload-multipart")]
109    UploadMultipart,
110    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
111    ///
112    /// This is now the default behaviour of Relay.
113    #[serde(rename = "organizations:span-v2-otlp-processing")]
114    DeprecatedSpanV2OtlpProcessing,
115    /// This feature has deprecated and is kept for external Relays.
116    #[doc(hidden)]
117    #[serde(rename = "projects:span-metrics-extraction")]
118    DeprecatedExtractCommonSpanMetricsFromEvent,
119    /// This feature has been deprecated and is kept for external Relays.
120    #[doc(hidden)]
121    #[serde(rename = "projects:span-metrics-extraction-addons")]
122    DeprecatedExtractAddonsSpanMetricsFromEvent,
123    /// This feature has graduated and is hard-coded for external Relays.
124    #[doc(hidden)]
125    #[serde(rename = "organizations:indexed-spans-extraction")]
126    DeprecatedExtractSpansFromEvent,
127    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
128    ///
129    /// This feature has graduated and is hard-coded for external Relays.
130    #[doc(hidden)]
131    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
132    DeprecatedOtelTracesEndpoint,
133    /// Enable logs ingestion via the `/logs/` OTel endpoint.
134    ///
135    /// This feature has graduated and is hard-coded for external Relays.
136    #[doc(hidden)]
137    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
138    DeprecatedOtelLogsEndpoint,
139    /// Enable standalone span ingestion.
140    ///
141    /// Serialized as `organizations:standalone-span-ingestion`.
142    #[doc(hidden)]
143    #[serde(rename = "organizations:standalone-span-ingestion")]
144    DeprecatedStandaloneSpanIngestion,
145
146    /// Forward compatibility.
147    #[doc(hidden)]
148    #[serde(other)]
149    Unknown,
150}
151
152/// A set of [`Feature`]s.
153#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
154pub struct FeatureSet(pub BTreeSet<Feature>);
155
156impl FeatureSet {
157    /// Returns `true` if the set of features is empty.
158    pub fn is_empty(&self) -> bool {
159        self.0.is_empty()
160    }
161
162    /// Returns `true` if the given feature is in the set.
163    pub fn has(&self, feature: Feature) -> bool {
164        self.0.contains(&feature)
165    }
166}
167
168impl FromIterator<Feature> for FeatureSet {
169    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
170        Self(BTreeSet::from_iter(iter))
171    }
172}
173
174impl<'de> Deserialize<'de> for FeatureSet {
175    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
176    where
177        D: serde::Deserializer<'de>,
178    {
179        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
180        set.remove(&Feature::Unknown);
181        Ok(Self(set))
182    }
183}
184
185#[cfg(test)]
186mod tests {
187    use super::*;
188
189    #[test]
190    fn roundtrip() {
191        let features: FeatureSet =
192            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
193        assert_eq!(
194            &features,
195            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
196        );
197        assert_eq!(
198            serde_json::to_string(&features).unwrap(),
199            r#"["organizations:session-replay"]"#
200        );
201    }
202
203    #[test]
204    fn test_continuous_profiling_perfetto_serde() {
205        // Verify the serialized name matches what Sentry's backend sends.
206        let serialized = serde_json::to_string(&Feature::ContinuousProfilingPerfetto).unwrap();
207        assert_eq!(
208            serialized,
209            r#""organizations:continuous-profiling-perfetto""#
210        );
211
212        let deserialized: Feature =
213            serde_json::from_str(r#""organizations:continuous-profiling-perfetto""#).unwrap();
214        assert_eq!(deserialized, Feature::ContinuousProfilingPerfetto);
215    }
216}