Skip to content
29 changes: 29 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 [`ParentType`] of an attachment.
///
/// For standard attachments (V1) always returns [`ParentType::Event`].
pub fn attachment_parent_type(&self) -> Option<ParentType> {
let is_attachment = self.ty() == &ItemType::Attachment;
let is_trace_attachment = self.content_type() == Some(&ContentType::TraceAttachment);

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

/// 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,14 @@ 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.

#[derive(Debug)]
pub enum ParentType {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub enum ParentType {
pub enum AttachmentParentType {

Event,
Span,
Trace,
Comment on lines +1113 to +1115
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
Loading