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 log ingestion for our log product (this is not internal logging).
60    ///
61    /// Serialized as `organizations:ourlogs-ingestion`.
62    #[serde(rename = "organizations:ourlogs-ingestion")]
63    OurLogsIngestion,
64    /// Enable trace metric ingestion for our trace metric product.
65    ///
66    /// Serialized as `organizations:tracemetrics-ingestion`.
67    #[serde(rename = "organizations:tracemetrics-ingestion")]
68    TraceMetricsIngestion,
69    /// This feature has graduated ant is hard-coded for external Relays.
70    #[doc(hidden)]
71    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
72    IngestUnsampledProfiles,
73    /// This feature has graduated and is hard-coded for external Relays.
74    #[doc(hidden)]
75    #[serde(rename = "organizations:user-feedback-ingest")]
76    UserReportV2Ingest,
77    #[doc(hidden)]
78    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
79    ViewHierarchyScrubbing,
80    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
81    #[serde(rename = "organizations:performance-issues-spans")]
82    PerformanceIssuesSpans,
83    /// Enables the experimental Span V2 processing pipeline in Relay.
84    #[serde(rename = "projects:span-v2-experimental-processing")]
85    SpanV2ExperimentalProcessing,
86    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
87    #[serde(rename = "projects:span-v2-attachment-processing")]
88    SpanV2AttachmentProcessing,
89    /// Enable the experimental Trace Attachment pipeline in Relay.
90    #[serde(rename = "projects:trace-attachment-processing")]
91    TraceAttachmentProcessing,
92    /// Enable the upload endpoint for attachments.
93    #[serde(rename = "projects:relay-upload-endpoint")]
94    UploadEndpoint,
95    /// Upload non-prosperodmp playstation attachments via the upload endpoint.
96    #[serde(rename = "projects:relay-playstation-uploads")]
97    PlaystationUploads,
98    /// Add a random trace ID to events that lack one.
99    #[serde(rename = "organizations:relay-default-trace-id")]
100    AddDefaultTraceID,
101    /// Enable experimental expansion of the unreal report in the endpoint rather than in the
102    /// processor. Only enable for organizations with sufficient attachment quota.
103    #[serde(rename = "organizations:relay-unreal-endpoint-expansion")]
104    UnrealEndpointExpansion,
105    /// Stream minidump attachments to objectstore.
106    #[serde(rename = "projects:relay-minidump-attachment-uploads")]
107    MinidumpAttachmentUploads,
108    /// Stream minidumps to objectstore.
109    #[serde(rename = "projects:relay-minidump-uploads")]
110    MinidumpUploads,
111    /// When converting measurements into attributes, use the name from the measurement
112    /// definition.
113    #[serde(rename = "projects:relay-measurements-smart-conversion")]
114    MeasurementsSmartConversion,
115
116    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
117    ///
118    /// This is now the default behaviour of Relay.
119    #[serde(rename = "organizations:span-v2-otlp-processing")]
120    DeprecatedSpanV2OtlpProcessing,
121    /// This feature has deprecated and is kept for external Relays.
122    #[doc(hidden)]
123    #[serde(rename = "projects:span-metrics-extraction")]
124    DeprecatedExtractCommonSpanMetricsFromEvent,
125    /// This feature has been deprecated and is kept for external Relays.
126    #[doc(hidden)]
127    #[serde(rename = "projects:span-metrics-extraction-addons")]
128    DeprecatedExtractAddonsSpanMetricsFromEvent,
129    /// This feature has graduated and is hard-coded for external Relays.
130    #[doc(hidden)]
131    #[serde(rename = "organizations:indexed-spans-extraction")]
132    DeprecatedExtractSpansFromEvent,
133    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
134    ///
135    /// This feature has graduated and is hard-coded for external Relays.
136    #[doc(hidden)]
137    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
138    DeprecatedOtelTracesEndpoint,
139    /// Enable logs ingestion via the `/logs/` OTel endpoint.
140    ///
141    /// This feature has graduated and is hard-coded for external Relays.
142    #[doc(hidden)]
143    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
144    DeprecatedOtelLogsEndpoint,
145    /// Enable standalone span ingestion.
146    ///
147    /// Serialized as `organizations:standalone-span-ingestion`.
148    #[doc(hidden)]
149    #[serde(rename = "organizations:standalone-span-ingestion")]
150    DeprecatedStandaloneSpanIngestion,
151
152    /// Forward compatibility.
153    #[doc(hidden)]
154    #[serde(other)]
155    Unknown,
156}
157
158/// A set of [`Feature`]s.
159#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
160pub struct FeatureSet(pub BTreeSet<Feature>);
161
162impl FeatureSet {
163    /// Returns `true` if the set of features is empty.
164    pub fn is_empty(&self) -> bool {
165        self.0.is_empty()
166    }
167
168    /// Returns `true` if the given feature is in the set.
169    pub fn has(&self, feature: Feature) -> bool {
170        self.0.contains(&feature)
171    }
172}
173
174impl FromIterator<Feature> for FeatureSet {
175    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
176        Self(BTreeSet::from_iter(iter))
177    }
178}
179
180impl<'de> Deserialize<'de> for FeatureSet {
181    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
182    where
183        D: serde::Deserializer<'de>,
184    {
185        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
186        set.remove(&Feature::Unknown);
187        Ok(Self(set))
188    }
189}
190
191#[cfg(test)]
192mod tests {
193    use super::*;
194
195    #[test]
196    fn roundtrip() {
197        let features: FeatureSet =
198            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
199        assert_eq!(
200            &features,
201            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
202        );
203        assert_eq!(
204            serde_json::to_string(&features).unwrap(),
205            r#"["organizations:session-replay"]"#
206        );
207    }
208}