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    /// Add a stack trace from the Unreal crash context to crashes without a minidump.
111    #[serde(rename = "projects:relay-unreal-crash-context-stacktrace")]
112    UnrealCrashContextStacktrace,
113    /// Stream minidumps to objectstore.
114    #[serde(rename = "projects:relay-minidump-uploads")]
115    MinidumpUploads,
116    /// Split an NVIDIA GPU crash dump (`.nv-gpudmp`) off a minidump upload into its
117    /// own event.
118    #[serde(rename = "organizations:gpu-crash-symbolication")]
119    NvGpuCrashSplit,
120    /// Enable resumable uploads to objectstore.
121    #[serde(rename = "projects:resumable-uploads")]
122    ResumableUpload,
123    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
124    ///
125    /// This is now the default behaviour of Relay.
126    #[serde(rename = "organizations:span-v2-otlp-processing")]
127    DeprecatedSpanV2OtlpProcessing,
128    /// This feature has deprecated and is kept for external Relays.
129    #[doc(hidden)]
130    #[serde(rename = "projects:span-metrics-extraction")]
131    DeprecatedExtractCommonSpanMetricsFromEvent,
132    /// This feature has been deprecated and is kept for external Relays.
133    #[doc(hidden)]
134    #[serde(rename = "projects:span-metrics-extraction-addons")]
135    DeprecatedExtractAddonsSpanMetricsFromEvent,
136    /// This feature has graduated and is hard-coded for external Relays.
137    #[doc(hidden)]
138    #[serde(rename = "organizations:indexed-spans-extraction")]
139    DeprecatedExtractSpansFromEvent,
140    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
141    ///
142    /// This feature has graduated and is hard-coded for external Relays.
143    #[doc(hidden)]
144    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
145    DeprecatedOtelTracesEndpoint,
146    /// Enable logs ingestion via the `/logs/` OTel endpoint.
147    ///
148    /// This feature has graduated and is hard-coded for external Relays.
149    #[doc(hidden)]
150    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
151    DeprecatedOtelLogsEndpoint,
152    /// Enable standalone span ingestion.
153    ///
154    /// Serialized as `organizations:standalone-span-ingestion`.
155    #[doc(hidden)]
156    #[serde(rename = "organizations:standalone-span-ingestion")]
157    DeprecatedStandaloneSpanIngestion,
158    /// Enable processing profiles.
159    ///
160    /// This feature has graduated and is hard-coded for external Relays.
161    #[doc(hidden)]
162    #[serde(rename = "organizations:profiling")]
163    DeprecatedProfiling,
164    /// Enables the experimental Span V2 processing pipeline in Relay.
165    ///
166    /// This feature has graduated.
167    #[doc(hidden)]
168    #[serde(rename = "projects:span-v2-experimental-processing")]
169    DeprecatedSpanV2ExperimentalProcessing,
170
171    /// Forward compatibility.
172    #[doc(hidden)]
173    #[serde(other)]
174    Unknown,
175}
176
177/// A set of [`Feature`]s.
178#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
179pub struct FeatureSet(pub BTreeSet<Feature>);
180
181impl FeatureSet {
182    /// Returns `true` if the set of features is empty.
183    pub fn is_empty(&self) -> bool {
184        self.0.is_empty()
185    }
186
187    /// Returns `true` if the given feature is in the set.
188    pub fn has(&self, feature: Feature) -> bool {
189        self.0.contains(&feature)
190    }
191}
192
193impl FromIterator<Feature> for FeatureSet {
194    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
195        Self(BTreeSet::from_iter(iter))
196    }
197}
198
199impl<'de> Deserialize<'de> for FeatureSet {
200    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
201    where
202        D: serde::Deserializer<'de>,
203    {
204        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
205        set.remove(&Feature::Unknown);
206        Ok(Self(set))
207    }
208}
209
210#[cfg(test)]
211mod tests {
212    use super::*;
213
214    #[test]
215    fn roundtrip() {
216        let features: FeatureSet =
217            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
218        assert_eq!(
219            &features,
220            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
221        );
222        assert_eq!(
223            serde_json::to_string(&features).unwrap(),
224            r#"["organizations:session-replay"]"#
225        );
226    }
227
228    #[test]
229    fn test_continuous_profiling_perfetto_serde() {
230        // Verify the serialized name matches what Sentry's backend sends.
231        let serialized = serde_json::to_string(&Feature::ContinuousProfilingPerfetto).unwrap();
232        assert_eq!(
233            serialized,
234            r#""organizations:continuous-profiling-perfetto""#
235        );
236
237        let deserialized: Feature =
238            serde_json::from_str(r#""organizations:continuous-profiling-perfetto""#).unwrap();
239        assert_eq!(deserialized, Feature::ContinuousProfilingPerfetto);
240    }
241}