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::ScrubMongoDbDescriptions,
11    Feature::DeprecatedExtractSpansFromEvent,
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    /// Enables device.class synthesis
33    ///
34    /// Enables device.class tag synthesis on mobile events.
35    ///
36    /// Serialized as `organizations:device-class-synthesis`.
37    #[serde(rename = "organizations:device-class-synthesis")]
38    DeviceClassSynthesis,
39    /// Allow ingestion of metrics in the "custom" namespace.
40    ///
41    /// Serialized as `organizations:custom-metrics`.
42    #[serde(rename = "organizations:custom-metrics")]
43    CustomMetrics,
44    /// Enable processing profiles.
45    ///
46    /// Serialized as `organizations:profiling`.
47    #[serde(rename = "organizations:profiling")]
48    Profiling,
49    /// Enable standalone span ingestion.
50    ///
51    /// Serialized as `organizations:standalone-span-ingestion`.
52    #[serde(rename = "organizations:standalone-span-ingestion")]
53    StandaloneSpanIngestion,
54    /// Enable standalone span ingestion via the `/traces/` OTel endpoint.
55    ///
56    /// Serialized as `organizations:relay-otlp-traces-endpoint`.
57    #[serde(rename = "organizations:relay-otlp-traces-endpoint")]
58    OtelTracesEndpoint,
59    /// Enable logs ingestion via the `/logs/` OTel endpoint.
60    ///
61    /// Serialized as `organizations:relay-otel-logs-endpoint`.
62    #[serde(rename = "organizations:relay-otel-logs-endpoint")]
63    OtelLogsEndpoint,
64    /// Enable playstation crash dump ingestion via the `/playstation/` endpoint.
65    ///
66    /// Serialized as `organizations:relay-playstation-ingestion`.
67    #[serde(rename = "organizations:relay-playstation-ingestion")]
68    PlaystationIngestion,
69    /// Discard transactions in a spans-only world.
70    ///
71    /// Serialized as `projects:discard-transaction`.
72    #[serde(rename = "projects:discard-transaction")]
73    DiscardTransaction,
74    /// Enable continuous profiling.
75    ///
76    /// Serialized as `organizations:continuous-profiling`.
77    #[serde(rename = "organizations:continuous-profiling")]
78    ContinuousProfiling,
79    /// Enabled for beta orgs
80    ///
81    /// Serialized as `organizations:continuous-profiling-beta`.
82    #[serde(rename = "organizations:continuous-profiling-beta")]
83    ContinuousProfilingBeta,
84    /// Enabled when only beta orgs are allowed to send continuous profiles.
85    ///
86    /// Serialized as `organizations:continuous-profiling-beta-ingest`.
87    #[serde(rename = "organizations:continuous-profiling-beta-ingest")]
88    ContinuousProfilingBetaIngest,
89    /// Enable log ingestion for our log product (this is not internal logging).
90    ///
91    /// Serialized as `organizations:ourlogs-ingestion`.
92    #[serde(rename = "organizations:ourlogs-ingestion")]
93    OurLogsIngestion,
94    /// Enable trace metric ingestion for our trace metric product.
95    ///
96    /// Serialized as `organizations:tracemetrics-ingestion`.
97    #[serde(rename = "organizations:tracemetrics-ingestion")]
98    TraceMetricsIngestion,
99    /// This feature has graduated ant is hard-coded for external Relays.
100    #[doc(hidden)]
101    #[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
102    IngestUnsampledProfiles,
103    /// This feature has graduated and is hard-coded for external Relays.
104    #[doc(hidden)]
105    #[serde(rename = "organizations:user-feedback-ingest")]
106    UserReportV2Ingest,
107    /// This feature has graduated and is hard-coded for external Relays.
108    #[doc(hidden)]
109    #[serde(rename = "organizations:performance-queries-mongodb-extraction")]
110    ScrubMongoDbDescriptions,
111    #[doc(hidden)]
112    #[serde(rename = "organizations:view-hierarchy-scrubbing")]
113    ViewHierarchyScrubbing,
114    /// Detect performance issues in the new standalone spans pipeline instead of on transactions.
115    #[serde(rename = "organizations:performance-issues-spans")]
116    PerformanceIssuesSpans,
117    /// Enables the experimental Span V2 processing pipeline in Relay.
118    #[serde(rename = "projects:span-v2-experimental-processing")]
119    SpanV2ExperimentalProcessing,
120    /// Enable the experimental Span Attachment subset of the Span V2 processing pipeline in Relay.
121    #[serde(rename = "projects:span-v2-attachment-processing")]
122    SpanV2AttachmentProcessing,
123    /// Enable the experimental Trace Attachment pipeline in Relay.
124    #[serde(rename = "projects:trace-attachment-processing")]
125    TraceAttachmentProcessing,
126    /// Enable the upload endpoint for attachments.
127    #[serde(rename = "projects:relay-upload-endpoint")]
128    UploadEndpoint,
129    /// Enable the new Error processing pipeline in Relay.
130    #[serde(rename = "organizations:relay-new-error-processing")]
131    NewErrorProcessing,
132    /// Enable the new Client Reports pipeline in Relay.
133    #[serde(rename = "organizations:new-client-report-processing")]
134    NewClientReportProcessing,
135
136    /// Enables OTLP spans to use the Span V2 processing pipeline in Relay.
137    ///
138    /// This is now the default behaviour of Relay.
139    #[serde(rename = "organizations:span-v2-otlp-processing")]
140    DeprecatedSpanV2OtlpProcessing,
141    /// This feature has deprecated and is kept for external Relays.
142    #[doc(hidden)]
143    #[serde(rename = "projects:span-metrics-extraction")]
144    DeprecatedExtractCommonSpanMetricsFromEvent,
145    /// This feature has been deprecated and is kept for external Relays.
146    #[doc(hidden)]
147    #[serde(rename = "projects:span-metrics-extraction-addons")]
148    DeprecatedExtractAddonsSpanMetricsFromEvent,
149    /// This feature has graduated and is hard-coded for external Relays.
150    #[doc(hidden)]
151    #[serde(rename = "organizations:indexed-spans-extraction")]
152    DeprecatedExtractSpansFromEvent,
153    /// Forward compatibility.
154    #[doc(hidden)]
155    #[serde(other)]
156    Unknown,
157}
158
159/// A set of [`Feature`]s.
160#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
161pub struct FeatureSet(pub BTreeSet<Feature>);
162
163impl FeatureSet {
164    /// Returns `true` if the set of features is empty.
165    pub fn is_empty(&self) -> bool {
166        self.0.is_empty()
167    }
168
169    /// Returns `true` if the given feature is in the set.
170    pub fn has(&self, feature: Feature) -> bool {
171        self.0.contains(&feature)
172    }
173}
174
175impl FromIterator<Feature> for FeatureSet {
176    fn from_iter<T: IntoIterator<Item = Feature>>(iter: T) -> Self {
177        Self(BTreeSet::from_iter(iter))
178    }
179}
180
181impl<'de> Deserialize<'de> for FeatureSet {
182    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
183    where
184        D: serde::Deserializer<'de>,
185    {
186        let mut set = BTreeSet::<Feature>::deserialize(deserializer)?;
187        set.remove(&Feature::Unknown);
188        Ok(Self(set))
189    }
190}
191
192#[cfg(test)]
193mod tests {
194    use super::*;
195
196    #[test]
197    fn roundtrip() {
198        let features: FeatureSet =
199            serde_json::from_str(r#"["organizations:session-replay", "foo"]"#).unwrap();
200        assert_eq!(
201            &features,
202            &FeatureSet(BTreeSet::from([Feature::SessionReplay]))
203        );
204        assert_eq!(
205            serde_json::to_string(&features).unwrap(),
206            r#"["organizations:session-replay"]"#
207        );
208    }
209}