Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions relay-server/src/managed/counted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,40 @@ impl Counted for Item {
}

impl Counted for Box<Envelope> {
fn quantities(&self) -> Quantities {
EnvelopeSummary::compute(self).quantities()
}
}

impl Counted for EnvelopeSummary {
fn quantities(&self) -> Quantities {
let mut quantities = Quantities::new();

// This matches the implementation of `ManagedEnvelope::reject`.
let summary = EnvelopeSummary::compute(self);
if let Some(category) = summary.event_category {
if let Some(category) = self.event_category {
quantities.push((category, 1));
if let Some(category) = category.index_category() {
quantities.push((category, 1));
}
}

let data = [
(DataCategory::Attachment, summary.attachment_quantity),
(DataCategory::Profile, summary.profile_quantity),
(DataCategory::ProfileIndexed, summary.profile_quantity),
(DataCategory::Span, summary.span_quantity),
(DataCategory::SpanIndexed, summary.span_quantity),
(DataCategory::Attachment, self.attachment_quantity),
(DataCategory::Profile, self.profile_quantity),
(DataCategory::ProfileIndexed, self.profile_quantity),
(DataCategory::Span, self.span_quantity),
(DataCategory::SpanIndexed, self.span_quantity),
(
DataCategory::Transaction,
summary.secondary_transaction_quantity,
),
(DataCategory::Span, summary.secondary_span_quantity),
(DataCategory::Replay, summary.replay_quantity),
(DataCategory::ProfileChunk, summary.profile_chunk_quantity),
(
DataCategory::ProfileChunkUi,
summary.profile_chunk_ui_quantity,
self.secondary_transaction_quantity,
),
(DataCategory::LogItem, summary.log_item_quantity),
(DataCategory::LogByte, summary.log_byte_quantity),
(DataCategory::Monitor, summary.monitor_quantity),
(DataCategory::Span, self.secondary_span_quantity),
(DataCategory::Replay, self.replay_quantity),
(DataCategory::UserReportV2, self.user_report_quantity),
(DataCategory::ProfileChunk, self.profile_chunk_quantity),
(DataCategory::ProfileChunkUi, self.profile_chunk_ui_quantity),
(DataCategory::LogItem, self.log_item_quantity),
(DataCategory::LogByte, self.log_byte_quantity),
(DataCategory::Monitor, self.monitor_quantity),
];

for (category, quantity) in data {
Expand Down
125 changes: 3 additions & 122 deletions relay-server/src/managed/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use relay_system::Addr;

use crate::envelope::{Envelope, Item};
use crate::extractors::RequestMeta;
use crate::managed::Counted;
use crate::services::outcome::{DiscardReason, Outcome, TrackOutcome};
use crate::services::processor::{Processed, ProcessingGroup};
use crate::statsd::{RelayCounters, RelayTimers};
Expand Down Expand Up @@ -349,128 +350,8 @@ impl ManagedEnvelope {
}
}

if let Some(category) = self.event_category() {
if let Some(category) = category.index_category() {
self.track_outcome(outcome.clone(), category, 1);
}
self.track_outcome(outcome.clone(), category, 1);
}

if self.context.summary.attachment_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::Attachment,
self.context.summary.attachment_quantity,
);
}

if self.context.summary.monitor_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::Monitor,
self.context.summary.monitor_quantity,
);
}

if self.context.summary.profile_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::Profile,
self.context.summary.profile_quantity,
);
self.track_outcome(
outcome.clone(),
DataCategory::ProfileIndexed,
self.context.summary.profile_quantity,
);
}

if self.context.summary.span_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::Span,
self.context.summary.span_quantity,
);
self.track_outcome(
outcome.clone(),
DataCategory::SpanIndexed,
self.context.summary.span_quantity,
);
}

if self.context.summary.log_item_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::LogItem,
self.context.summary.log_item_quantity,
);
}
if self.context.summary.log_byte_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::LogByte,
self.context.summary.log_byte_quantity,
);
}

// Track outcomes for attached secondary transactions, e.g. extracted from metrics.
//
// Primary transaction count is already tracked through the event category
// (see: `Self::event_category()`).
if self.context.summary.secondary_transaction_quantity > 0 {
self.track_outcome(
outcome.clone(),
// Secondary transaction counts are never indexed transactions
DataCategory::Transaction,
self.context.summary.secondary_transaction_quantity,
);
}

// Track outcomes for attached secondary spans, e.g. extracted from metrics.
//
// Primary span count is already tracked through `SpanIndexed`.
if self.context.summary.secondary_span_quantity > 0 {
self.track_outcome(
outcome.clone(),
// Secondary transaction counts are never indexed transactions
DataCategory::Span,
self.context.summary.secondary_span_quantity,
);
}

if self.context.summary.replay_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::Replay,
self.context.summary.replay_quantity,
);
}

// Track outcomes for user reports, the legacy item type for user feedback.
//
// User reports are not events, but count toward UserReportV2 for quotas and outcomes.
if self.context.summary.user_report_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::UserReportV2,
self.context.summary.user_report_quantity,
);
}

if self.context.summary.profile_chunk_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::ProfileChunk,
self.context.summary.profile_chunk_quantity,
);
}

if self.context.summary.profile_chunk_ui_quantity > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::ProfileChunkUi,
self.context.summary.profile_chunk_ui_quantity,
);
for (category, quantity) in self.context.summary.quantities() {
self.track_outcome(outcome.clone(), category, quantity);
}

self.finish(RelayCounters::EnvelopeRejected, handling);
Expand Down
Loading