-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathfeature.rs
60 lines (56 loc) · 2.19 KB
/
feature.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::borrow::Cow;
use serde::{Deserialize, Serialize};
/// Features exposed by project config.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub enum Feature {
/// Enables ingestion of Session Replays (Replay Recordings and Replay Events).
SessionReplay,
/// Enables data scrubbing of replay recording payloads.
SessionReplayRecordingScrubbing,
/// Enables device.class synthesis
///
/// Enables device.class tag synthesis on mobile events.
DeviceClassSynthesis,
/// Enables metric extraction from spans.
SpanMetricsExtraction,
/// Apply transaction normalization rules to transactions from legacy SDKs.
NormalizeLegacyTransactions,
/// Forward compatibility.
Unknown(String),
}
impl<'de> Deserialize<'de> for Feature {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let feature_name = Cow::<str>::deserialize(deserializer)?;
Ok(match feature_name.as_ref() {
"organizations:session-replay" => Feature::SessionReplay,
"organizations:session-replay-recording-scrubbing" => {
Feature::SessionReplayRecordingScrubbing
}
"organizations:device-class-synthesis" => Feature::DeviceClassSynthesis,
"projects:span-metrics-extraction" => Feature::SpanMetricsExtraction,
_ => Feature::Unknown(feature_name.to_string()),
})
}
}
impl Serialize for Feature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(match self {
Feature::SessionReplay => "organizations:session-replay",
Feature::SessionReplayRecordingScrubbing => {
"organizations:session-replay-recording-scrubbing"
}
Feature::DeviceClassSynthesis => "organizations:device-class-synthesis",
Feature::SpanMetricsExtraction => "projects:span-metrics-extraction",
Feature::NormalizeLegacyTransactions => {
"organizations:transaction-name-normalize-legacy"
}
Feature::Unknown(s) => s,
})
}
}