Skip to content

Conversation

@jjbayer
Copy link
Member

@jjbayer jjbayer commented Dec 9, 2025

Add a new processing pipeline for attachments that are not explicitly associated to spans. These attachments are only associated by their trace ID, so they do not check span rate limits, but are stored in the same way as span attachments.

See https://develop.sentry.dev/sdk/data-model/envelope-items/#trace-attachment.

Closes INGEST-654.

@linear
Copy link

linear bot commented Dec 9, 2025

@jjbayer jjbayer changed the base branch from master to tobias-wilfert/feat/attachmentv2-scrubbing December 10, 2025 10:20
Base automatically changed from tobias-wilfert/feat/attachmentv2-scrubbing to master December 10, 2025 11:45
let attachments = envelope
.envelope_mut()
.take_items_by(|item| item.is_attachment_v2())
.take_items_by(|item| item.is_span_attachment())
Copy link
Member Author

Choose a reason for hiding this comment

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

The spans processor is now only concerned with trace attachments that have a span_id header.

item.set_parent_id(parent_id);

Ok(item)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved some of the functions into the new trace_attachments module.

Ok(ExpandedAttachment {
parent_id: item.parent_id().cloned(),
meta,
body: payload.slice_ref(body),
Copy link
Member Author

Choose a reason for hiding this comment

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

This function was moved over from the spans module, but I changed this to slice_ref to prevent copying the data.


metric!(
timer(RelayTimers::AttachmentScrubbing),
attachment_type = "trace_attachment",
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the metric tag from attachmentv2 to trace_attachment here.



def test_standalone_attachment_forwarding(mini_sentry, relay):
@pytest.mark.parametrize("owned_by", ["spans", "trace"])
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to do most of the testing by extending / parametrizing the existing span attachment tests.

def test_span_attachment_independent_rate_limiting(
mini_sentry,
relay,
outcomes_consumer,
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the dependency on the outcomes_consumer here to speed up the test. Since the test uses a non-processing relay, the outcomes_consumer would always be empty anyway.



def _add_sampling_config(
def add_sampling_config(
Copy link
Member Author

Choose a reason for hiding this comment

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

This function is imported from other modules, so I removed the leading underscore.

@jjbayer jjbayer marked this pull request as ready for review December 10, 2025 12:30
@jjbayer jjbayer requested a review from a team as a code owner December 10, 2025 12:31
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
pub struct AttachmentV2Meta {
pub struct TraceAttachmentMeta {
Copy link
Member

Choose a reason for hiding this comment

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

The name of this file is still attachment_v2 do we want to change that over to something else as well?
The only other spot we now have this naming is ContentType::AttachmentV2 I think there we can leave it though unless you think ContentType::TraceAttachment is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the name to TraceAttachment now, and also the content-type string. I added application/vnd.sentry.attachment.v2 as a legacy alias.

Co-authored-by: Sebastian Zivota <[email protected]>
Comment on lines +116 to +119
(!items.is_empty()).then(|| {
let work = SerializedAttachments { headers, items };
Managed::from_envelope(envelope, work)
})
Copy link
Member

Choose a reason for hiding this comment

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

This is purely defensive, right? Don't think items can/should every be empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe @Dav1dde's intention is to eventually get rid of split_envelope, and then prepare_envelope needs to be written in a way that they can handle any envelope.

Copy link
Member

@tobias-wilfert tobias-wilfert left a comment

Choose a reason for hiding this comment

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

Looks good and thanks for all the small fix ups along the way 🙏🏻

@jjbayer jjbayer enabled auto-merge December 11, 2025 09:03
@jjbayer jjbayer added this pull request to the merge queue Dec 11, 2025
Any commits made after this event will not be merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants