← All changes
|
vendor_prefixed/sentry/sentry/src/State/Scope.php
+30
-1
1.10.6
→
1.10.21
View file →
| @@ -2,11 +2,13 @@ | ||
| 2 | 2 | |
| 3 | 3 | declare (strict_types=1); |
| 4 | 4 | namespace WCPOS\Vendor\Sentry\State; |
| 5 | 5 | |
| 6 | +use WCPOS\Vendor\Sentry\Attachment\Attachment; | |
| 6 | 7 | use WCPOS\Vendor\Sentry\Breadcrumb; |
| 7 | 8 | use WCPOS\Vendor\Sentry\Event; |
| 8 | 9 | use WCPOS\Vendor\Sentry\EventHint; |
| 10 | +use WCPOS\Vendor\Sentry\EventType; | |
| 9 | 11 | use WCPOS\Vendor\Sentry\Options; |
| 10 | 12 | use WCPOS\Vendor\Sentry\Severity; |
| 11 | 13 | use WCPOS\Vendor\Sentry\Tracing\DynamicSamplingContext; |
| 12 | 14 | use WCPOS\Vendor\Sentry\Tracing\PropagationContext; |
| @@ -73,8 +75,12 @@ | ||
| 73 | 75 | * @var Span|null Set a Span on the Scope |
| 74 | 76 | */ |
| 75 | 77 | private $span; |
| 76 | 78 | /** |
| 79 | + * @var Attachment[] | |
| 80 | + */ | |
| 81 | + private $attachments = []; | |
| 82 | + /** | |
| 77 | 83 | * @var callable[] List of event processors |
| 78 | 84 | * |
| 79 | 85 | * @phpstan-var array<callable(Event, EventHint): ?Event> |
| 80 | 86 | */ |
| @@ -369,8 +375,9 @@ | ||
| 369 | 375 | $this->tags = []; |
| 370 | 376 | $this->flags = []; |
| 371 | 377 | $this->extra = []; |
| 372 | 378 | $this->contexts = []; |
| 379 | + $this->attachments = []; | |
| 373 | 380 | return $this; |
| 374 | 381 | } |
| 375 | 382 | /** |
| 376 | 383 | * Applies the current context and fingerprint to the event. If the event has |
| @@ -440,10 +447,22 @@ | ||
| 440 | 447 | // We create a empty `EventHint` instance to allow processors to always receive a `EventHint` instance even if there wasn't one |
| 441 | 448 | if ($hint === null) { |
| 442 | 449 | $hint = new EventHint(); |
| 443 | 450 | } |
| 451 | + if ($event->getType() === EventType::event() || $event->getType() === EventType::transaction()) { | |
| 452 | + if (empty($event->getAttachments())) { | |
| 453 | + $event->setAttachments($this->attachments); | |
| 454 | + } | |
| 455 | + } | |
| 444 | 456 | foreach (\array_merge(self::$globalEventProcessors, $this->eventProcessors) as $processor) { |
| 445 | - $event = $processor($event, $hint); | |
| 457 | + try { | |
| 458 | + $event = $processor($event, $hint); | |
| 459 | + } catch (\Throwable $exception) { | |
| 460 | + if ($options !== null) { | |
| 461 | + $options->getLoggerOrNullLogger()->error(\sprintf('The event processor failed with exception: "%s".', $exception->getMessage())); | |
| 462 | + } | |
| 463 | + return null; | |
| 464 | + } | |
| 446 | 465 | if ($event === null) { |
| 447 | 466 | return null; |
| 448 | 467 | } |
| 449 | 468 | if (!$event instanceof Event) { |
| @@ -521,6 +540,16 @@ | ||
| 521 | 540 | } |
| 522 | 541 | if ($this->propagationContext !== null) { |
| 523 | 542 | $this->propagationContext = clone $this->propagationContext; |
| 524 | 543 | } |
| 544 | + } | |
| 545 | + public function addAttachment(Attachment $attachment) : self | |
| 546 | + { | |
| 547 | + $this->attachments[] = $attachment; | |
| 548 | + return $this; | |
| 549 | + } | |
| 550 | + public function clearAttachments() : self | |
| 551 | + { | |
| 552 | + $this->attachments = []; | |
| 553 | + return $this; | |
| 525 | 554 | } |
| 526 | 555 | } |