Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
38 changes: 38 additions & 0 deletions relay-server/src/envelope/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,27 @@ impl Item {
self.is_attachment_v2() && self.parent_id().is_none()
}

/// Returns the [`AttachmentParentType`] of an attachment.
///
/// For standard attachments (V1) always returns [`AttachmentParentType::Event`].
pub fn attachment_parent_type(&self) -> AttachmentParentType {
let is_attachment = self.ty() == &ItemType::Attachment;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would make this an early return, i.e.

if self.ty() != &ItemType::Attachment { return None; }

debug_assert!(
is_attachment,
"function should only be called on attachments"
);
let is_trace_attachment = self.content_type() == Some(&ContentType::TraceAttachment);

if is_trace_attachment {
match self.parent_id() {
Some(ParentId::SpanId(_)) => AttachmentParentType::Span,
None => AttachmentParentType::Trace,
}
} else {
AttachmentParentType::Event
}
}

/// Returns the attachment payload size.
///
/// For AttachmentV2, returns only the size of the actual payload, excluding the attachment meta.
Expand Down Expand Up @@ -1086,6 +1107,23 @@ impl ParentId {
}
}

/// The type of parent entity an attachment is associated with.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good just to add some examples or what this is used for.

///
/// This is used to route attachments to different rate limiting buckets, since
/// depending on the parent the limiting logic is different. E.g. if the attachment has
/// [`AttachmentParentType::Span`] than it should be dropped if there are span limits.
///
/// See [`Item::attachment_parent_type`] for how this is determined from an item.
#[derive(Debug)]
pub enum AttachmentParentType {
/// The parent type for all V1 attachments (e.g. minidumps)
Event,
/// The parent type for all span V2 attachments.
Span,
/// The parent type for all trace V2 attachments.
Trace,
Comment on lines 1120 to 1124
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised clippy isn't mad at this, usually need to document every public symbol and enum variants are always public if the enum is.

Would be good to just add documentation of what we consider an Event attachment parent etc. (can also just be generic docs on the type) with an example.

}

#[cfg(test)]
mod tests {
use crate::integrations::OtelFormat;
Expand Down
7 changes: 5 additions & 2 deletions relay-server/src/managed/counted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ impl Counted for Box<Envelope> {
}

let data = [
(DataCategory::Attachment, summary.attachment_quantity),
(
DataCategory::Attachment,
summary.attachment_quantities.bytes(),
),
(
DataCategory::AttachmentItem,
summary.attachment_item_quantity,
summary.attachment_quantities.count(),
),
(DataCategory::Profile, summary.profile_quantity),
(DataCategory::ProfileIndexed, summary.profile_quantity),
Expand Down
10 changes: 5 additions & 5 deletions relay-server/src/managed/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl ManagedEnvelope {

relay_log::error!(
tags.project_key = self.scoping().project_key.to_string(),
tags.has_attachments = summary.attachment_quantity > 0,
tags.has_attachments = summary.attachment_quantities.bytes() > 0,
tags.has_sessions = summary.session_quantity > 0,
tags.has_profiles = summary.profile_quantity > 0,
tags.has_transactions = summary.secondary_transaction_quantity > 0,
Expand All @@ -354,19 +354,19 @@ impl ManagedEnvelope {
self.track_outcome(outcome.clone(), category, 1);
}

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

if self.context.summary.attachment_item_quantity > 0 {
if self.context.summary.attachment_quantities.count() > 0 {
self.track_outcome(
outcome.clone(),
DataCategory::AttachmentItem,
self.context.summary.attachment_item_quantity,
self.context.summary.attachment_quantities.count(),
);
}

Expand Down
Loading