PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.14
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.14
1.10.25 1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 All 169 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / Event.php

Event.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.14, at vendor_prefixed/sentry/sentry/src/Event.php

850 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\Sentry;
5
6 use WCPOS\Vendor\Sentry\ClientReport\DiscardedEvent;
7 use WCPOS\Vendor\Sentry\Context\OsContext;
8 use WCPOS\Vendor\Sentry\Context\RuntimeContext;
9 use WCPOS\Vendor\Sentry\Logs\Log;
10 use WCPOS\Vendor\Sentry\Metrics\Types\Metric;
11 use WCPOS\Vendor\Sentry\Profiling\Profile;
12 use WCPOS\Vendor\Sentry\Tracing\Span;
13 /**
14 * This is the base class for classes containing event data.
15 *
16 * @phpstan-type MetricsSummary array{
17 * min: int|float,
18 * max: int|float,
19 * sum: int|float,
20 * count: int,
21 * tags: array<string>,
22 * }
23 * @phpstan-type SdkPackageEntry array{
24 * name: string,
25 * version: string,
26 * }
27 */
28 final class Event
29 {
30 public const DEFAULT_ENVIRONMENT = 'production';
31 /**
32 * @var EventId The ID
33 */
34 private $id;
35 /**
36 * @var float|null The date and time of when this event was generated
37 */
38 private $timestamp;
39 /**
40 * This property is used if it's a Transaction event together with $timestamp it's the duration of the transaction.
41 *
42 * @var float|null The date and time of when this event was generated
43 */
44 private $startTimestamp;
45 /**
46 * @var Severity|null The severity of this event
47 */
48 private $level;
49 /**
50 * @var string|null The name of the logger which created the record
51 */
52 private $logger;
53 /**
54 * @var string|null the name of the transaction (or culprit) which caused this exception
55 */
56 private $transaction;
57 /**
58 * @var CheckIn|null The check in data
59 */
60 private $checkIn;
61 /**
62 * @var Log[]
63 */
64 private $logs = [];
65 /**
66 * @var Metric[]
67 */
68 private $metrics = [];
69 /**
70 * @var string|null The name of the server (e.g. the host name)
71 */
72 private $serverName;
73 /**
74 * @var string|null The release of the program
75 */
76 private $release;
77 /**
78 * @var string|null The error message
79 */
80 private $message;
81 /**
82 * @var string|null The formatted error message
83 */
84 private $messageFormatted;
85 /**
86 * @var string[] The parameters to use to format the message
87 */
88 private $messageParams = [];
89 /**
90 * @var string|null The environment where this event generated (e.g. production)
91 */
92 private $environment;
93 /**
94 * @var array<string, string> A list of relevant modules and their versions
95 */
96 private $modules = [];
97 /**
98 * @var array<string, mixed> The request data
99 */
100 private $request = [];
101 /**
102 * @var array<string, string> A list of tags associated to this event
103 */
104 private $tags = [];
105 /**
106 * @var OsContext|null The server OS context data
107 */
108 private $osContext;
109 /**
110 * @var RuntimeContext|null The runtime context data
111 */
112 private $runtimeContext;
113 /**
114 * @var UserDataBag|null The user context data
115 */
116 private $user;
117 /**
118 * @var array<string, array<string, mixed>> An arbitrary mapping of additional contexts associated to this event
119 */
120 private $contexts = [];
121 /**
122 * @var array<string, mixed> An arbitrary mapping of additional metadata
123 */
124 private $extra = [];
125 /**
126 * @var string[] An array of strings used to dictate the deduplication of this event
127 */
128 private $fingerprint = [];
129 /**
130 * @var Breadcrumb[] The associated breadcrumbs
131 */
132 private $breadcrumbs = [];
133 /**
134 * @var Span[] The array of spans if it's a transaction
135 */
136 private $spans = [];
137 /**
138 * @var ExceptionDataBag[] The exceptions
139 */
140 private $exceptions = [];
141 /**
142 * @var Stacktrace|null The stacktrace that generated this event
143 */
144 private $stacktrace;
145 /**
146 * A place to stash data which is needed at some point in the SDK's
147 * event processing pipeline but which shouldn't get sent to Sentry.
148 *
149 * @var array<string, mixed>
150 */
151 private $sdkMetadata = [];
152 /**
153 * @var string The Sentry SDK identifier
154 */
155 private $sdkIdentifier = Client::SDK_IDENTIFIER;
156 /**
157 * @var string The Sentry SDK version
158 */
159 private $sdkVersion = Client::SDK_VERSION;
160 /**
161 * @var SdkPackageEntry[] The Sentry SDK packages
162 */
163 private $sdkPackages = [['name' => 'composer:sentry/sentry', 'version' => Client::SDK_VERSION]];
164 /**
165 * @var EventType The type of the Event
166 */
167 private $type;
168 /**
169 * @var Profile|null The profile data
170 */
171 private $profile;
172 /**
173 * @var DiscardedEvent[]
174 */
175 private $clientReports = [];
176 private function __construct(?EventId $eventId, EventType $eventType)
177 {
178 $this->id = $eventId ?? EventId::generate();
179 $this->timestamp = \microtime(\true);
180 $this->type = $eventType;
181 }
182 /**
183 * Creates a new event.
184 *
185 * @param EventId|null $eventId The ID of the event
186 */
187 public static function createEvent(?EventId $eventId = null) : self
188 {
189 return new self($eventId, EventType::event());
190 }
191 /**
192 * Creates a new transaction event.
193 *
194 * @param EventId|null $eventId The ID of the event
195 */
196 public static function createTransaction(?EventId $eventId = null) : self
197 {
198 return new self($eventId, EventType::transaction());
199 }
200 public static function createCheckIn(?EventId $eventId = null) : self
201 {
202 return new self($eventId, EventType::checkIn());
203 }
204 public static function createLogs(?EventId $eventId = null) : self
205 {
206 return new self($eventId, EventType::logs());
207 }
208 public static function createMetrics(?EventId $eventId = null) : self
209 {
210 return new self($eventId, EventType::metrics());
211 }
212 public static function createClientReport(?EventId $eventId = null) : self
213 {
214 return new self($eventId, EventType::clientReport());
215 }
216 /**
217 * Gets the ID of this event.
218 */
219 public function getId() : EventId
220 {
221 return $this->id;
222 }
223 /**
224 * Gets the identifier of the SDK package that generated this event.
225 *
226 * @internal
227 */
228 public function getSdkIdentifier() : string
229 {
230 return $this->sdkIdentifier;
231 }
232 /**
233 * Sets the identifier of the SDK package that generated this event.
234 *
235 * @internal
236 */
237 public function setSdkIdentifier(string $sdkIdentifier) : self
238 {
239 $this->sdkIdentifier = $sdkIdentifier;
240 return $this;
241 }
242 /**
243 * Gets the version of the SDK package that generated this Event.
244 *
245 * @internal
246 */
247 public function getSdkVersion() : string
248 {
249 return $this->sdkVersion;
250 }
251 /**
252 * Sets the version of the SDK package that generated this Event.
253 *
254 * @internal
255 */
256 public function setSdkVersion(string $sdkVersion) : self
257 {
258 $this->sdkVersion = $sdkVersion;
259 return $this;
260 }
261 /**
262 * Append a package to the list of SDK packages.
263 *
264 * @param SdkPackageEntry $package The package to append
265 *
266 * @return $this
267 *
268 * @internal
269 */
270 public function appendSdkPackage(array $package) : self
271 {
272 $this->sdkPackages[] = $package;
273 return $this;
274 }
275 /**
276 * Gets the SDK playload that will be sent to Sentry.
277 *
278 * @see https://develop.sentry.dev/sdk/data-model/event-payloads/sdk/
279 *
280 * @return array{name: string, version: string, packages: SdkPackageEntry[]}
281 *
282 * @internal
283 */
284 public function getSdkPayload() : array
285 {
286 return ['name' => $this->sdkIdentifier, 'version' => $this->sdkVersion, 'packages' => $this->sdkPackages];
287 }
288 /**
289 * Gets the timestamp of when this event was generated.
290 */
291 public function getTimestamp() : ?float
292 {
293 return $this->timestamp;
294 }
295 /**
296 * Sets the timestamp of when the Event was created.
297 */
298 public function setTimestamp(?float $timestamp) : self
299 {
300 $this->timestamp = $timestamp;
301 return $this;
302 }
303 /**
304 * Gets the severity of this event.
305 */
306 public function getLevel() : ?Severity
307 {
308 return $this->level;
309 }
310 /**
311 * Sets the severity of this event.
312 *
313 * @param Severity|null $level The severity
314 */
315 public function setLevel(?Severity $level) : self
316 {
317 $this->level = $level;
318 return $this;
319 }
320 /**
321 * Gets the name of the logger which created the event.
322 */
323 public function getLogger() : ?string
324 {
325 return $this->logger;
326 }
327 /**
328 * Sets the name of the logger which created the event.
329 *
330 * @param string|null $logger The logger name
331 */
332 public function setLogger(?string $logger) : self
333 {
334 $this->logger = $logger;
335 return $this;
336 }
337 /**
338 * Gets the name of the transaction (or culprit) which caused this
339 * exception.
340 */
341 public function getTransaction() : ?string
342 {
343 return $this->transaction;
344 }
345 /**
346 * Sets the name of the transaction (or culprit) which caused this
347 * exception.
348 *
349 * @param string|null $transaction The transaction name
350 */
351 public function setTransaction(?string $transaction) : self
352 {
353 $this->transaction = $transaction;
354 return $this;
355 }
356 public function getCheckIn() : ?CheckIn
357 {
358 return $this->checkIn;
359 }
360 public function setCheckIn(?CheckIn $checkIn) : self
361 {
362 $this->checkIn = $checkIn;
363 return $this;
364 }
365 /**
366 * @return Log[]
367 */
368 public function getLogs() : array
369 {
370 return $this->logs;
371 }
372 /**
373 * @param Log[] $logs
374 */
375 public function setLogs(array $logs) : self
376 {
377 $this->logs = $logs;
378 return $this;
379 }
380 /**
381 * @return Metric[]
382 */
383 public function getMetrics() : array
384 {
385 return $this->metrics;
386 }
387 /**
388 * @param Metric[] $metrics
389 */
390 public function setMetrics(array $metrics) : self
391 {
392 $this->metrics = $metrics;
393 return $this;
394 }
395 /**
396 * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
397 */
398 public function getMetricsSummary() : array
399 {
400 return [];
401 }
402 /**
403 * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
404 */
405 public function setMetricsSummary(array $metricsSummary) : self
406 {
407 return $this;
408 }
409 /**
410 * Gets the name of the server.
411 */
412 public function getServerName() : ?string
413 {
414 return $this->serverName;
415 }
416 /**
417 * Sets the name of the server.
418 *
419 * @param string|null $serverName The server name
420 */
421 public function setServerName(?string $serverName) : self
422 {
423 $this->serverName = $serverName;
424 return $this;
425 }
426 /**
427 * Gets the release of the program.
428 */
429 public function getRelease() : ?string
430 {
431 return $this->release;
432 }
433 /**
434 * Sets the release of the program.
435 *
436 * @param string|null $release The release
437 */
438 public function setRelease(?string $release) : self
439 {
440 $this->release = $release;
441 return $this;
442 }
443 /**
444 * Gets the error message.
445 */
446 public function getMessage() : ?string
447 {
448 return $this->message;
449 }
450 /**
451 * Gets the formatted message.
452 */
453 public function getMessageFormatted() : ?string
454 {
455 return $this->messageFormatted;
456 }
457 /**
458 * Gets the parameters to use to format the message.
459 *
460 * @return string[]
461 */
462 public function getMessageParams() : array
463 {
464 return $this->messageParams;
465 }
466 /**
467 * Sets the error message.
468 *
469 * @param string $message The message
470 * @param string[] $params The parameters to use to format the message
471 * @param string|null $formatted The formatted message
472 */
473 public function setMessage(string $message, array $params = [], ?string $formatted = null) : self
474 {
475 $this->message = $message;
476 $this->messageParams = $params;
477 $this->messageFormatted = $formatted;
478 return $this;
479 }
480 /**
481 * Gets a list of relevant modules and their versions.
482 *
483 * @return array<string, string>
484 */
485 public function getModules() : array
486 {
487 return $this->modules;
488 }
489 /**
490 * Sets a list of relevant modules and their versions.
491 *
492 * @param array<string, string> $modules
493 */
494 public function setModules(array $modules) : self
495 {
496 $this->modules = $modules;
497 return $this;
498 }
499 /**
500 * Gets the request data.
501 *
502 * @return array<string, mixed>
503 */
504 public function getRequest() : array
505 {
506 return $this->request;
507 }
508 /**
509 * Sets the request data.
510 *
511 * @param array<string, mixed> $request The request data
512 */
513 public function setRequest(array $request) : self
514 {
515 $this->request = $request;
516 return $this;
517 }
518 /**
519 * Gets an arbitrary mapping of additional contexts.
520 *
521 * @return array<string, array<string, mixed>>
522 */
523 public function getContexts() : array
524 {
525 return $this->contexts;
526 }
527 /**
528 * Sets data to the context by a given name.
529 *
530 * @param string $name The name that uniquely identifies the context
531 * @param array<string, mixed> $data The data of the context
532 */
533 public function setContext(string $name, array $data) : self
534 {
535 if (!empty($data)) {
536 $this->contexts[$name] = $data;
537 }
538 return $this;
539 }
540 /**
541 * Gets an arbitrary mapping of additional metadata.
542 *
543 * @return array<string, mixed>
544 */
545 public function getExtra() : array
546 {
547 return $this->extra;
548 }
549 /**
550 * Sets an arbitrary mapping of additional metadata.
551 *
552 * @param array<string, mixed> $extra The context object
553 */
554 public function setExtra(array $extra) : self
555 {
556 $this->extra = $extra;
557 return $this;
558 }
559 /**
560 * Gets a list of tags associated to this event.
561 *
562 * @return array<string, string>
563 */
564 public function getTags() : array
565 {
566 return $this->tags;
567 }
568 /**
569 * Sets a list of tags associated to this event.
570 *
571 * @param array<string, string> $tags The tags to set
572 */
573 public function setTags(array $tags) : self
574 {
575 $this->tags = $tags;
576 return $this;
577 }
578 /**
579 * Sets or updates a tag in this event.
580 *
581 * @param string $key The key that uniquely identifies the tag
582 * @param string $value The value
583 */
584 public function setTag(string $key, string $value) : self
585 {
586 $this->tags[$key] = $value;
587 return $this;
588 }
589 /**
590 * Removes a given tag from the event.
591 *
592 * @param string $key The key that uniquely identifies the tag
593 */
594 public function removeTag(string $key) : self
595 {
596 unset($this->tags[$key]);
597 return $this;
598 }
599 /**
600 * Gets the user context.
601 */
602 public function getUser() : ?UserDataBag
603 {
604 return $this->user;
605 }
606 /**
607 * Sets the user context.
608 *
609 * @param UserDataBag|null $user The context object
610 */
611 public function setUser(?UserDataBag $user) : self
612 {
613 $this->user = $user;
614 return $this;
615 }
616 /**
617 * Gets the server OS context.
618 */
619 public function getOsContext() : ?OsContext
620 {
621 return $this->osContext;
622 }
623 /**
624 * Sets the server OS context.
625 *
626 * @param OsContext|null $osContext The context object
627 */
628 public function setOsContext(?OsContext $osContext) : self
629 {
630 $this->osContext = $osContext;
631 return $this;
632 }
633 /**
634 * Gets the runtime context data.
635 */
636 public function getRuntimeContext() : ?RuntimeContext
637 {
638 return $this->runtimeContext;
639 }
640 /**
641 * Sets the runtime context data.
642 *
643 * @param RuntimeContext|null $runtimeContext The context object
644 */
645 public function setRuntimeContext(?RuntimeContext $runtimeContext) : self
646 {
647 $this->runtimeContext = $runtimeContext;
648 return $this;
649 }
650 /**
651 * Gets an array of strings used to dictate the deduplication of this
652 * event.
653 *
654 * @return string[]
655 */
656 public function getFingerprint() : array
657 {
658 return $this->fingerprint;
659 }
660 /**
661 * Sets an array of strings used to dictate the deduplication of this
662 * event.
663 *
664 * @param string[] $fingerprint The strings
665 */
666 public function setFingerprint(array $fingerprint) : self
667 {
668 $this->fingerprint = $fingerprint;
669 return $this;
670 }
671 /**
672 * Gets the environment in which this event was generated.
673 */
674 public function getEnvironment() : ?string
675 {
676 return $this->environment;
677 }
678 /**
679 * Sets the environment in which this event was generated.
680 *
681 * @param string|null $environment The name of the environment
682 */
683 public function setEnvironment(?string $environment) : self
684 {
685 $this->environment = $environment;
686 return $this;
687 }
688 /**
689 * Gets the breadcrumbs.
690 *
691 * @return Breadcrumb[]
692 */
693 public function getBreadcrumbs() : array
694 {
695 return $this->breadcrumbs;
696 }
697 /**
698 * Set new breadcrumbs to the event.
699 *
700 * @param Breadcrumb[] $breadcrumbs The breadcrumb array
701 */
702 public function setBreadcrumb(array $breadcrumbs) : self
703 {
704 $this->breadcrumbs = $breadcrumbs;
705 return $this;
706 }
707 /**
708 * Gets the exception.
709 *
710 * @return ExceptionDataBag[]
711 */
712 public function getExceptions() : array
713 {
714 return $this->exceptions;
715 }
716 /**
717 * Sets the exceptions.
718 *
719 * @param ExceptionDataBag[] $exceptions The exceptions
720 */
721 public function setExceptions(array $exceptions) : self
722 {
723 foreach ($exceptions as $exception) {
724 if (!$exception instanceof ExceptionDataBag) {
725 throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, \get_debug_type($exception)));
726 }
727 }
728 $this->exceptions = $exceptions;
729 return $this;
730 }
731 /**
732 * Gets the stacktrace that generated this event.
733 */
734 public function getStacktrace() : ?Stacktrace
735 {
736 return $this->stacktrace;
737 }
738 /**
739 * Sets the stacktrace that generated this event.
740 *
741 * @param Stacktrace|null $stacktrace The stacktrace instance
742 */
743 public function setStacktrace(?Stacktrace $stacktrace) : self
744 {
745 $this->stacktrace = $stacktrace;
746 return $this;
747 }
748 public function getType() : EventType
749 {
750 return $this->type;
751 }
752 /**
753 * Sets the SDK metadata with the given name.
754 *
755 * @param string $name The name that uniquely identifies the SDK metadata
756 * @param mixed $data The data of the SDK metadata
757 */
758 public function setSdkMetadata(string $name, $data) : self
759 {
760 $this->sdkMetadata[$name] = $data;
761 return $this;
762 }
763 /**
764 * Gets the SDK metadata.
765 *
766 * @phpstan-template T of string|null
767 *
768 * @phpstan-param T $name
769 *
770 * @return mixed
771 *
772 * @phpstan-return (T is string ? mixed : array<string, mixed>|null)
773 */
774 public function getSdkMetadata(?string $name = null)
775 {
776 if ($name !== null) {
777 return $this->sdkMetadata[$name] ?? null;
778 }
779 return $this->sdkMetadata;
780 }
781 /**
782 * Gets a timestamp representing when the measuring of a transaction started.
783 */
784 public function getStartTimestamp() : ?float
785 {
786 return $this->startTimestamp;
787 }
788 /**
789 * Sets a timestamp representing when the measuring of a transaction started.
790 *
791 * @param float|null $startTimestamp The start time of the measurement
792 */
793 public function setStartTimestamp(?float $startTimestamp) : self
794 {
795 $this->startTimestamp = $startTimestamp;
796 return $this;
797 }
798 /**
799 * A list of timed application events that have a start and end time.
800 *
801 * @return Span[]
802 */
803 public function getSpans() : array
804 {
805 return $this->spans;
806 }
807 /**
808 * Sets a list of timed application events that have a start and end time.
809 *
810 * @param Span[] $spans The list of spans
811 */
812 public function setSpans(array $spans) : self
813 {
814 $this->spans = $spans;
815 return $this;
816 }
817 public function getProfile() : ?Profile
818 {
819 return $this->profile;
820 }
821 public function setProfile(?Profile $profile) : self
822 {
823 $this->profile = $profile;
824 return $this;
825 }
826 public function getTraceId() : ?string
827 {
828 $traceId = $this->getContexts()['trace']['trace_id'];
829 if (\is_string($traceId) && !empty($traceId)) {
830 return $traceId;
831 }
832 return null;
833 }
834 /**
835 * @param DiscardedEvent[] $clientReports
836 */
837 public function setClientReports(array $clientReports) : self
838 {
839 $this->clientReports = $clientReports;
840 return $this;
841 }
842 /**
843 * @return DiscardedEvent[]
844 */
845 public function getClientReports() : array
846 {
847 return $this->clientReports;
848 }
849 }
850