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    /// Upload non-prosperodmp playstation attachments via the upload endpoint.
101    #[serde(rename = "projects:relay-playstation-uploads")]
102    PlaystationUploads,
103    /// Enable experimental expansion of the unreal report in the endpoint rather than in the
104    /// processor. Only enable for organizations with sufficient attachment quota.
105    #[serde(rename = "organizations:relay-unreal-endpoint-expansion")]
106    UnrealEndpointExpansion,
107    /// Stream minidump attachments to objectstore.
108    #[serde(rename = "projects:relay-minidump-attachment-uploads")]
109    MinidumpAttachmentUploads,
110    /// Stream minidumps to objectstore.
111    #[serde(rename = "projects:relay-minidump-uploads")]
112    MinidumpUploads,
113    /// Allow additional exceptions to accompany minidumps.
114    #[serde(rename = "projects:minidump-multi-exception")]
115    MinidumpMultiException,
116    /// Enable relay billing outcome generation.
117    #[serde(rename = "organizations:relay-generate-billing-outcome")]
118    GenerateBillingOutcome,
119
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
156    /// Forward compatibility.
157    #[doc(hidden)]
158    #[serde(other)]
159    Unknown,
160}
161
162/// A set of [`Feature`]s.
163#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
164pub struct FeatureSet(pub BTreeSet<Feature>);
165
166impl FeatureSet {
167    /// Returns `true` if the set of features is empty.
168    pub fn is_empty(&self) -> bool {
169        self.0.is_empty()
170    }
171
172    /// Returns `true` if the given feature is in the set.
173    pub fn has(&self, feature: Feature) -> bool {
174        self.0.contains(&feature)
175    }
176}
177
178impl FromIterator<Feature> for FeatureSet {
179    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
180        Self(BTreeSet::from_iter(iter))
181    }
182}
183
184impl<'de> Deserialize<'de> for FeatureSet {
185    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
186    where
187        D: serde::Deserializer<'de>,
188    {
189        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
190        set.remove(&Feature::Unknown);
191        Ok(Self(set))
192    }
193}
194
195#[cfg(test)]
196mod tests {
197    use super::*;
198
199    #[test]
200    fn roundtrip() {
201        let features: FeatureSet =
202            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
203        assert_eq!(
204            &features,
205            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
206        );
207        assert_eq!(
208            serde_json::to_string(&features).unwrap(),
209            r#"["organizations:session-replay"]"#
210        );
211    }
212
213    #[test]
214    fn test_continuous_profiling_perfetto_serde() {
215        // Verify the serialized name matches what Sentry's backend sends.
216        let serialized = serde_json::to_string(&Feature::ContinuousProfilingPerfetto).unwrap();
217        assert_eq!(
218            serialized,
219            r#""organizations:continuous-profiling-perfetto""#
220        );
221
222        let deserialized: Feature =
223            serde_json::from_str(r#""organizations:continuous-profiling-perfetto""#).unwrap();
224        assert_eq!(deserialized, Feature::ContinuousProfilingPerfetto);
225    }
226}