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::DeprecatedProfiling,
11    Feature::DeprecatedOtelTracesEndpoint,
12    Feature::DeprecatedOtelLogsEndpoint,
13    Feature::DeprecatedExtractSpansFromEvent,
14    Feature::DeprecatedStandaloneSpanIngestion,
15    Feature::DeprecatedSpanV2ExperimentalProcessing,
16];
17
18/// Features exposed by project config.
19#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
20pub enum Feature {
21    /// Enables ingestion of Session Replays (Replay Recordings and Replay Events).
22    ///
23    /// Serialized as `organizations:session-replay`.
24    #[serde(rename = "organizations:session-replay")]
25    SessionReplay,
26    /// Enables data scrubbing of replay recording payloads.
27    ///
28    /// Serialized as `organizations:session-replay-recording-scrubbing`.
29    #[serde(rename = "organizations:session-replay-recording-scrubbing")]
30    SessionReplayRecordingScrubbing,
31    /// Disables select organizations from processing mobile replay events.
32    ///
33    /// Serialized as `organizations:session-replay-video-disabled`.
34    #[serde(rename = "organizations:session-replay-video-disabled")]
35    SessionReplayVideoDisabled,
36    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
37    ///
38    /// Serialized as `organizations:relay-playstation-ingestion`.
39    #[serde(rename = "organizations:relay-playstation-ingestion")]
40    PlaystationIngestion,
41    /// Discard transactions in a spans-only world.
42    ///
43    /// Serialized as `projects:discard-transaction`.
44    #[serde(rename = "projects:discard-transaction")]
45    DiscardTransaction,
46    /// Enable continuous profiling.
47    ///
48    /// Serialized as `organizations:continuous-profiling`.
49    #[serde(rename = "organizations:continuous-profiling")]
50    ContinuousProfiling,
51    /// Enable Perfetto binary trace processing for continuous profiling.
52    ///
53    /// When enabled, compound profile chunk items with `content_type: "perfetto"` are
54    /// expanded from binary Perfetto format into the Sample v2 JSON format.
55    ///
56    /// Serialized as `organizations:continuous-profiling-perfetto`.
57    #[serde(rename = "organizations:continuous-profiling-perfetto")]
58    ContinuousProfilingPerfetto,
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    /// Project-level opt-in for JSON attribute expansion, set via project settings.
70    ///
71    /// Serialized as `projects:relay-automatic-json-expansion`.
72    #[serde(rename = "projects:relay-automatic-json-expansion")]
73    ProjectAutomaticJsonExpansion,
74    /// This feature has graduated ant is hard-coded for external Relays.
75    #[doc(hidden)]
76    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
77    IngestUnsampledProfiles,
78    /// This feature has graduated and is hard-coded for external Relays.
79    #[doc(hidden)]
80    #[serde(rename = "organizations:user-feedback-ingest")]
81    UserReportV2Ingest,
82    #[doc(hidden)]
83    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
84    ViewHierarchyScrubbing,
85    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
86    #[serde(rename = "organizations:performance-issues-spans")]
87    PerformanceIssuesSpans,
88    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
89    #[serde(rename = "projects:span-v2-attachment-processing")]
90    SpanV2AttachmentProcessing,
91    /// Enable the experimental Trace Attachment pipeline in Relay.
92    #[serde(rename = "projects:trace-attachment-processing")]
93    TraceAttachmentProcessing,
94    /// Upload non-prosperodmp playstation attachments via the upload endpoint.
95    #[serde(rename = "projects:relay-playstation-uploads")]
96    PlaystationUploads,
97    /// Enable Nintendo event rewrite.
98    #[serde(rename = "projects:relay-nintendo-event-rewrite")]
99    NintendoEventRewrite,
100    /// Stream minidumps to objectstore.
101    #[serde(rename = "projects:relay-minidump-uploads")]
102    MinidumpUploads,
103    /// Split an NVIDIA GPU crash dump (`.nv-gpudmp`) off a minidump upload into its
104    /// own event.
105    #[serde(rename = "organizations:gpu-crash-symbolication")]
106    NvGpuCrashSplit,
107    /// Enable resumable uploads to objectstore.
108    #[serde(rename = "projects:resumable-uploads")]
109    ResumableUpload,
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    /// Enable processing profiles.
146    ///
147    /// This feature has graduated and is hard-coded for external Relays.
148    #[doc(hidden)]
149    #[serde(rename = "organizations:profiling")]
150    DeprecatedProfiling,
151    /// Enables the experimental Span V2 processing pipeline in Relay.
152    ///
153    /// This feature has graduated.
154    #[doc(hidden)]
155    #[serde(rename = "projects:span-v2-experimental-processing")]
156    DeprecatedSpanV2ExperimentalProcessing,
157
158    /// Forward compatibility.
159    #[doc(hidden)]
160    #[serde(other)]
161    Unknown,
162}
163
164/// A set of [`Feature`]s.
165#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
166pub struct FeatureSet(pub BTreeSet<Feature>);
167
168impl FeatureSet {
169    /// Returns `true` if the set of features is empty.
170    pub fn is_empty(&self) -> bool {
171        self.0.is_empty()
172    }
173
174    /// Returns `true` if the given feature is in the set.
175    pub fn has(&self, feature: Feature) -> bool {
176        self.0.contains(&feature)
177    }
178}
179
180impl FromIterator<Feature> for FeatureSet {
181    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
182        Self(BTreeSet::from_iter(iter))
183    }
184}
185
186impl<'de> Deserialize<'de> for FeatureSet {
187    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
188    where
189        D: serde::Deserializer<'de>,
190    {
191        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
192        set.remove(&Feature::Unknown);
193        Ok(Self(set))
194    }
195}
196
197#[cfg(test)]
198mod tests {
199    use super::*;
200
201    #[test]
202    fn roundtrip() {
203        let features: FeatureSet =
204            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
205        assert_eq!(
206            &features,
207            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
208        );
209        assert_eq!(
210            serde_json::to_string(&features).unwrap(),
211            r#"["organizations:session-replay"]"#
212        );
213    }
214
215    #[test]
216    fn test_continuous_profiling_perfetto_serde() {
217        // Verify the serialized name matches what Sentry's backend sends.
218        let serialized = serde_json::to_string(&Feature::ContinuousProfilingPerfetto).unwrap();
219        assert_eq!(
220            serialized,
221            r#""organizations:continuous-profiling-perfetto""#
222        );
223
224        let deserialized: Feature =
225            serde_json::from_str(r#""organizations:continuous-profiling-perfetto""#).unwrap();
226        assert_eq!(deserialized, Feature::ContinuousProfilingPerfetto);
227    }
228}