relay_filter/
interface.rs1use url::Url;
4
5use relay_event_schema::protocol::{
6 Csp, Event, EventType, Exception, LogEntry, Replay, Span, Values,
7};
8
9pub trait Filterable {
11 fn csp(&self) -> Option<&Csp>;
13
14 fn exceptions(&self) -> Option<&Values<Exception>>;
16
17 fn ip_addr(&self) -> Option<&str>;
19
20 fn logentry(&self) -> Option<&LogEntry>;
22
23 fn release(&self) -> Option<&str>;
25
26 fn transaction(&self) -> Option<&str>;
28
29 fn url(&self) -> Option<Url>;
31
32 fn user_agent(&self) -> Option<&str>;
34
35 fn header(&self, header_name: &str) -> Option<&str>;
42}
43
44impl Filterable for Event {
45 fn csp(&self) -> Option<&Csp> {
46 if self.ty.value() != Some(&EventType::Csp) {
47 return None;
48 }
49 self.csp.value()
50 }
51
52 fn exceptions(&self) -> Option<&Values<Exception>> {
53 self.exceptions.value()
54 }
55
56 fn ip_addr(&self) -> Option<&str> {
57 let user = self.user.value()?;
58 Some(user.ip_address.value()?.as_ref())
59 }
60
61 fn logentry(&self) -> Option<&LogEntry> {
62 self.logentry.value()
63 }
64
65 fn release(&self) -> Option<&str> {
66 self.release.as_str()
67 }
68
69 fn transaction(&self) -> Option<&str> {
70 if self.ty.value() != Some(&EventType::Transaction) {
71 return None;
72 }
73 self.transaction.as_str()
74 }
75
76 fn url(&self) -> Option<Url> {
77 let url_str = self.request.value()?.url.value()?;
78 Url::parse(url_str).ok()
79 }
80
81 fn user_agent(&self) -> Option<&str> {
82 self.user_agent()
83 }
84
85 fn header(&self, header_name: &str) -> Option<&str> {
86 self.request
87 .value()?
88 .headers
89 .value()?
90 .get_header(header_name)
91 }
92}
93
94impl Filterable for Replay {
95 fn csp(&self) -> Option<&Csp> {
96 None
97 }
98
99 fn exceptions(&self) -> Option<&Values<Exception>> {
100 None
101 }
102
103 fn ip_addr(&self) -> Option<&str> {
104 let user = self.user.value()?;
105 Some(user.ip_address.value()?.as_ref())
106 }
107
108 fn logentry(&self) -> Option<&LogEntry> {
109 None
110 }
111
112 fn release(&self) -> Option<&str> {
113 self.release.as_str()
114 }
115
116 fn transaction(&self) -> Option<&str> {
117 None
118 }
119
120 fn url(&self) -> Option<Url> {
121 let url_str = self.request.value()?.url.value()?;
122 Url::parse(url_str).ok()
123 }
124
125 fn user_agent(&self) -> Option<&str> {
126 self.user_agent()
127 }
128
129 fn header(&self, header_name: &str) -> Option<&str> {
130 self.request
131 .value()?
132 .headers
133 .value()?
134 .get_header(header_name)
135 }
136}
137
138impl Filterable for Span {
139 fn csp(&self) -> Option<&Csp> {
140 None
142 }
143
144 fn exceptions(&self) -> Option<&Values<Exception>> {
145 None
147 }
148
149 fn ip_addr(&self) -> Option<&str> {
150 self.data.value()?.client_address.as_str()
151 }
152
153 fn logentry(&self) -> Option<&LogEntry> {
154 None
156 }
157
158 fn release(&self) -> Option<&str> {
159 self.data.value()?.release.as_str()
160 }
161
162 fn transaction(&self) -> Option<&str> {
163 self.data.value()?.segment_name.as_str()
164 }
165
166 fn url(&self) -> Option<Url> {
167 let url_str = self.data.value()?.url_full.as_str()?;
168 Url::parse(url_str).ok()
169 }
170
171 fn user_agent(&self) -> Option<&str> {
172 self.data.value()?.user_agent_original.as_str()
173 }
174
175 fn header(&self, _: &str) -> Option<&str> {
176 None
177 }
178}