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