From 69803b7c5350e3d57e531073cb0b6c057e7a47fa Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Thu, 25 Sep 2025 13:27:55 +0200 Subject: [PATCH 1/4] feat: add attachment support --- src/Attachment/Attachment.php | 75 +++++++++++++++++++ src/Attachment/ByteAttachment.php | 30 ++++++++ src/Attachment/FileAttachment.php | 31 ++++++++ src/Event.php | 27 +++++++ src/EventType.php | 6 ++ .../EnvelopItems/AttachmentItem.php | 67 +++++++++++++++++ .../EnvelopItems/EnvelopeItemInterface.php | 6 +- src/Serializer/PayloadSerializer.php | 13 ++++ src/State/Hub.php | 14 ++++ src/State/HubInterface.php | 3 + src/State/Scope.php | 25 +++++++ tests/Attachment/AttachmentTest.php | 53 +++++++++++++ tests/Serializer/PayloadSerializerTest.php | 49 ++++++++++++ tests/data/attachment.txt | 1 + 14 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 src/Attachment/Attachment.php create mode 100644 src/Attachment/ByteAttachment.php create mode 100644 src/Attachment/FileAttachment.php create mode 100644 src/Serializer/EnvelopItems/AttachmentItem.php create mode 100644 tests/Attachment/AttachmentTest.php create mode 100644 tests/data/attachment.txt diff --git a/src/Attachment/Attachment.php b/src/Attachment/Attachment.php new file mode 100644 index 000000000..9fdeea438 --- /dev/null +++ b/src/Attachment/Attachment.php @@ -0,0 +1,75 @@ +filename = $filename; + $this->contentType = $contentType; + } + + public function getFilename(): string + { + return $this->filename; + } + + public function getContentType(): string + { + return $this->contentType; + } + + /** + * Returns the size in bytes for the attachment. This method should aim to use a low overhead + * way of determining the size because it will be called more than once. + * For example, for file attachments it should read the file size from the filesystem instead of + * reading the file in memory and then calculating the length. + * If no low overhead way exists, then the result should be cached so that calling it multiple times + * does not decrease performance. + * + * @return int the size in bytes or null if the length could not be determined, for example if the file + * does not exist + */ + abstract public function getSize(): ?int; + + /** + * Fetches and returns the data. Calling this can have a non-trivial impact on memory usage, depending + * on the type and size of attachment. + * + * @return string the content as bytes or null if the content could not be retrieved, for example if the file + * does not exist + */ + abstract public function getData(): ?string; + + /** + * Creates a new attachment representing a file referenced by a path. + * The file is not validated and the content is not read when creating the attachment. + */ + public static function fromFile(string $path, string $contentType = self::DEFAULT_CONTENT_TYPE): Attachment + { + return new FileAttachment($path, $contentType); + } + + /** + * Creates a new attachment representing a slice of bytes that lives in memory. + */ + public static function fromBytes(string $filename, string $data, string $contentType = self::DEFAULT_CONTENT_TYPE): Attachment + { + return new ByteAttachment($filename, $contentType, $data); + } +} diff --git a/src/Attachment/ByteAttachment.php b/src/Attachment/ByteAttachment.php new file mode 100644 index 000000000..dbaa27b6a --- /dev/null +++ b/src/Attachment/ByteAttachment.php @@ -0,0 +1,30 @@ +data = $data; + } + + public function getSize(): ?int + { + return \strlen($this->data); + } + + public function getData(): ?string + { + return $this->data; + } +} diff --git a/src/Attachment/FileAttachment.php b/src/Attachment/FileAttachment.php new file mode 100644 index 000000000..da928520d --- /dev/null +++ b/src/Attachment/FileAttachment.php @@ -0,0 +1,31 @@ +path = $path; + } + + public function getSize(): ?int + { + return @filesize($this->path) ?: null; + } + + public function getData(): ?string + { + return @file_get_contents($this->path) ?: null; + } +} diff --git a/src/Event.php b/src/Event.php index 18189eb5e..f01c9a4e8 100644 --- a/src/Event.php +++ b/src/Event.php @@ -4,6 +4,7 @@ namespace Sentry; +use Sentry\Attachment\Attachment; use Sentry\Context\OsContext; use Sentry\Context\RuntimeContext; use Sentry\Logs\Log; @@ -204,6 +205,11 @@ final class Event */ private $profile; + /** + * @var Attachment[] + */ + private $attachments = []; + private function __construct(?EventId $eventId, EventType $eventType) { $this->id = $eventId ?? EventId::generate(); @@ -241,6 +247,11 @@ public static function createLogs(?EventId $eventId = null): self return new self($eventId, EventType::logs()); } + public static function createAttachments(?EventId $eventId = null): self + { + return new self($eventId, EventType::attachment()); + } + /** * Gets the ID of this event. */ @@ -933,4 +944,20 @@ public function getTraceId(): ?string return null; } + + /** + * @return Attachment[] + */ + public function getAttachments(): array + { + return $this->attachments; + } + + /** + * @param Attachment[] $attachments + */ + public function setAttachments(array $attachments): void + { + $this->attachments = $attachments; + } } diff --git a/src/EventType.php b/src/EventType.php index 79e4a4325..848e1577b 100644 --- a/src/EventType.php +++ b/src/EventType.php @@ -47,6 +47,11 @@ public static function logs(): self return self::getInstance('log'); } + public static function attachment(): self + { + return self::getInstance('attachment'); + } + /** * List of all cases on the enum. * @@ -59,6 +64,7 @@ public static function cases(): array self::transaction(), self::checkIn(), self::logs(), + self::attachment() ]; } diff --git a/src/Serializer/EnvelopItems/AttachmentItem.php b/src/Serializer/EnvelopItems/AttachmentItem.php new file mode 100644 index 000000000..eb998698b --- /dev/null +++ b/src/Serializer/EnvelopItems/AttachmentItem.php @@ -0,0 +1,67 @@ +getAttachments(); + + $items = []; + + foreach ($attachments as $attachment) { + $header = [ + 'filename' => $attachment->getFilename(), + 'content_type' => $attachment->getContentType(), + 'attachment_type' => 'event.attachment', + ]; + + $items[] = \sprintf("%s\n%s", JSON::encode($header), file_get_contents($attachment->getFilename())); + } + + return $items; + } + + public static function toAttachmentItem(Attachment $attachment): ?string + { + $data = $attachment->getData(); + if ($data === null) { + return null; + } + + $header = [ + 'type' => 'attachment', + 'filename' => $attachment->getFilename(), + 'content_type' => $attachment->getContentType(), + 'attachment_type' => 'event.attachment', + 'length' => $attachment->getSize(), + ]; + + return \sprintf("%s\n%s", JSON::encode($header), $data); + } + + /** + * Returns the total size of all attachments in bytes. + * + * @param Attachment[] $attachments + */ + public static function totalAttachmentSize(array $attachments): int + { + $sum = 0; + foreach ($attachments as $attachment) { + $sum += $attachment->getSize(); + } + + return $sum; + } +} diff --git a/src/Serializer/EnvelopItems/EnvelopeItemInterface.php b/src/Serializer/EnvelopItems/EnvelopeItemInterface.php index bf95f6e45..922708ab7 100644 --- a/src/Serializer/EnvelopItems/EnvelopeItemInterface.php +++ b/src/Serializer/EnvelopItems/EnvelopeItemInterface.php @@ -11,5 +11,9 @@ */ interface EnvelopeItemInterface { - public static function toEnvelopeItem(Event $event): ?string; + /** + * @param Event $event + * @return ?string|string[] + */ + public static function toEnvelopeItem(Event $event); } diff --git a/src/Serializer/PayloadSerializer.php b/src/Serializer/PayloadSerializer.php index 4878cc767..7e2ea56cc 100644 --- a/src/Serializer/PayloadSerializer.php +++ b/src/Serializer/PayloadSerializer.php @@ -7,6 +7,7 @@ use Sentry\Event; use Sentry\EventType; use Sentry\Options; +use Sentry\Serializer\EnvelopItems\AttachmentItem; use Sentry\Serializer\EnvelopItems\CheckInItem; use Sentry\Serializer\EnvelopItems\EventItem; use Sentry\Serializer\EnvelopItems\LogsItem; @@ -23,6 +24,11 @@ */ final class PayloadSerializer implements PayloadSerializerInterface { + /** + * Attachments have a limit of 100MB before compression. + */ + private const MAX_ATTACHMENT_SIZE = 100000000; + /** * @var Options The SDK client options */ @@ -75,6 +81,13 @@ public function serialize(Event $event): string break; } + // If attachments are exceeding the limit, then we drop all attachments + if (AttachmentItem::totalAttachmentSize($event->getAttachments()) <= self::MAX_ATTACHMENT_SIZE) { + foreach ($event->getAttachments() as $attachment) { + $items[] = AttachmentItem::toAttachmentItem($attachment); + } + } + return \sprintf("%s\n%s", JSON::encode($envelopeHeader), implode("\n", array_filter($items))); } } diff --git a/src/State/Hub.php b/src/State/Hub.php index eeaf7bb28..2ab9930e9 100644 --- a/src/State/Hub.php +++ b/src/State/Hub.php @@ -5,6 +5,7 @@ namespace Sentry\State; use Psr\Log\NullLogger; +use Sentry\Attachment\Attachment; use Sentry\Breadcrumb; use Sentry\CheckIn; use Sentry\CheckInStatus; @@ -231,6 +232,19 @@ public function addBreadcrumb(Breadcrumb $breadcrumb): bool return $breadcrumb !== null; } + public function addAttachment(Attachment $attachment): bool + { + $client = $this->getClient(); + + if ($client === null) { + return false; + } + + $this->getScope()->addAttachment($attachment); + + return true; + } + /** * {@inheritdoc} */ diff --git a/src/State/HubInterface.php b/src/State/HubInterface.php index 227a8451e..14931917b 100644 --- a/src/State/HubInterface.php +++ b/src/State/HubInterface.php @@ -4,6 +4,7 @@ namespace Sentry\State; +use Sentry\Attachment\Attachment; use Sentry\Breadcrumb; use Sentry\CheckInStatus; use Sentry\ClientInterface; @@ -152,4 +153,6 @@ public function getSpan(): ?Span; * Sets the span on the Hub. */ public function setSpan(?Span $span): HubInterface; + + public function addAttachment(Attachment $attachment): bool; } diff --git a/src/State/Scope.php b/src/State/Scope.php index e4e054c3c..7fab2fb2b 100644 --- a/src/State/Scope.php +++ b/src/State/Scope.php @@ -4,6 +4,7 @@ namespace Sentry\State; +use Sentry\Attachment\Attachment; use Sentry\Breadcrumb; use Sentry\Event; use Sentry\EventHint; @@ -75,6 +76,11 @@ class Scope */ private $span; + /** + * @var Attachment[] + */ + private $attachments = []; + /** * @var callable[] List of event processors * @@ -333,6 +339,7 @@ public function clear(): self $this->tags = []; $this->extra = []; $this->contexts = []; + $this->attachments = []; return $this; } @@ -411,6 +418,10 @@ public function applyToEvent(Event $event, ?EventHint $hint = null, ?Options $op $hint = new EventHint(); } + if (empty($event->getAttachments())) { + $event->setAttachments($this->attachments); + } + foreach (array_merge(self::$globalEventProcessors, $this->eventProcessors) as $processor) { $event = $processor($event, $hint); @@ -481,4 +492,18 @@ public function __clone() $this->propagationContext = clone $this->propagationContext; } } + + public function addAttachment(Attachment $attachment): self + { + $this->attachments[] = $attachment; + + return $this; + } + + public function clearAttachments(): self + { + $this->attachments = []; + + return $this; + } } diff --git a/tests/Attachment/AttachmentTest.php b/tests/Attachment/AttachmentTest.php new file mode 100644 index 000000000..b675d8850 --- /dev/null +++ b/tests/Attachment/AttachmentTest.php @@ -0,0 +1,53 @@ +assertEquals(25, $attachment->getSize()); + $this->assertEquals('This is a temp attachment', $attachment->getData()); + $this->assertStringStartsWith('attachment.txt', $attachment->getFilename()); + $this->assertEquals('application/octet-stream', $attachment->getContentType()); + } + + public function testEmptyFile(): void + { + $file = tempnam(sys_get_temp_dir(), 'attachment.txt'); + $attachment = Attachment::fromFile($file); + $this->assertEquals(0, $attachment->getSize()); + $this->assertEquals('', $attachment->getData()); + } + + public function testFileDoesNotExist(): void + { + $attachment = Attachment::fromFile('this/does/not/exist'); + $this->assertNull($attachment->getSize()); + $this->assertNull($attachment->getData()); + } + + public function testByteAttachment(): void + { + $attachment = Attachment::fromBytes('test', 'ExampleDataThatShouldNotBeAFile'); + $this->assertEquals(31, $attachment->getSize()); + $this->assertEquals('ExampleDataThatShouldNotBeAFile', $attachment->getData()); + $this->assertEquals('test', $attachment->getFilename()); + $this->assertEquals('application/octet-stream', $attachment->getContentType()); + } + + public function testEmptyBytes(): void + { + $attachment = Attachment::fromBytes('test', ''); + $this->assertEquals(0, $attachment->getSize()); + $this->assertEquals('', $attachment->getData()); + } +} diff --git a/tests/Serializer/PayloadSerializerTest.php b/tests/Serializer/PayloadSerializerTest.php index 3ae6a5777..35ad26ff0 100644 --- a/tests/Serializer/PayloadSerializerTest.php +++ b/tests/Serializer/PayloadSerializerTest.php @@ -5,6 +5,7 @@ namespace Sentry\Tests\Serializer; use PHPUnit\Framework\TestCase; +use Sentry\Attachment\Attachment; use Sentry\Breadcrumb; use Sentry\CheckIn; use Sentry\CheckInStatus; @@ -422,6 +423,54 @@ public static function serializeAsEnvelopeDataProvider(): iterable {"event_id":"fc9442f5aef34234bb22b9a615e30ccd","sent_at":"2020-08-18T22:47:15Z","dsn":"http:\/\/public@example.com\/sentry\/1","sdk":{"name":"sentry.php","version":"$sdkVersion","packages":[{"name":"composer:sentry\/sentry","version":"$sdkVersion"}]}} {"type":"log","item_count":1,"content_type":"application\/vnd.sentry.items.log+json"} {"items":[{"timestamp":1597790835,"trace_id":"21160e9b836d479f81611368b2aa3d2c","level":"info","body":"A log message","attributes":{"foo":{"type":"string","value":"bar"}}}]} +TEXT + , + ]; + + // Test in memory attachment + $event = Event::createAttachments(new EventId('fc9442f5aef34234bb22b9a615e30ccd')); + $event->setAttachments([ + Attachment::fromBytes('test.attachment', 'This is a test attachment stored in memory'), + ]); + + yield [ + $event, + <<setAttachments([ + Attachment::fromFile(realpath(__DIR__ . '/../data/attachment.txt')), + ]); + + yield [ + $event, + <<setAttachments([ + Attachment::fromFile('does not exist'), + ]); + + yield [ + $event, + << Date: Mon, 29 Sep 2025 16:35:23 +0200 Subject: [PATCH 2/4] remove attachment event type --- src/Attachment/ByteAttachment.php | 2 ++ src/Attachment/FileAttachment.php | 3 +- src/Event.php | 5 --- src/EventType.php | 2 +- .../EnvelopItems/AttachmentItem.php | 32 ++++++------------- .../EnvelopItems/EnvelopeItemInterface.php | 6 +--- src/Serializer/PayloadSerializer.php | 9 ++---- src/State/HubAdapter.php | 9 ++++++ src/State/HubInterface.php | 3 ++ src/State/Scope.php | 7 ++-- tests/Serializer/PayloadSerializerTest.php | 13 +++++--- tests/State/ScopeTest.php | 20 ++++++++++++ 12 files changed, 64 insertions(+), 47 deletions(-) diff --git a/src/Attachment/ByteAttachment.php b/src/Attachment/ByteAttachment.php index dbaa27b6a..35f8dc5a4 100644 --- a/src/Attachment/ByteAttachment.php +++ b/src/Attachment/ByteAttachment.php @@ -1,5 +1,7 @@ getAttachments(); - - $items = []; - - foreach ($attachments as $attachment) { - $header = [ - 'filename' => $attachment->getFilename(), - 'content_type' => $attachment->getContentType(), - 'attachment_type' => 'event.attachment', - ]; - - $items[] = \sprintf("%s\n%s", JSON::encode($header), file_get_contents($attachment->getFilename())); - } - - return $items; - } - public static function toAttachmentItem(Attachment $attachment): ?string { $data = $attachment->getData(); @@ -64,4 +42,14 @@ public static function totalAttachmentSize(array $attachments): int return $sum; } + + public static function toEnvelopeItem(Event $event): ?string + { + $result = []; + foreach ($event->getAttachments() as $attachment) { + $result[] = self::toAttachmentItem($attachment); + } + + return implode("\n", $result); + } } diff --git a/src/Serializer/EnvelopItems/EnvelopeItemInterface.php b/src/Serializer/EnvelopItems/EnvelopeItemInterface.php index 922708ab7..bf95f6e45 100644 --- a/src/Serializer/EnvelopItems/EnvelopeItemInterface.php +++ b/src/Serializer/EnvelopItems/EnvelopeItemInterface.php @@ -11,9 +11,5 @@ */ interface EnvelopeItemInterface { - /** - * @param Event $event - * @return ?string|string[] - */ - public static function toEnvelopeItem(Event $event); + public static function toEnvelopeItem(Event $event): ?string; } diff --git a/src/Serializer/PayloadSerializer.php b/src/Serializer/PayloadSerializer.php index 7e2ea56cc..c3ace64f3 100644 --- a/src/Serializer/PayloadSerializer.php +++ b/src/Serializer/PayloadSerializer.php @@ -66,12 +66,14 @@ public function serialize(Event $event): string switch ($event->getType()) { case EventType::event(): $items[] = EventItem::toEnvelopeItem($event); + $items[] = AttachmentItem::toEnvelopeItem($event); break; case EventType::transaction(): $items[] = TransactionItem::toEnvelopeItem($event); if ($event->getSdkMetadata('profile') !== null) { $items[] = ProfileItem::toEnvelopeItem($event); } + $items[] = AttachmentItem::toEnvelopeItem($event); break; case EventType::checkIn(): $items[] = CheckInItem::toEnvelopeItem($event); @@ -81,13 +83,6 @@ public function serialize(Event $event): string break; } - // If attachments are exceeding the limit, then we drop all attachments - if (AttachmentItem::totalAttachmentSize($event->getAttachments()) <= self::MAX_ATTACHMENT_SIZE) { - foreach ($event->getAttachments() as $attachment) { - $items[] = AttachmentItem::toAttachmentItem($attachment); - } - } - return \sprintf("%s\n%s", JSON::encode($envelopeHeader), implode("\n", array_filter($items))); } } diff --git a/src/State/HubAdapter.php b/src/State/HubAdapter.php index 503153860..1c10b4956 100644 --- a/src/State/HubAdapter.php +++ b/src/State/HubAdapter.php @@ -4,6 +4,7 @@ namespace Sentry\State; +use Sentry\Attachment\Attachment; use Sentry\Breadcrumb; use Sentry\CheckInStatus; use Sentry\ClientInterface; @@ -155,6 +156,14 @@ public function addBreadcrumb(Breadcrumb $breadcrumb): bool return SentrySdk::getCurrentHub()->addBreadcrumb($breadcrumb); } + /** + * {@inheritDoc} + */ + public function addAttachment(Attachment $attachment): bool + { + return SentrySdk::getCurrentHub()->addAttachment($attachment); + } + /** * {@inheritdoc} */ diff --git a/src/State/HubInterface.php b/src/State/HubInterface.php index 14931917b..27751564f 100644 --- a/src/State/HubInterface.php +++ b/src/State/HubInterface.php @@ -154,5 +154,8 @@ public function getSpan(): ?Span; */ public function setSpan(?Span $span): HubInterface; + /** + * Records a new attachment that will be attached to error and transaction events. + */ public function addAttachment(Attachment $attachment): bool; } diff --git a/src/State/Scope.php b/src/State/Scope.php index 7fab2fb2b..87706f446 100644 --- a/src/State/Scope.php +++ b/src/State/Scope.php @@ -8,6 +8,7 @@ use Sentry\Breadcrumb; use Sentry\Event; use Sentry\EventHint; +use Sentry\EventType; use Sentry\Options; use Sentry\Severity; use Sentry\Tracing\DynamicSamplingContext; @@ -418,8 +419,10 @@ public function applyToEvent(Event $event, ?EventHint $hint = null, ?Options $op $hint = new EventHint(); } - if (empty($event->getAttachments())) { - $event->setAttachments($this->attachments); + if ($event->getType() === EventType::event() || $event->getType() === EventType::transaction()) { + if (empty($event->getAttachments())) { + $event->setAttachments($this->attachments); + } } foreach (array_merge(self::$globalEventProcessors, $this->eventProcessors) as $processor) { diff --git a/tests/Serializer/PayloadSerializerTest.php b/tests/Serializer/PayloadSerializerTest.php index 35ad26ff0..963a46ce8 100644 --- a/tests/Serializer/PayloadSerializerTest.php +++ b/tests/Serializer/PayloadSerializerTest.php @@ -428,7 +428,7 @@ public static function serializeAsEnvelopeDataProvider(): iterable ]; // Test in memory attachment - $event = Event::createAttachments(new EventId('fc9442f5aef34234bb22b9a615e30ccd')); + $event = Event::createEvent(new EventId('fc9442f5aef34234bb22b9a615e30ccd')); $event->setAttachments([ Attachment::fromBytes('test.attachment', 'This is a test attachment stored in memory'), ]); @@ -437,6 +437,8 @@ public static function serializeAsEnvelopeDataProvider(): iterable $event, <<setAttachments([ Attachment::fromFile(realpath(__DIR__ . '/../data/attachment.txt')), ]); @@ -453,6 +455,8 @@ public static function serializeAsEnvelopeDataProvider(): iterable $event, <<setAttachments([ Attachment::fromFile('does not exist'), ]); @@ -470,7 +474,8 @@ public static function serializeAsEnvelopeDataProvider(): iterable $event, <<assertSame('foo', $dynamicSamplingContext->get('transaction')); $this->assertSame('566e3688a61d4bc888951642d6f14a19', $dynamicSamplingContext->get('trace_id')); } + + /** + * @dataProvider eventWithLogCountProvider + */ + public function testAttachmentsAppliedForType(Event $event, int $attachmentCount): void + { + $scope = new Scope(); + $scope->addAttachment(Attachment::fromBytes('test', 'abcde')); + $scope->applyToEvent($event); + $this->assertCount($attachmentCount, $event->getAttachments()); + } + + public function eventWithLogCountProvider(): \Generator + { + yield 'event' => [Event::createEvent(), 1]; + yield 'transaction' => [Event::createTransaction(), 1]; + yield 'check-in' => [Event::createCheckIn(), 0]; + yield 'logs' => [Event::createLogs(), 0]; + } } From 276d203ca0d0d338e574b5c1efa5080c5acb3f40 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Mon, 29 Sep 2025 16:37:55 +0200 Subject: [PATCH 3/4] remove attachment event type --- src/EventType.php | 6 ------ src/Serializer/EnvelopItems/AttachmentItem.php | 15 --------------- src/Serializer/PayloadSerializer.php | 5 ----- 3 files changed, 26 deletions(-) diff --git a/src/EventType.php b/src/EventType.php index a59316726..79e4a4325 100644 --- a/src/EventType.php +++ b/src/EventType.php @@ -47,11 +47,6 @@ public static function logs(): self return self::getInstance('log'); } - public static function attachment(): self - { - return self::getInstance('attachment'); - } - /** * List of all cases on the enum. * @@ -64,7 +59,6 @@ public static function cases(): array self::transaction(), self::checkIn(), self::logs(), - self::attachment(), ]; } diff --git a/src/Serializer/EnvelopItems/AttachmentItem.php b/src/Serializer/EnvelopItems/AttachmentItem.php index 429fd38c6..14ddf5a42 100644 --- a/src/Serializer/EnvelopItems/AttachmentItem.php +++ b/src/Serializer/EnvelopItems/AttachmentItem.php @@ -28,21 +28,6 @@ public static function toAttachmentItem(Attachment $attachment): ?string return \sprintf("%s\n%s", JSON::encode($header), $data); } - /** - * Returns the total size of all attachments in bytes. - * - * @param Attachment[] $attachments - */ - public static function totalAttachmentSize(array $attachments): int - { - $sum = 0; - foreach ($attachments as $attachment) { - $sum += $attachment->getSize(); - } - - return $sum; - } - public static function toEnvelopeItem(Event $event): ?string { $result = []; diff --git a/src/Serializer/PayloadSerializer.php b/src/Serializer/PayloadSerializer.php index c3ace64f3..78b5a335d 100644 --- a/src/Serializer/PayloadSerializer.php +++ b/src/Serializer/PayloadSerializer.php @@ -24,11 +24,6 @@ */ final class PayloadSerializer implements PayloadSerializerInterface { - /** - * Attachments have a limit of 100MB before compression. - */ - private const MAX_ATTACHMENT_SIZE = 100000000; - /** * @var Options The SDK client options */ From 863394472a92fc7435b710ae7c46a298fb94749c Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Mon, 29 Sep 2025 16:51:59 +0200 Subject: [PATCH 4/4] fix tests in windows --- tests/Attachment/AttachmentTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Attachment/AttachmentTest.php b/tests/Attachment/AttachmentTest.php index b675d8850..074d96bd3 100644 --- a/tests/Attachment/AttachmentTest.php +++ b/tests/Attachment/AttachmentTest.php @@ -11,12 +11,13 @@ class AttachmentTest extends TestCase { public function testFileAttachment(): void { - $file = tempnam(sys_get_temp_dir(), 'attachment.txt'); + // We use 3 char prefix because windows supports only 3 + $file = tempnam(sys_get_temp_dir(), 'att'); file_put_contents($file, 'This is a temp attachment'); $attachment = Attachment::fromFile($file); $this->assertEquals(25, $attachment->getSize()); $this->assertEquals('This is a temp attachment', $attachment->getData()); - $this->assertStringStartsWith('attachment.txt', $attachment->getFilename()); + $this->assertStringStartsWith('att', $attachment->getFilename()); $this->assertEquals('application/octet-stream', $attachment->getContentType()); }