Skip to content

Commit 9ec42ed

Browse files
ref(normalization): Add origin and event_type tags to normalization decision (#3764)
S4S processing relays run some normalization and I can't explain why. Adding these two tags should provide enough clarity: - `origin`: whether the event is coming from an internal relay. - `event_type`: the type of the event _before_ normalizing it (i.e. it could be inaccurate). Could processing relays create transactions and explain it?
1 parent 5b79e15 commit 9ec42ed

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

relay-base-schema/src/events.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ pub enum EventType {
5353
Default,
5454
}
5555

56+
impl EventType {
57+
/// Returns the string representation of this event type.
58+
pub fn as_str(&self) -> &'static str {
59+
match self {
60+
EventType::Default => "default",
61+
EventType::Error => "error",
62+
EventType::Csp => "csp",
63+
EventType::Hpkp => "hpkp",
64+
EventType::ExpectCt => "expectct",
65+
EventType::ExpectStaple => "expectstaple",
66+
EventType::Nel => "nel",
67+
EventType::Transaction => "transaction",
68+
EventType::UserReportV2 => "feedback",
69+
}
70+
}
71+
}
72+
5673
/// An error used when parsing `EventType`.
5774
#[derive(Clone, Copy, Debug)]
5875
pub struct ParseEventTypeError;
@@ -86,17 +103,7 @@ impl FromStr for EventType {
86103

87104
impl fmt::Display for EventType {
88105
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89-
match *self {
90-
EventType::Default => write!(f, "default"),
91-
EventType::Error => write!(f, "error"),
92-
EventType::Csp => write!(f, "csp"),
93-
EventType::Hpkp => write!(f, "hpkp"),
94-
EventType::ExpectCt => write!(f, "expectct"),
95-
EventType::ExpectStaple => write!(f, "expectstaple"),
96-
EventType::Nel => write!(f, "nel"),
97-
EventType::Transaction => write!(f, "transaction"),
98-
EventType::UserReportV2 => write!(f, "feedback"),
99-
}
106+
write!(f, "{}", self.as_str())
100107
}
101108
}
102109

relay-server/src/services/processor.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1381,11 +1381,23 @@ impl EnvelopeProcessorService {
13811381
.get_item_by(|item| item.attachment_type().is_some())
13821382
.and_then(|item| item.attachment_type())
13831383
.map(|ty| ty.to_string());
1384+
let event_type = state
1385+
.event
1386+
.value()
1387+
.and_then(|e| e.ty.value())
1388+
.map(|ty| ty.as_str())
1389+
.unwrap_or("none");
13841390

13851391
if !state.has_event() {
13861392
metric!(
13871393
counter(RelayCounters::NormalizationDecision) += 1,
1394+
event_type = event_type,
13881395
attachment_type = attachment_type.as_deref().unwrap_or("none"),
1396+
origin = if state.envelope().meta().is_from_internal_relay() {
1397+
"internal"
1398+
} else {
1399+
"external"
1400+
},
13891401
decision = "no_event"
13901402
);
13911403

@@ -1407,7 +1419,13 @@ impl EnvelopeProcessorService {
14071419
{
14081420
metric!(
14091421
counter(RelayCounters::NormalizationDecision) += 1,
1422+
event_type = event_type,
14101423
attachment_type = attachment_type.as_deref().unwrap_or("none"),
1424+
origin = if state.envelope().meta().is_from_internal_relay() {
1425+
"internal"
1426+
} else {
1427+
"external"
1428+
},
14111429
decision = "skip_normalized"
14121430
);
14131431
return Ok(());
@@ -1419,7 +1437,13 @@ impl EnvelopeProcessorService {
14191437

14201438
metric!(
14211439
counter(RelayCounters::NormalizationDecision) += 1,
1440+
event_type = event_type,
14221441
attachment_type = attachment_type.as_deref().unwrap_or("none"),
1442+
origin = if state.envelope().meta().is_from_internal_relay() {
1443+
"internal"
1444+
} else {
1445+
"external"
1446+
},
14231447
decision = if full_normalization {
14241448
"full_normalization"
14251449
} else {

0 commit comments

Comments
 (0)