relay_pii/legacy.rs
1//! Legacy datascrubbing coniguration
2//!
3//! All these configuration options are ignored by the new data scrubbers which operate
4//! solely from the [PiiConfig] rules for the project.
5
6use std::sync::OnceLock;
7
8use serde::{Deserialize, Serialize};
9
10use crate::config::PiiConfig;
11use crate::convert;
12
13/// Configuration for Sentry's datascrubbing
14#[derive(Debug, Default, Clone, Serialize, Deserialize)]
15#[serde(default, rename_all = "camelCase")]
16pub struct DataScrubbingConfig {
17 /// List with the fields to be excluded.
18 pub exclude_fields: Vec<String>,
19 /// Toggles all data scrubbing on or off.
20 #[serde(skip_serializing_if = "crate::is_flag_default")]
21 pub scrub_data: bool,
22 /// Should ip addresses be scrubbed from messages?
23 #[serde(skip_serializing_if = "crate::is_flag_default")]
24 pub scrub_ip_addresses: bool,
25 /// List of sensitive fields to be scrubbed from the messages.
26 pub sensitive_fields: Vec<String>,
27 /// Controls whether default fields will be scrubbed.
28 #[serde(skip_serializing_if = "crate::is_flag_default")]
29 pub scrub_defaults: bool,
30
31 /// PII config derived from datascrubbing settings.
32 ///
33 /// Cached because the conversion process is expensive.
34 ///
35 /// NOTE: We discarded the idea of making the conversion to PiiConfig part of deserialization,
36 /// because we want the conversion to run on the processing sync arbiter, so that it does not
37 /// slow down or even crash other parts of the system.
38 #[serde(skip)]
39 pub(super) pii_config: OnceLock<Option<PiiConfig>>,
40}
41
42impl DataScrubbingConfig {
43 /// Creates a new data scrubbing configuration that does nothing on the event.
44 pub fn new_disabled() -> Self {
45 let pii_config = OnceLock::new();
46 let _ = pii_config.set(None);
47
48 DataScrubbingConfig {
49 exclude_fields: vec![],
50 scrub_data: false,
51 scrub_ip_addresses: false,
52 sensitive_fields: vec![],
53 scrub_defaults: false,
54 pii_config,
55 }
56 }
57
58 /// Returns true if datascrubbing is disabled.
59 pub fn is_disabled(&self) -> bool {
60 !self.scrub_data && !self.scrub_ip_addresses
61 }
62
63 /// Get the PII config derived from datascrubbing settings.
64 ///
65 /// This can be computationally expensive when called for the first time. The result is cached
66 /// internally and reused on the second call.
67 pub fn pii_config(&self) -> &'_ Option<PiiConfig> {
68 self.pii_config.get_or_init(|| self.pii_config_uncached())
69 }
70
71 /// Like [`pii_config`](Self::pii_config) but without internal caching.
72 #[inline]
73 pub fn pii_config_uncached(&self) -> Option<PiiConfig> {
74 convert::to_pii_config(self)
75 }
76}