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::DeprecatedExtractSpansFromEvent,
11    Feature::DeprecatedStandaloneSpanIngestion,
12];
13
14/// Features exposed by project config.
15#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
16pub enum Feature {
17    /// Enables ingestion of Session Replays (Replay Recordings and Replay Events).
18    ///
19    /// Serialized as `organizations:session-replay`.
20    #[serde(rename = "organizations:session-replay")]
21    SessionReplay,
22    /// Enables data scrubbing of replay recording payloads.
23    ///
24    /// Serialized as `organizations:session-replay-recording-scrubbing`.
25    #[serde(rename = "organizations:session-replay-recording-scrubbing")]
26    SessionReplayRecordingScrubbing,
27    /// Disables select organizations from processing mobile replay events.
28    ///
29    /// Serialized as `organizations:session-replay-video-disabled`.
30    #[serde(rename = "organizations:session-replay-video-disabled")]
31    SessionReplayVideoDisabled,
32    /// Allow ingestion of metrics in the "custom" namespace.
33    ///
34    /// Serialized as `organizations:custom-metrics`.
35    #[serde(rename = "organizations:custom-metrics")]
36    CustomMetrics,
37    /// Enable processing profiles.
38    ///
39    /// Serialized as `organizations:profiling`.
40    #[serde(rename = "organizations:profiling")]
41    Profiling,
42    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
43    ///
44    /// Serialized as `organizations:relay-otlp-traces-endpoint`.
45    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
46    OtelTracesEndpoint,
47    /// Enable logs ingestion via the `/logs/` OTel endpoint.
48    ///
49    /// Serialized as `organizations:relay-otel-logs-endpoint`.
50    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
51    OtelLogsEndpoint,
52    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
53    ///
54    /// Serialized as `organizations:relay-playstation-ingestion`.
55    #[serde(rename = "organizations:relay-playstation-ingestion")]
56    PlaystationIngestion,
57    /// Discard transactions in a spans-only world.
58    ///
59    /// Serialized as `projects:discard-transaction`.
60    #[serde(rename = "projects:discard-transaction")]
61    DiscardTransaction,
62    /// Enable continuous profiling.
63    ///
64    /// Serialized as `organizations:continuous-profiling`.
65    #[serde(rename = "organizations:continuous-profiling")]
66    ContinuousProfiling,
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    /// Add a random trace ID to events that lack one.
107    #[serde(rename = "organizations:relay-default-trace-id")]
108    AddDefaultTraceID,
109    /// Enable experimental expansion of the unreal report in the endpoint rather than in the
110    /// processor. Only enable for organizations with sufficient attachment quota.
111    #[serde(rename = "organizations:relay-unreal-endpoint-expansion")]
112    UnrealEndpointExpansion,
113
114    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
115    ///
116    /// This is now the default behaviour of Relay.
117    #[serde(rename = "organizations:span-v2-otlp-processing")]
118    DeprecatedSpanV2OtlpProcessing,
119    /// This feature has deprecated and is kept for external Relays.
120    #[doc(hidden)]
121    #[serde(rename = "projects:span-metrics-extraction")]
122    DeprecatedExtractCommonSpanMetricsFromEvent,
123    /// This feature has been deprecated and is kept for external Relays.
124    #[doc(hidden)]
125    #[serde(rename = "projects:span-metrics-extraction-addons")]
126    DeprecatedExtractAddonsSpanMetricsFromEvent,
127    /// This feature has graduated and is hard-coded for external Relays.
128    #[doc(hidden)]
129    #[serde(rename = "organizations:indexed-spans-extraction")]
130    DeprecatedExtractSpansFromEvent,
131    /// Enable standalone span ingestion.
132    ///
133    /// Serialized as `organizations:standalone-span-ingestion`.
134    #[doc(hidden)]
135    #[serde(rename = "organizations:standalone-span-ingestion")]
136    DeprecatedStandaloneSpanIngestion,
137
138    /// Forward compatibility.
139    #[doc(hidden)]
140    #[serde(other)]
141    Unknown,
142}
143
144/// A set of [`Feature`]s.
145#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
146pub struct FeatureSet(pub BTreeSet<Feature>);
147
148impl FeatureSet {
149    /// Returns `true` if the set of features is empty.
150    pub fn is_empty(&self) -> bool {
151        self.0.is_empty()
152    }
153
154    /// Returns `true` if the given feature is in the set.
155    pub fn has(&self, feature: Feature) -> bool {
156        self.0.contains(&feature)
157    }
158}
159
160impl FromIterator<Feature> for FeatureSet {
161    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
162        Self(BTreeSet::from_iter(iter))
163    }
164}
165
166impl<'de> Deserialize<'de> for FeatureSet {
167    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
168    where
169        D: serde::Deserializer<'de>,
170    {
171        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
172        set.remove(&Feature::Unknown);
173        Ok(Self(set))
174    }
175}
176
177#[cfg(test)]
178mod tests {
179    use super::*;
180
181    #[test]
182    fn roundtrip() {
183        let features: FeatureSet =
184            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
185        assert_eq!(
186            &features,
187            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
188        );
189        assert_eq!(
190            serde_json::to_string(&features).unwrap(),
191            r#"["organizations:session-replay"]"#
192        );
193    }
194}