PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
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 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / Tracing / TransactionContext.php

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

149 lines 4.6 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\Tracing;
5
6 use WCPOS\Vendor\Sentry\Tracing\Traits\TraceHeaderParserTrait;
7 final class TransactionContext extends SpanContext
8 {
9 use TraceHeaderParserTrait;
10 public const DEFAULT_NAME = '<unlabeled transaction>';
11 /**
12 * @var string Name of the transaction
13 */
14 private $name;
15 /**
16 * @var bool|null The parent's sampling decision
17 */
18 private $parentSampled;
19 /**
20 * @var TransactionMetadata The transaction metadata
21 */
22 private $metadata;
23 /**
24 * Constructor.
25 *
26 * @param string $name The name of the transaction
27 * @param bool|null $parentSampled The parent's sampling decision
28 * @param TransactionMetadata|null $metadata The transaction metadata
29 */
30 public function __construct(string $name = self::DEFAULT_NAME, ?bool $parentSampled = null, ?TransactionMetadata $metadata = null)
31 {
32 $this->name = $name;
33 $this->parentSampled = $parentSampled;
34 $this->metadata = $metadata ?? new TransactionMetadata();
35 }
36 /**
37 * @return self
38 */
39 public static function make()
40 {
41 return new self();
42 }
43 /**
44 * Gets the name of the transaction.
45 */
46 public function getName() : string
47 {
48 return $this->name;
49 }
50 /**
51 * Sets the name of the transaction.
52 *
53 * @param string $name The name
54 */
55 public function setName(string $name) : self
56 {
57 $this->name = $name;
58 return $this;
59 }
60 /**
61 * Gets the parent's sampling decision.
62 */
63 public function getParentSampled() : ?bool
64 {
65 return $this->parentSampled;
66 }
67 /**
68 * Sets the parent's sampling decision.
69 *
70 * @param bool|null $parentSampled The decision
71 */
72 public function setParentSampled(?bool $parentSampled) : self
73 {
74 $this->parentSampled = $parentSampled;
75 return $this;
76 }
77 /**
78 * Gets the transaction metadata.
79 */
80 public function getMetadata() : TransactionMetadata
81 {
82 return $this->metadata;
83 }
84 /**
85 * Sets the transaction metadata.
86 *
87 * @param TransactionMetadata $metadata The transaction metadata
88 */
89 public function setMetadata(TransactionMetadata $metadata) : self
90 {
91 $this->metadata = $metadata;
92 return $this;
93 }
94 /**
95 * Sets the transaction source.
96 *
97 * @param TransactionSource $transactionSource The transaction source
98 */
99 public function setSource(TransactionSource $transactionSource) : self
100 {
101 $this->metadata->setSource($transactionSource);
102 return $this;
103 }
104 /**
105 * Returns a context populated with the data of the given environment variables.
106 *
107 * @param string $sentryTrace The sentry-trace value from the environment
108 * @param string $baggage The baggage header value from the environment
109 */
110 public static function fromEnvironment(string $sentryTrace, string $baggage) : self
111 {
112 return self::parseTraceAndBaggage($sentryTrace, $baggage);
113 }
114 /**
115 * Returns a context populated with the data of the given headers.
116 *
117 * @param string $sentryTraceHeader The sentry-trace header from an incoming request
118 * @param string $baggageHeader The baggage header from an incoming request
119 */
120 public static function fromHeaders(string $sentryTraceHeader, string $baggageHeader) : self
121 {
122 return self::parseTraceAndBaggage($sentryTraceHeader, $baggageHeader);
123 }
124 private static function parseTraceAndBaggage(string $sentryTrace, string $baggage) : self
125 {
126 $context = new self();
127 $parsedData = self::parseTraceAndBaggageHeaders($sentryTrace, $baggage);
128 if ($parsedData['traceId'] !== null) {
129 $context->traceId = $parsedData['traceId'];
130 }
131 if ($parsedData['parentSpanId'] !== null) {
132 $context->parentSpanId = $parsedData['parentSpanId'];
133 }
134 if ($parsedData['parentSampled'] !== null) {
135 $context->parentSampled = $parsedData['parentSampled'];
136 }
137 if ($parsedData['dynamicSamplingContext'] !== null) {
138 $context->getMetadata()->setDynamicSamplingContext($parsedData['dynamicSamplingContext']);
139 }
140 if ($parsedData['parentSamplingRate'] !== null) {
141 $context->getMetadata()->setParentSamplingRate($parsedData['parentSamplingRate']);
142 }
143 if ($parsedData['sampleRand'] !== null) {
144 $context->getMetadata()->setSampleRand($parsedData['sampleRand']);
145 }
146 return $context;
147 }
148 }
149