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
112    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
113    ///
114    /// This is now the default behaviour of Relay.
115    #[serde(rename = "organizations:span-v2-otlp-processing")]
116    DeprecatedSpanV2OtlpProcessing,
117    /// This feature has deprecated and is kept for external Relays.
118    #[doc(hidden)]
119    #[serde(rename = "projects:span-metrics-extraction")]
120    DeprecatedExtractCommonSpanMetricsFromEvent,
121    /// This feature has been deprecated and is kept for external Relays.
122    #[doc(hidden)]
123    #[serde(rename = "projects:span-metrics-extraction-addons")]
124    DeprecatedExtractAddonsSpanMetricsFromEvent,
125    /// This feature has graduated and is hard-coded for external Relays.
126    #[doc(hidden)]
127    #[serde(rename = "organizations:indexed-spans-extraction")]
128    DeprecatedExtractSpansFromEvent,
129    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
130    ///
131    /// This feature has graduated and is hard-coded for external Relays.
132    #[doc(hidden)]
133    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
134    DeprecatedOtelTracesEndpoint,
135    /// Enable logs ingestion via the `/logs/` OTel endpoint.
136    ///
137    /// This feature has graduated and is hard-coded for external Relays.
138    #[doc(hidden)]
139    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
140    DeprecatedOtelLogsEndpoint,
141    /// Enable standalone span ingestion.
142    ///
143    /// Serialized as `organizations:standalone-span-ingestion`.
144    #[doc(hidden)]
145    #[serde(rename = "organizations:standalone-span-ingestion")]
146    DeprecatedStandaloneSpanIngestion,
147
148    /// Forward compatibility.
149    #[doc(hidden)]
150    #[serde(other)]
151    Unknown,
152}
153
154/// A set of [`Feature`]s.
155#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
156pub struct FeatureSet(pub BTreeSet<Feature>);
157
158impl FeatureSet {
159    /// Returns `true` if the set of features is empty.
160    pub fn is_empty(&self) -> bool {
161        self.0.is_empty()
162    }
163
164    /// Returns `true` if the given feature is in the set.
165    pub fn has(&self, feature: Feature) -> bool {
166        self.0.contains(&feature)
167    }
168}
169
170impl FromIterator<Feature> for FeatureSet {
171    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
172        Self(BTreeSet::from_iter(iter))
173    }
174}
175
176impl<'de> Deserialize<'de> for FeatureSet {
177    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
178    where
179        D: serde::Deserializer<'de>,
180    {
181        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
182        set.remove(&Feature::Unknown);
183        Ok(Self(set))
184    }
185}
186
187#[cfg(test)]
188mod tests {
189    use super::*;
190
191    #[test]
192    fn roundtrip() {
193        let features: FeatureSet =
194            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
195        assert_eq!(
196            &features,
197            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
198        );
199        assert_eq!(
200            serde_json::to_string(&features).unwrap(),
201            r#"["organizations:session-replay"]"#
202        );
203    }
204}