1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Standard context carrier |
4
|
|
|
* User: moyo |
5
|
|
|
* Date: 27/12/2017 |
6
|
|
|
* Time: 11:39 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Carno\Tracing\Standard\Carriers; |
10
|
|
|
|
11
|
|
|
use Carno\Tracing\Chips\StandardCC; |
12
|
|
|
use Carno\Tracing\Chips\UnsupportedHTTP; |
13
|
|
|
use Carno\Tracing\Contracts\Carrier; |
14
|
|
|
use Carno\Tracing\Contracts\Vars\CTX; |
15
|
|
|
use Carno\Tracing\Standard\Context as OpenContext; |
16
|
|
|
|
17
|
|
|
class Context implements Carrier |
18
|
|
|
{ |
19
|
|
|
use StandardCC, UnsupportedHTTP; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var OpenContext |
23
|
|
|
*/ |
24
|
|
|
private $ctx = null; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Context constructor. |
28
|
|
|
* @param OpenContext $context |
29
|
|
|
*/ |
30
|
|
|
public function __construct(OpenContext $context) |
31
|
|
|
{ |
32
|
|
|
$this->ctx = $context; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return string|int |
37
|
|
|
*/ |
38
|
|
|
public function getTraceID() |
39
|
|
|
{ |
40
|
|
|
return $this->ctx[CTX::TRACE_ID] ?? ''; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string|int |
45
|
|
|
*/ |
46
|
|
|
public function getSpanID() |
47
|
|
|
{ |
48
|
|
|
return $this->ctx[CTX::SPAN_ID] ?? ''; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string|int |
53
|
|
|
*/ |
54
|
|
|
public function getParentSpanID() |
55
|
|
|
{ |
56
|
|
|
return $this->ctx[CTX::PARENT_SPAN_ID] ?? ''; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getBaggageItems() : array |
63
|
|
|
{ |
64
|
|
|
return (array) $this->ctx; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
public function checkIsSampled() : bool |
71
|
|
|
{ |
72
|
|
|
return $this->ctx[CTX::TRACE_SAMPLED] ?? false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $id |
77
|
|
|
*/ |
78
|
|
|
public function setTraceID(string $id) : void |
79
|
|
|
{ |
80
|
|
|
$this->ctx[CTX::TRACE_ID] = $id; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $id |
85
|
|
|
*/ |
86
|
|
|
public function setSpanID(string $id) : void |
87
|
|
|
{ |
88
|
|
|
$this->ctx[CTX::SPAN_ID] = $id; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $id |
93
|
|
|
*/ |
94
|
|
|
public function setParentSpanID(string $id) : void |
95
|
|
|
{ |
96
|
|
|
$this->ctx[CTX::PARENT_SPAN_ID] = $id; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param array $items |
101
|
|
|
*/ |
102
|
|
|
public function setBaggageItems(array $items) : void |
103
|
|
|
{ |
104
|
|
|
foreach ($items as $key => $val) { |
105
|
|
|
$this->ctx[$key] = $val; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param bool $sampled |
111
|
|
|
*/ |
112
|
|
|
public function markIsSampled(bool $sampled) : void |
113
|
|
|
{ |
114
|
|
|
$this->ctx[CTX::TRACE_SAMPLED] = $sampled; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|