feat(attachments): Migrate standalone logic#5703
feat(attachments): Migrate standalone logic#5703tobias-wilfert wants to merge 15 commits intomasterfrom
Conversation
| ) -> Option<Managed<Self::UnitOfWork>> { | ||
| // For now only extract the standalone attachments. | ||
| if envelope.envelope().items().any(Item::creates_event) { | ||
| return None; | ||
| }; |
There was a problem hiding this comment.
Not sure if we can just grab attachments here, since I would assume that this break in the future.
There was a problem hiding this comment.
I think it's fine to remove the check, but instead maybe explicitly turn it into a debug_assert!
…github.com:getsentry/relay into tobias-wilfert/feat/migrate-standalone-attachments
| attachments = [ | ||
| ("att_1", "foo.txt", chunked_contents), | ||
| ("att_2", "foobar.txt", b""), | ||
| ] | ||
| relay.send_attachments(project_id, event_id, attachments) | ||
| relay.send_attachments( | ||
| project_id, event_id, [("att_1", "foo.txt", chunked_contents)] | ||
| ) |
There was a problem hiding this comment.
Split this into 2 tests since the 'wrong' attachment arrived first now, causing the test to fail.
Not sure how this never flaked before.
| pub struct StoreAttachment { | ||
| pub struct StoreTraceAttachment { |
There was a problem hiding this comment.
Renamed this to avoid naming collisions.
| /// Uploads the attachment. | ||
| /// | ||
| /// This mutates the attachment item in-place, setting the `stored_key` field to the key in the | ||
| /// objectstore. | ||
| async fn handle_attachment(&self, mut attachment: Managed<StoreAttachment>) { |
There was a problem hiding this comment.
Logic taken over from handle_envelope with minor changes.
…github.com:getsentry/relay into tobias-wilfert/feat/migrate-standalone-attachments
|
Current plan is to deploy this without a feature flag, if there are objections to it I can still add one. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Standalone attachments missing PII scrubbing for untyped items
- Changed filter to use unwrap_or_default() so attachments without explicit AttachmentType headers are correctly routed to StandaloneAttachments group for PII scrubbing.
Or push these changes by commenting:
@cursor push fc2208ed3e
Preview (fc2208ed3e)
diff --git a/relay-server/src/services/processor.rs b/relay-server/src/services/processor.rs
--- a/relay-server/src/services/processor.rs
+++ b/relay-server/src/services/processor.rs
@@ -380,7 +380,7 @@
if !envelope.items().any(Item::creates_event) {
let standalone_attachments = envelope.take_items_by(|i| {
i.requires_event()
- && matches!(i.attachment_type(), Some(AttachmentType::Attachment))
+ && i.attachment_type().unwrap_or_default() == AttachmentType::Attachment
});
if !standalone_attachments.is_empty() {
grouped_envelopes.push((| Some(Outcome::RateLimited(reason_code)) | ||
| } | ||
| #[cfg(feature = "processing")] | ||
| Self::NoEventId => Some(Outcome::Invalid(DiscardReason::Internal)), |
There was a problem hiding this comment.
I assume Relay somehow already ensures there is always an event id?
What happens if the there is a standalone attachment sent in an envelope without event id? Does it make sense to ingest it? And does that actually mean it's Internal?
There was a problem hiding this comment.
The old logic checks it in the store here, so this check "just moved into the processor".
relay/relay-server/src/services/store.rs
Line 371 in bf82189
The outcome is the same as that of the store error (but we can ofcourse improve it):
relay/relay-server/src/services/store.rs
Lines 52 to 67 in bf82189
| ) -> Option<Managed<Self::UnitOfWork>> { | ||
| // For now only extract the standalone attachments. | ||
| if envelope.envelope().items().any(Item::creates_event) { | ||
| return None; | ||
| }; |
There was a problem hiding this comment.
I think it's fine to remove the check, but instead maybe explicitly turn it into a debug_assert!
| Err(error) => { | ||
| relay_log::error!(error = &error as &dyn std::error::Error, "session error"); | ||
| relay_statsd::metric!( | ||
| counter(RelayCounters::AttachmentUpload) += 1, | ||
| result = error.to_string().as_str(), | ||
| type = "attachment", | ||
| ); | ||
| } |
There was a problem hiding this comment.
This match is pretty large, maybe an early return makes it more readable.
session.inspect_err(|_| <analytics here>)?;
There was a problem hiding this comment.
The function is a bit sneaky in the sense that at the end we still do self.store.send(attachment) no matter what match arm we end up in.
Co-authored-by: David Herberth <david.herberth@sentry.io>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Moves the standalone attachment logic out of
process_standalone, migrating the logic to the new processor architecture.Ref: https://linear.app/getsentry/issue/INGEST-796/extract-attachment-logic-from-process-standalone