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