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