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::DeprecatedOtelTracesEndpoint,
11    Feature::DeprecatedOtelLogsEndpoint,
12    Feature::DeprecatedExtractSpansFromEvent,
13    Feature::DeprecatedStandaloneSpanIngestion,
14];
15
16/// Features exposed by project config.
17#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
18pub enum Feature {
19    /// Enables ingestion of Session Replays (Replay Recordings and Replay Events).
20    ///
21    /// Serialized as `organizations:session-replay`.
22    #[serde(rename = "organizations:session-replay")]
23    SessionReplay,
24    /// Enables data scrubbing of replay recording payloads.
25    ///
26    /// Serialized as `organizations:session-replay-recording-scrubbing`.
27    #[serde(rename = "organizations:session-replay-recording-scrubbing")]
28    SessionReplayRecordingScrubbing,
29    /// Disables select organizations from processing mobile replay events.
30    ///
31    /// Serialized as `organizations:session-replay-video-disabled`.
32    #[serde(rename = "organizations:session-replay-video-disabled")]
33    SessionReplayVideoDisabled,
34    /// Enable processing profiles.
35    ///
36    /// Serialized as `organizations:profiling`.
37    #[serde(rename = "organizations:profiling")]
38    Profiling,
39    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
40    ///
41    /// Serialized as `organizations:relay-playstation-ingestion`.
42    #[serde(rename = "organizations:relay-playstation-ingestion")]
43    PlaystationIngestion,
44    /// Discard transactions in a spans-only world.
45    ///
46    /// Serialized as `projects:discard-transaction`.
47    #[serde(rename = "projects:discard-transaction")]
48    DiscardTransaction,
49    /// Enable continuous profiling.
50    ///
51    /// Serialized as `organizations:continuous-profiling`.
52    #[serde(rename = "organizations:continuous-profiling")]
53    ContinuousProfiling,
54    /// Enable Perfetto binary trace processing for continuous profiling.
55    ///
56    /// When enabled, compound profile chunk items with `content_type: "perfetto"` are
57    /// expanded from binary Perfetto format into the Sample v2 JSON format.
58    ///
59    /// Serialized as `organizations:continuous-profiling-perfetto`.
60    #[serde(rename = "organizations:continuous-profiling-perfetto")]
61    ContinuousProfilingPerfetto,
62    /// Enable log ingestion for our log product (this is not internal logging).
63    ///
64    /// Serialized as `organizations:ourlogs-ingestion`.
65    #[serde(rename = "organizations:ourlogs-ingestion")]
66    OurLogsIngestion,
67    /// Enable trace metric ingestion for our trace metric product.
68    ///
69    /// Serialized as `organizations:tracemetrics-ingestion`.
70    #[serde(rename = "organizations:tracemetrics-ingestion")]
71    TraceMetricsIngestion,
72    /// This feature has graduated ant is hard-coded for external Relays.
73    #[doc(hidden)]
74    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
75    IngestUnsampledProfiles,
76    /// This feature has graduated and is hard-coded for external Relays.
77    #[doc(hidden)]
78    #[serde(rename = "organizations:user-feedback-ingest")]
79    UserReportV2Ingest,
80    #[doc(hidden)]
81    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
82    ViewHierarchyScrubbing,
83    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
84    #[serde(rename = "organizations:performance-issues-spans")]
85    PerformanceIssuesSpans,
86    /// Enables the experimental Span V2 processing pipeline in Relay.
87    #[serde(rename = "projects:span-v2-experimental-processing")]
88    SpanV2ExperimentalProcessing,
89    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
90    #[serde(rename = "projects:span-v2-attachment-processing")]
91    SpanV2AttachmentProcessing,
92    /// Enable the experimental Trace Attachment pipeline in Relay.
93    #[serde(rename = "projects:trace-attachment-processing")]
94    TraceAttachmentProcessing,
95    /// Upload non-prosperodmp playstation attachments via the upload endpoint.
96    #[serde(rename = "projects:relay-playstation-uploads")]
97    PlaystationUploads,
98    /// Enable experimental expansion of the unreal report in the endpoint rather than in the
99    /// processor. Only enable for organizations with sufficient attachment quota.
100    #[serde(rename = "organizations:relay-unreal-endpoint-expansion")]
101    UnrealEndpointExpansion,
102    /// Stream minidump attachments to objectstore.
103    #[serde(rename = "projects:relay-minidump-attachment-uploads")]
104    MinidumpAttachmentUploads,
105    /// Stream minidumps to objectstore.
106    #[serde(rename = "projects:relay-minidump-uploads")]
107    MinidumpUploads,
108    /// Allow additional exceptions to accompany minidumps.
109    #[serde(rename = "projects:minidump-multi-exception")]
110    MinidumpMultiException,
111    /// Enable relay billing outcome generation.
112    #[serde(rename = "organizations:relay-generate-billing-outcome")]
113    GenerateBillingOutcome,
114
115    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
116    ///
117    /// This is now the default behaviour of Relay.
118    #[serde(rename = "organizations:span-v2-otlp-processing")]
119    DeprecatedSpanV2OtlpProcessing,
120    /// This feature has deprecated and is kept for external Relays.
121    #[doc(hidden)]
122    #[serde(rename = "projects:span-metrics-extraction")]
123    DeprecatedExtractCommonSpanMetricsFromEvent,
124    /// This feature has been deprecated and is kept for external Relays.
125    #[doc(hidden)]
126    #[serde(rename = "projects:span-metrics-extraction-addons")]
127    DeprecatedExtractAddonsSpanMetricsFromEvent,
128    /// This feature has graduated and is hard-coded for external Relays.
129    #[doc(hidden)]
130    #[serde(rename = "organizations:indexed-spans-extraction")]
131    DeprecatedExtractSpansFromEvent,
132    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
133    ///
134    /// This feature has graduated and is hard-coded for external Relays.
135    #[doc(hidden)]
136    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
137    DeprecatedOtelTracesEndpoint,
138    /// Enable logs ingestion via the `/logs/` OTel endpoint.
139    ///
140    /// This feature has graduated and is hard-coded for external Relays.
141    #[doc(hidden)]
142    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
143    DeprecatedOtelLogsEndpoint,
144    /// Enable standalone span ingestion.
145    ///
146    /// Serialized as `organizations:standalone-span-ingestion`.
147    #[doc(hidden)]
148    #[serde(rename = "organizations:standalone-span-ingestion")]
149    DeprecatedStandaloneSpanIngestion,
150
151    /// Forward compatibility.
152    #[doc(hidden)]
153    #[serde(other)]
154    Unknown,
155}
156
157/// A set of [`Feature`]s.
158#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
159pub struct FeatureSet(pub BTreeSet<Feature>);
160
161impl FeatureSet {
162    /// Returns `true` if the set of features is empty.
163    pub fn is_empty(&self) -> bool {
164        self.0.is_empty()
165    }
166
167    /// Returns `true` if the given feature is in the set.
168    pub fn has(&self, feature: Feature) -> bool {
169        self.0.contains(&feature)
170    }
171}
172
173impl FromIterator<Feature> for FeatureSet {
174    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
175        Self(BTreeSet::from_iter(iter))
176    }
177}
178
179impl<'de> Deserialize<'de> for FeatureSet {
180    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
181    where
182        D: serde::Deserializer<'de>,
183    {
184        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
185        set.remove(&Feature::Unknown);
186        Ok(Self(set))
187    }
188}
189
190#[cfg(test)]
191mod tests {
192    use super::*;
193
194    #[test]
195    fn roundtrip() {
196        let features: FeatureSet =
197            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
198        assert_eq!(
199            &features,
200            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
201        );
202        assert_eq!(
203            serde_json::to_string(&features).unwrap(),
204            r#"["organizations:session-replay"]"#
205        );
206    }
207
208    #[test]
209    fn test_continuous_profiling_perfetto_serde() {
210        // Verify the serialized name matches what Sentry's backend sends.
211        let serialized = serde_json::to_string(&Feature::ContinuousProfilingPerfetto).unwrap();
212        assert_eq!(
213            serialized,
214            r#""organizations:continuous-profiling-perfetto""#
215        );
216
217        let deserialized: Feature =
218            serde_json::from_str(r#""organizations:continuous-profiling-perfetto""#).unwrap();
219        assert_eq!(deserialized, Feature::ContinuousProfilingPerfetto);
220    }
221}