Skip to content

Commit

Permalink
Emit metrics from processor::process_errors, make helper in event pro…
Browse files Browse the repository at this point in the history
…cessor
  • Loading branch information
aliu39 committed Jun 3, 2024
1 parent 8a9351e commit 2bb39e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
9 changes: 1 addition & 8 deletions relay-server/src/services/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,18 +1486,11 @@ impl EnvelopeProcessorService {
if state.has_event() {
event::scrub(state)?;
event::serialize(state)?;
event::emit_feedback_metrics(state.envelope());
}

attachment::scrub(state);

/*
//TODO:
if envelope state has user report v2:
let num_attachments = 0; // unsigned
count num attachments
metric!(counter(RelayCounters::FeedbackAttachments) += num_attachments as i64);
*/

Ok(())
}

Expand Down
22 changes: 21 additions & 1 deletion relay-server/src/services/processor/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use relay_quotas::DataCategory;
use relay_statsd::metric;
use serde_json::Value as SerdeValue;

use crate::envelope::{AttachmentType, ContentType, Item, ItemType};
use crate::envelope::{AttachmentType, ContentType, Envelope, Item, ItemType};
use crate::extractors::RequestMeta;
use crate::services::outcome::Outcome;
use crate::services::processor::{
Expand Down Expand Up @@ -420,6 +420,26 @@ pub fn has_unprintable_fields(event: &Annotated<Event>) -> bool {
}
}

//TODO: comment
//TODO: add test: all incr/no incr cases, envelope unchanged
pub fn emit_feedback_metrics(envelope: &Envelope) -> i64 {
let mut has_feedback = false;
let mut num_attachments = 0;
for item in envelope.items() {
match item.ty() {
ItemType::UserReportV2 => has_feedback = true,
ItemType::Attachment => num_attachments += 1,
_ => (),
}
}
if has_feedback && num_attachments > 0 {
metric!(counter(RelayCounters::FeedbackAttachments) += num_attachments);
num_attachments
} else {
0
}
}

/// Checks for duplicate items in an envelope.
///
/// An item is considered duplicate if it was not removed by sanitation in `process_event` and
Expand Down
6 changes: 0 additions & 6 deletions relay-server/src/services/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ impl StoreService {
let mut replay_event = None;
let mut replay_recording = None;

let mut has_feedback = false;
for item in envelope.items() {
match item.ty() {
ItemType::Attachment => {
Expand Down Expand Up @@ -253,7 +252,6 @@ impl StoreService {
)?;
}
ItemType::UserReportV2 => {
has_feedback = true;
let remote_addr = envelope.meta().client_addr().map(|addr| addr.to_string());
self.produce_user_report_v2(
event_id.ok_or(StoreError::NoEventId)?,
Expand Down Expand Up @@ -350,10 +348,6 @@ impl StoreService {
}
}

if has_feedback && !attachments.is_empty() {
metric!(counter(RelayCounters::FeedbackAttachments) += attachments.len() as i64);
}

if let Some(recording) = replay_recording {
// If a recording item type was seen we produce it to Kafka with the replay-event
// payload (should it have been provided).
Expand Down

0 comments on commit 2bb39e7

Please sign in to comment.