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    /// Expand attributes containing a JSON object into a key-value list on EAP items.
70    ///
71    /// Enabling/disabling controls how these are sent to EAP.
72    ///
73    /// Serialized as `organizations:relay-automatic-json-expansion`.
74    #[serde(rename = "organizations:relay-automatic-json-expansion")]
75    AutomaticJsonExpansion,
76    /// Project-level opt-in for JSON attribute expansion, set via project settings.
77    ///
78    /// Serialized as `projects:relay-automatic-json-expansion`.
79    #[serde(rename = "projects:relay-automatic-json-expansion")]
80    ProjectAutomaticJsonExpansion,
81    /// This feature has graduated ant is hard-coded for external Relays.
82    #[doc(hidden)]
83    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
84    IngestUnsampledProfiles,
85    /// This feature has graduated and is hard-coded for external Relays.
86    #[doc(hidden)]
87    #[serde(rename = "organizations:user-feedback-ingest")]
88    UserReportV2Ingest,
89    #[doc(hidden)]
90    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
91    ViewHierarchyScrubbing,
92    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
93    #[serde(rename = "organizations:performance-issues-spans")]
94    PerformanceIssuesSpans,
95    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
96    #[serde(rename = "projects:span-v2-attachment-processing")]
97    SpanV2AttachmentProcessing,
98    /// Enable the experimental Trace Attachment pipeline in Relay.
99    #[serde(rename = "projects:trace-attachment-processing")]
100    TraceAttachmentProcessing,
101    /// Upload non-prosperodmp playstation attachments via the upload endpoint.
102    #[serde(rename = "projects:relay-playstation-uploads")]
103    PlaystationUploads,
104    /// Enable Nintendo event rewrite.
105    #[serde(rename = "projects:relay-nintendo-event-rewrite")]
106    NintendoEventRewrite,
107    /// Stream minidumps to objectstore.
108    #[serde(rename = "projects:relay-minidump-uploads")]
109    MinidumpUploads,
110    /// Split an NVIDIA GPU crash dump (`.nv-gpudmp`) off a minidump upload into its
111    /// own event.
112    #[serde(rename = "organizations:gpu-crash-symbolication")]
113    NvGpuCrashSplit,
114    /// Enable resumable uploads to objectstore.
115    #[serde(rename = "projects:resumable-uploads")]
116    ResumableUpload,
117    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
118    ///
119    /// This is now the default behaviour of Relay.
120    #[serde(rename = "organizations:span-v2-otlp-processing")]
121    DeprecatedSpanV2OtlpProcessing,
122    /// This feature has deprecated and is kept for external Relays.
123    #[doc(hidden)]
124    #[serde(rename = "projects:span-metrics-extraction")]
125    DeprecatedExtractCommonSpanMetricsFromEvent,
126    /// This feature has been deprecated and is kept for external Relays.
127    #[doc(hidden)]
128    #[serde(rename = "projects:span-metrics-extraction-addons")]
129    DeprecatedExtractAddonsSpanMetricsFromEvent,
130    /// This feature has graduated and is hard-coded for external Relays.
131    #[doc(hidden)]
132    #[serde(rename = "organizations:indexed-spans-extraction")]
133    DeprecatedExtractSpansFromEvent,
134    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
135    ///
136    /// This feature has graduated and is hard-coded for external Relays.
137    #[doc(hidden)]
138    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
139    DeprecatedOtelTracesEndpoint,
140    /// Enable logs ingestion via the `/logs/` OTel endpoint.
141    ///
142    /// This feature has graduated and is hard-coded for external Relays.
143    #[doc(hidden)]
144    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
145    DeprecatedOtelLogsEndpoint,
146    /// Enable standalone span ingestion.
147    ///
148    /// Serialized as `organizations:standalone-span-ingestion`.
149    #[doc(hidden)]
150    #[serde(rename = "organizations:standalone-span-ingestion")]
151    DeprecatedStandaloneSpanIngestion,
152    /// Enable processing profiles.
153    ///
154    /// This feature has graduated and is hard-coded for external Relays.
155    #[doc(hidden)]
156    #[serde(rename = "organizations:profiling")]
157    DeprecatedProfiling,
158    /// Enables the experimental Span V2 processing pipeline in Relay.
159    ///
160    /// This feature has graduated.
161    #[doc(hidden)]
162    #[serde(rename = "projects:span-v2-experimental-processing")]
163    DeprecatedSpanV2ExperimentalProcessing,
164
165    /// Forward compatibility.
166    #[doc(hidden)]
167    #[serde(other)]
168    Unknown,
169}
170
171/// A set of [`Feature`]s.
172#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
173pub struct FeatureSet(pub BTreeSet<Feature>);
174
175impl FeatureSet {
176    /// Returns `true` if the set of features is empty.
177    pub fn is_empty(&self) -> bool {
178        self.0.is_empty()
179    }
180
181    /// Returns `true` if the given feature is in the set.
182    pub fn has(&self, feature: Feature) -> bool {
183        self.0.contains(&feature)
184    }
185}
186
187impl FromIterator<Feature> for FeatureSet {
188    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
189        Self(BTreeSet::from_iter(iter))
190    }
191}
192
193impl<'de> Deserialize<'de> for FeatureSet {
194    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
195    where
196        D: serde::Deserializer<'de>,
197    {
198        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
199        set.remove(&Feature::Unknown);
200        Ok(Self(set))
201    }
202}
203
204#[cfg(test)]
205mod tests {
206    use super::*;
207
208    #[test]
209    fn roundtrip() {
210        let features: FeatureSet =
211            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
212        assert_eq!(
213            &features,
214            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
215        );
216        assert_eq!(
217            serde_json::to_string(&features).unwrap(),
218            r#"["organizations:session-replay"]"#
219        );
220    }
221
222    #[test]
223    fn test_continuous_profiling_perfetto_serde() {
224        // Verify the serialized name matches what Sentry's backend sends.
225        let serialized = serde_json::to_string(&Feature::ContinuousProfilingPerfetto).unwrap();
226        assert_eq!(
227            serialized,
228            r#""organizations:continuous-profiling-perfetto""#
229        );
230
231        let deserialized: Feature =
232            serde_json::from_str(r#""organizations:continuous-profiling-perfetto""#).unwrap();
233        assert_eq!(deserialized, Feature::ContinuousProfilingPerfetto);
234    }
235}