Skip to content

Commit

Permalink
instr(server): Count transactions that have attachments (#4344)
Browse files Browse the repository at this point in the history
Measure how many transactions have attachments to estimate the potential
impact of removing them.
  • Loading branch information
jjbayer authored Dec 5, 2024
1 parent fcc343c commit 931fa9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
49 changes: 32 additions & 17 deletions relay-server/src/endpoints/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,7 @@ pub async fn handle_envelope(
state: &ServiceState,
envelope: Box<Envelope>,
) -> Result<Option<EventId>, BadStoreRequest> {
let client_name = envelope.meta().client_name();
for item in envelope.items() {
metric!(
histogram(RelayHistograms::EnvelopeItemSize) = item.payload().len() as u64,
item_type = item.ty().name()
);
metric!(
counter(RelayCounters::EnvelopeItems) += 1,
item_type = item.ty().name(),
sdk = client_name.name(),
);
metric!(
counter(RelayCounters::EnvelopeItemBytes) += item.payload().len() as u64,
item_type = item.ty().name(),
sdk = client_name.name(),
);
}
emit_envelope_metrics(&envelope);

if state.memory_checker().check_memory().is_exceeded() {
return Err(BadStoreRequest::QueueFailed);
Expand Down Expand Up @@ -409,6 +393,37 @@ pub async fn handle_envelope(
}
}

fn emit_envelope_metrics(envelope: &Envelope) {
let client_name = envelope.meta().client_name();
let mut has_transaction = false;
let mut has_attachment = false;
for item in envelope.items() {
has_transaction |= item.ty() == &ItemType::Transaction;
has_attachment |= item.ty() == &ItemType::Attachment;
metric!(
histogram(RelayHistograms::EnvelopeItemSize) = item.payload().len() as u64,
item_type = item.ty().name()
);
metric!(
counter(RelayCounters::EnvelopeItems) += 1,
item_type = item.ty().name(),
sdk = client_name.name(),
);
metric!(
counter(RelayCounters::EnvelopeItemBytes) += item.payload().len() as u64,
item_type = item.ty().name(),
sdk = client_name.name(),
);
}

if has_transaction && has_attachment {
metric!(
counter(RelayCounters::TransactionsWithAttachments) += 1,
sdk = client_name.name(),
)
}
}

#[derive(Debug)]
pub struct TextResponse(pub Option<EventId>);

Expand Down
3 changes: 3 additions & 0 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ pub enum RelayCounters {
EnvelopeItems,
/// Number of bytes we processed per envelope item.
EnvelopeItemBytes,
/// Number of transactions with attachments seen in the request handler.
TransactionsWithAttachments,
/// Number of envelopes that were returned to the envelope buffer by the project cache.
///
/// This happens when the envelope buffer falsely assumes that the envelope's projects are loaded
Expand Down Expand Up @@ -848,6 +850,7 @@ impl CounterMetric for RelayCounters {
RelayCounters::EnvelopeAccepted => "event.accepted",
RelayCounters::EnvelopeRejected => "event.rejected",
RelayCounters::EnvelopeItems => "event.items",
RelayCounters::TransactionsWithAttachments => "transactions_with_attachments",
RelayCounters::EnvelopeItemBytes => "event.item_bytes",
RelayCounters::BufferEnvelopesReturned => "buffer.envelopes_returned",
RelayCounters::BufferTryPop => "buffer.try_pop",
Expand Down

0 comments on commit 931fa9d

Please sign in to comment.