|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ZoiloMora\ElasticAPM\Events\Span; |
|
4
|
|
|
|
|
5
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Message; |
|
6
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Tags; |
|
7
|
|
|
use ZoiloMora\ElasticAPM\Events\Span\Context\Db; |
|
8
|
|
|
use ZoiloMora\ElasticAPM\Events\Span\Context\Destination; |
|
9
|
|
|
use ZoiloMora\ElasticAPM\Events\Span\Context\Http; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Any other arbitrary data captured by the agent, optionally provided by the user |
|
13
|
|
|
*/ |
|
14
|
|
|
final class Context implements \JsonSerializable |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* An object containing contextual data about the destination for spans |
|
18
|
|
|
* |
|
19
|
|
|
* @var Destination|null |
|
20
|
|
|
*/ |
|
21
|
|
|
private $destination; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* An object containing contextual data for database spans |
|
25
|
|
|
* |
|
26
|
|
|
* @var Db|null |
|
27
|
|
|
*/ |
|
28
|
|
|
private $db; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* An object containing contextual data of the related http request. |
|
32
|
|
|
* |
|
33
|
|
|
* @var Http|null |
|
34
|
|
|
*/ |
|
35
|
|
|
private $http; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* A flat mapping of user-defined tags with string, boolean or number values. |
|
39
|
|
|
* "string", "boolean", "number", "null" |
|
40
|
|
|
* |
|
41
|
|
|
* @var Tags|null |
|
42
|
|
|
*/ |
|
43
|
|
|
private $tags; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Details related to message receiving and publishing if the captured event |
|
47
|
|
|
* integrates with a messaging system |
|
48
|
|
|
* |
|
49
|
|
|
* @var Message|null |
|
50
|
|
|
*/ |
|
51
|
|
|
private $message; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param Destination|null $destination |
|
55
|
|
|
* @param Db|null $db |
|
56
|
|
|
* @param Http|null $http |
|
57
|
|
|
* @param Tags|null $tags |
|
58
|
|
|
* @param Message|null $message |
|
59
|
|
|
*/ |
|
60
|
5 |
|
public function __construct( |
|
61
|
|
|
Destination $destination = null, |
|
62
|
|
|
Db $db = null, |
|
63
|
|
|
Http $http = null, |
|
64
|
|
|
Tags $tags = null, |
|
65
|
|
|
Message $message = null |
|
66
|
|
|
) { |
|
67
|
5 |
|
$this->setDestination($destination); |
|
68
|
5 |
|
$this->setDb($db); |
|
69
|
5 |
|
$this->setHttp($http); |
|
70
|
5 |
|
$this->setTags($tags); |
|
71
|
5 |
|
$this->setMessage($message); |
|
72
|
5 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param Db $db |
|
76
|
|
|
* |
|
77
|
|
|
* @return Context |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public static function fromDb(Db $db) |
|
80
|
|
|
{ |
|
81
|
1 |
|
return new self(null, $db); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param Http $http |
|
86
|
|
|
* |
|
87
|
|
|
* @return Context |
|
88
|
|
|
*/ |
|
89
|
1 |
|
public static function fromHttp(Http $http) |
|
90
|
|
|
{ |
|
91
|
1 |
|
return new self(null, null, $http); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param Message $message |
|
96
|
|
|
* |
|
97
|
|
|
* @return Context |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public static function fromMessage(Message $message) |
|
100
|
|
|
{ |
|
101
|
1 |
|
return new self(null, null, null, null, $message); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return Destination|null |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function destination() |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->destination; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param Destination|null $destination |
|
114
|
|
|
*/ |
|
115
|
5 |
|
public function setDestination(Destination $destination = null) |
|
116
|
|
|
{ |
|
117
|
5 |
|
$this->destination = $destination; |
|
118
|
5 |
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return Db|null |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function db() |
|
124
|
|
|
{ |
|
125
|
1 |
|
return $this->db; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param Db|null $db |
|
130
|
|
|
*/ |
|
131
|
5 |
|
public function setDb(Db $db = null) |
|
132
|
|
|
{ |
|
133
|
5 |
|
$this->db = $db; |
|
134
|
5 |
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return Http|null |
|
138
|
|
|
*/ |
|
139
|
1 |
|
public function http() |
|
140
|
|
|
{ |
|
141
|
1 |
|
return $this->http; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param Http|null $http |
|
146
|
|
|
*/ |
|
147
|
5 |
|
public function setHttp(Http $http = null) |
|
148
|
|
|
{ |
|
149
|
5 |
|
$this->http = $http; |
|
150
|
5 |
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return Tags|null |
|
154
|
|
|
*/ |
|
155
|
1 |
|
public function tags() |
|
156
|
|
|
{ |
|
157
|
1 |
|
return $this->tags; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param Tags|null $tags |
|
162
|
|
|
*/ |
|
163
|
5 |
|
public function setTags(Tags $tags = null) |
|
164
|
|
|
{ |
|
165
|
5 |
|
$this->tags = $tags; |
|
166
|
5 |
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return Message|null |
|
170
|
|
|
*/ |
|
171
|
1 |
|
public function message() |
|
172
|
|
|
{ |
|
173
|
1 |
|
return $this->message; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param Message|null $message |
|
178
|
|
|
*/ |
|
179
|
5 |
|
public function setMessage(Message $message = null) |
|
180
|
|
|
{ |
|
181
|
5 |
|
$this->message = $message; |
|
182
|
5 |
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @return array |
|
186
|
|
|
*/ |
|
187
|
1 |
|
public function jsonSerialize() |
|
188
|
|
|
{ |
|
189
|
|
|
return [ |
|
190
|
1 |
|
'destination' => $this->destination, |
|
191
|
1 |
|
'db' => $this->db, |
|
192
|
1 |
|
'http' => $this->http, |
|
193
|
1 |
|
'tags' => $this->tags, |
|
194
|
1 |
|
'message' => $this->message, |
|
195
|
1 |
|
]; |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|