1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ZoiloMora\ElasticAPM\Events\Common; |
4
|
|
|
|
5
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Context\Response; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user |
9
|
|
|
*/ |
10
|
|
|
class Context implements \JsonSerializable |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* An arbitrary mapping of additional metadata to store with the event. |
14
|
|
|
* |
15
|
|
|
* @var array|null |
16
|
|
|
*/ |
17
|
|
|
private $custom; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Response|null |
21
|
|
|
*/ |
22
|
|
|
private $response; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* If a log record was generated as a result of a http request, |
26
|
|
|
* the http interface can be used to collect this information. |
27
|
|
|
* |
28
|
|
|
* @var Request|null |
29
|
|
|
*/ |
30
|
|
|
private $request; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* A flat mapping of user-defined tags with string, boolean or number values. |
34
|
|
|
* |
35
|
|
|
* @var Tags|null |
36
|
|
|
*/ |
37
|
|
|
private $tags; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Describes the correlated user for this event. |
41
|
|
|
* If user data are provided here, all user related information from metadata is ignored, |
42
|
|
|
* otherwise the metadata's user information will be stored with the event. |
43
|
|
|
* |
44
|
|
|
* @var User|null |
45
|
|
|
*/ |
46
|
|
|
private $user; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var Message|null |
50
|
|
|
*/ |
51
|
|
|
private $message; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array|null $custom |
55
|
|
|
* @param Response|null $response |
56
|
|
|
* @param Request|null $request |
57
|
|
|
* @param Tags|null $tags |
58
|
|
|
* @param User|null $user |
59
|
|
|
* @param Message|null $message |
60
|
|
|
*/ |
61
|
15 |
|
public function __construct( |
62
|
|
|
array $custom = null, |
63
|
|
|
Response $response = null, |
64
|
|
|
Request $request = null, |
65
|
|
|
Tags $tags = null, |
66
|
|
|
User $user = null, |
67
|
|
|
Message $message = null |
68
|
|
|
) { |
69
|
15 |
|
$this->setCustom($custom); |
70
|
15 |
|
$this->setResponse($response); |
71
|
15 |
|
$this->setRequest($request); |
72
|
15 |
|
$this->setTags($tags); |
73
|
15 |
|
$this->setUser($user); |
74
|
15 |
|
$this->setMessage($message); |
75
|
15 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array|null |
79
|
|
|
*/ |
80
|
1 |
|
public function custom() |
81
|
|
|
{ |
82
|
1 |
|
return $this->custom; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param array|null $custom |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
15 |
|
public function setCustom(array $custom = null) |
91
|
|
|
{ |
92
|
15 |
|
$this->custom = $custom; |
93
|
15 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return Response|null |
97
|
|
|
*/ |
98
|
1 |
|
public function response() |
99
|
|
|
{ |
100
|
1 |
|
return $this->response; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param Response|null $response |
105
|
|
|
* |
106
|
|
|
* @return void |
107
|
|
|
*/ |
108
|
15 |
|
public function setResponse(Response $response = null) |
109
|
|
|
{ |
110
|
15 |
|
$this->response = $response; |
111
|
15 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return Request|null |
115
|
|
|
*/ |
116
|
1 |
|
public function request() |
117
|
|
|
{ |
118
|
1 |
|
return $this->request; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param Request|null $request |
123
|
|
|
* |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
15 |
|
public function setRequest(Request $request = null) |
127
|
|
|
{ |
128
|
15 |
|
$this->request = $request; |
129
|
15 |
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return array|Tags|null |
133
|
|
|
*/ |
134
|
1 |
|
public function tags() |
135
|
|
|
{ |
136
|
1 |
|
return $this->tags; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param Tags|null $tags |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
15 |
|
public function setTags(Tags $tags = null) |
145
|
|
|
{ |
146
|
15 |
|
$this->tags = $tags; |
147
|
15 |
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return User|null |
151
|
|
|
*/ |
152
|
1 |
|
public function user() |
153
|
|
|
{ |
154
|
1 |
|
return $this->user; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param User|null $user |
159
|
|
|
* |
160
|
|
|
* @return void |
161
|
|
|
*/ |
162
|
15 |
|
public function setUser(User $user = null) |
163
|
|
|
{ |
164
|
15 |
|
$this->user = $user; |
165
|
15 |
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return Message|null |
169
|
|
|
*/ |
170
|
1 |
|
public function message() |
171
|
|
|
{ |
172
|
1 |
|
return $this->message; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param Message|null $message |
177
|
|
|
* |
178
|
|
|
* @return void |
179
|
|
|
*/ |
180
|
15 |
|
public function setMessage(Message $message = null) |
181
|
|
|
{ |
182
|
15 |
|
$this->message = $message; |
183
|
15 |
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return Context |
187
|
|
|
*/ |
188
|
12 |
|
public static function discover() |
189
|
|
|
{ |
190
|
12 |
|
return new self( |
191
|
12 |
|
null, |
192
|
12 |
|
null, |
193
|
12 |
|
Request::discover() |
194
|
12 |
|
); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return array |
199
|
|
|
*/ |
200
|
1 |
|
public function jsonSerialize() |
201
|
|
|
{ |
202
|
|
|
return [ |
203
|
1 |
|
'custom' => $this->custom, |
204
|
1 |
|
'response' => $this->response, |
205
|
1 |
|
'request' => $this->request, |
206
|
1 |
|
'tags' => $this->tags, |
207
|
1 |
|
'user' => $this->user, |
208
|
1 |
|
'message' => $this->message, |
209
|
1 |
|
]; |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|