Skip to content

Conversation

Litarnus
Copy link
Contributor

@Litarnus Litarnus commented Sep 25, 2025

Introducing attachment support for PHP!

Attachments can be set on Scopes and will be added to Errors and Transaction events when sending them to sentry.

The PR currently does not enforce limits and reads the entire attachment content in memory before sending it. There is room for improvement such as respecting attachment limits as well as streaming the envelope to reduce the memory impact.

@Litarnus Litarnus self-assigned this Sep 29, 2025
@Litarnus Litarnus added the 5.x label Sep 29, 2025
Copy link
Collaborator

@stayallive stayallive left a comment

Choose a reason for hiding this comment

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

Single suggestion but nothing major. Looks good to me!

switch ($event->getType()) {
case EventType::event():
$items[] = EventItem::toEnvelopeItem($event);
$items[] = AttachmentItem::toEnvelopeItem($event);
Copy link
Collaborator

Choose a reason for hiding this comment

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

For clarity I think I would go for this (also in the transaction) instead and move the loop here. Yes it's a little more duplicated code but I think the clarity is a little better to also keep all the toEnvelopeItem methods returning a single item instead of multiple or none.

Suggested change
$items[] = AttachmentItem::toEnvelopeItem($event);
foreach ($event->getAttachments() as $attachment) {
$items[] = AttachmentItem::toEnvelopeItem($attachment);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, very good point!

@Litarnus Litarnus marked this pull request as ready for review October 14, 2025 09:28
public function getData(): ?string
{
return @file_get_contents($this->path) ?: null;
}
Copy link

Choose a reason for hiding this comment

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

Bug: Null Handling Bug in File Operations

The ?: null operator in getSize() and getData() incorrectly handles empty files. It converts filesize()'s 0 and file_get_contents()'s empty string '' into null. This causes empty files to be treated as unreadable, conflicting with tests expecting 0 for size and '' for data.

Fix in Cursor Fix in Web

}

return implode("\n", $result);
}
Copy link

Choose a reason for hiding this comment

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

Bug: Null Attachments Cause Malformed Envelope Data

The toEnvelopeItem method includes null results from toAttachmentItem when attachment data is missing. These null values are then converted to empty strings by implode("\n", $result), creating extra newlines and malformed envelope data that can cause parsing issues.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants