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    /// Allow ingestion of metrics in the "custom" namespace.
35    ///
36    /// Serialized as `organizations:custom-metrics`.
37    #[serde(rename = "organizations:custom-metrics")]
38    CustomMetrics,
39    /// Enable processing profiles.
40    ///
41    /// Serialized as `organizations:profiling`.
42    #[serde(rename = "organizations:profiling")]
43    Profiling,
44    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
45    ///
46    /// Serialized as `organizations:relay-playstation-ingestion`.
47    #[serde(rename = "organizations:relay-playstation-ingestion")]
48    PlaystationIngestion,
49    /// Discard transactions in a spans-only world.
50    ///
51    /// Serialized as `projects:discard-transaction`.
52    #[serde(rename = "projects:discard-transaction")]
53    DiscardTransaction,
54    /// Enable continuous profiling.
55    ///
56    /// Serialized as `organizations:continuous-profiling`.
57    #[serde(rename = "organizations:continuous-profiling")]
58    ContinuousProfiling,
59    /// Enable Perfetto binary trace processing for continuous profiling.
60    ///
61    /// When enabled, compound profile chunk items with `content_type: "perfetto"` are
62    /// expanded from binary Perfetto format into the Sample v2 JSON format.
63    ///
64    /// Serialized as `organizations:continuous-profiling-perfetto`.
65    #[serde(rename = "organizations:continuous-profiling-perfetto")]
66    ContinuousProfilingPerfetto,
67    /// Enable log ingestion for our log product (this is not internal logging).
68    ///
69    /// Serialized as `organizations:ourlogs-ingestion`.
70    #[serde(rename = "organizations:ourlogs-ingestion")]
71    OurLogsIngestion,
72    /// Enable trace metric ingestion for our trace metric product.
73    ///
74    /// Serialized as `organizations:tracemetrics-ingestion`.
75    #[serde(rename = "organizations:tracemetrics-ingestion")]
76    TraceMetricsIngestion,
77    /// This feature has graduated ant is hard-coded for external Relays.
78    #[doc(hidden)]
79    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
80    IngestUnsampledProfiles,
81    /// This feature has graduated and is hard-coded for external Relays.
82    #[doc(hidden)]
83    #[serde(rename = "organizations:user-feedback-ingest")]
84    UserReportV2Ingest,
85    #[doc(hidden)]
86    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
87    ViewHierarchyScrubbing,
88    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
89    #[serde(rename = "organizations:performance-issues-spans")]
90    PerformanceIssuesSpans,
91    /// Enables the experimental Span V2 processing pipeline in Relay.
92    #[serde(rename = "projects:span-v2-experimental-processing")]
93    SpanV2ExperimentalProcessing,
94    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
95    #[serde(rename = "projects:span-v2-attachment-processing")]
96    SpanV2AttachmentProcessing,
97    /// Enable the experimental Trace Attachment pipeline in Relay.
98    #[serde(rename = "projects:trace-attachment-processing")]
99    TraceAttachmentProcessing,
100    /// Enable the upload endpoint for attachments.
101    #[serde(rename = "projects:relay-upload-endpoint")]
102    UploadEndpoint,
103    /// Upload non-prosperodmp playstation attachments via the upload endpoint.
104    #[serde(rename = "projects:relay-playstation-uploads")]
105    PlaystationUploads,
106    /// Enable experimental expansion of the unreal report in the endpoint rather than in the
107    /// processor. Only enable for organizations with sufficient attachment quota.
108    #[serde(rename = "organizations:relay-unreal-endpoint-expansion")]
109    UnrealEndpointExpansion,
110    /// Stream minidump attachments to objectstore.
111    #[serde(rename = "projects:relay-minidump-attachment-uploads")]
112    MinidumpAttachmentUploads,
113    /// Stream minidumps to objectstore.
114    #[serde(rename = "projects:relay-minidump-uploads")]
115    MinidumpUploads,
116    /// Allow additional exceptions to accompany minidumps.
117    #[serde(rename = "projects:minidump-multi-exception")]
118    MinidumpMultiException,
119    /// Enable relay billing outcome generation.
120    #[serde(rename = "organizations:relay-generate-billing-outcome")]
121    GenerateBillingOutcome,
122
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
159    /// Forward compatibility.
160    #[doc(hidden)]
161    #[serde(other)]
162    Unknown,
163}
164
165/// A set of [`Feature`]s.
166#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
167pub struct FeatureSet(pub BTreeSet<Feature>);
168
169impl FeatureSet {
170    /// Returns `true` if the set of features is empty.
171    pub fn is_empty(&self) -> bool {
172        self.0.is_empty()
173    }
174
175    /// Returns `true` if the given feature is in the set.
176    pub fn has(&self, feature: Feature) -> bool {
177        self.0.contains(&feature)
178    }
179}
180
181impl FromIterator<Feature> for FeatureSet {
182    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
183        Self(BTreeSet::from_iter(iter))
184    }
185}
186
187impl<'de> Deserialize<'de> for FeatureSet {
188    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
189    where
190        D: serde::Deserializer<'de>,
191    {
192        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
193        set.remove(&Feature::Unknown);
194        Ok(Self(set))
195    }
196}
197
198#[cfg(test)]
199mod tests {
200    use super::*;
201
202    #[test]
203    fn roundtrip() {
204        let features: FeatureSet =
205            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
206        assert_eq!(
207            &features,
208            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
209        );
210        assert_eq!(
211            serde_json::to_string(&features).unwrap(),
212            r#"["organizations:session-replay"]"#
213        );
214    }
215
216    #[test]
217    fn test_continuous_profiling_perfetto_serde() {
218        // Verify the serialized name matches what Sentry's backend sends.
219        let serialized = serde_json::to_string(&Feature::ContinuousProfilingPerfetto).unwrap();
220        assert_eq!(
221            serialized,
222            r#""organizations:continuous-profiling-perfetto""#
223        );
224
225        let deserialized: Feature =
226            serde_json::from_str(r#""organizations:continuous-profiling-perfetto""#).unwrap();
227        assert_eq!(deserialized, Feature::ContinuousProfilingPerfetto);
228    }
229}