forked from microsoft/ApplicationInsights-PHP
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTelemetry_Context.php
284 lines (248 loc) · 9.16 KB
/
Telemetry_Context.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
namespace ApplicationInsights;
/**
* Responsible for managing the context to send along with all telemetry items.
*/
class Telemetry_Context
{
/**
* The instrumentation key
* @var string (Guid)
*/
private $_instrumentationKey;
/**
* The device context
* @var \ApplicationInsights\Channel\Contracts\Device
*/
private $_deviceContext;
/**
* The cloud context
* @var \ApplicationInsights\Channel\Contracts\Cloud
*/
private $_cloudContext;
/**
* The application context
* @var \ApplicationInsights\Channel\Contracts\Application
*/
private $_applicationContext;
/**
* The user context
* @var \ApplicationInsights\Channel\Contracts\User
*/
private $_userContext;
/**
* The location context
* @var \ApplicationInsights\Channel\Contracts\Location
*/
private $_locationContext;
/**
* The operation context
* @var \ApplicationInsights\Channel\Contracts\Operation
*/
private $_operationContext;
/**
* The session context
* @var \ApplicationInsights\Channel\Contracts\Session
*/
private $_sessionContext;
/**
* The internal context
* @var \ApplicationInsights\Channel\Contracts\Internal
*/
private $_internalContext;
/**
* Additional custom properties array.
* @var array Additional properties (name/value pairs) to append as custom properties to all telemetry.
*/
private $_properties;
/**
* Initializes a new TelemetryContext.
*/
function __construct()
{
$this->_deviceContext = new Channel\Contracts\Device();
$this->_cloudContext = new Channel\Contracts\Cloud();
$this->_applicationContext = new Channel\Contracts\Application();
$this->_userContext = new Channel\Contracts\User();
$this->_locationContext = new Channel\Contracts\Location();
$this->_operationContext = new Channel\Contracts\Operation();
$this->_sessionContext = new Channel\Contracts\Session();
$this->_internalContext = new Channel\Contracts\Internal();
$this->_properties = array();
// Initialize user id
$currentUser = new Current_User();
$this->_userContext->setId($currentUser->id);
// Initialize session id
$currentSession = new Current_Session();
$this->_sessionContext->setId($currentSession->id);
// Initialize the operation id
$operationId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid();
$this->_operationContext->setId($operationId);
// Initialize client ip
if (array_key_exists('REMOTE_ADDR', $_SERVER) && sizeof(explode('.', $_SERVER['REMOTE_ADDR'])) >= 4)
{
$this->_locationContext->setIp($_SERVER['REMOTE_ADDR']);
}
$this->_internalContext->setSdkVersion('php:0.4.6');
}
/**
* The instrumentation key for your Application Insights application.
* @return string (Guid)
*/
public function getInstrumentationKey()
{
return $this->_instrumentationKey;
}
/**
* Sets the instrumetation key on the context. This is the key for you application in Application Insights.
* @param string $instrumentationKey (Guid)
*/
public function setInstrumentationKey($instrumentationKey)
{
$this->_instrumentationKey = $instrumentationKey;
}
/**
* The device context object. Allows you to set properties that will be attached to all telemetry about the device.
* @return \ApplicationInsights\Channel\Contracts\Device
*/
public function getDeviceContext()
{
return $this->_deviceContext;
}
/**
* Sets device context object. Allows you to set properties that will be attached to all telemetry about the device.
* @param \ApplicationInsights\Channel\Contracts\Device $deviceContext
*/
public function setDeviceContext(Channel\Contracts\Device $deviceContext)
{
$this->_deviceContext = $deviceContext;
}
/**
* The cloud context object. Allows you to set properties that will be attached to all telemetry about the cloud placement of an application.
* @return \ApplicationInsights\Channel\Contracts\Cloud
*/
public function getCloudContext()
{
return $this->_cloudContext;
}
/**
* Sets cloud context object. Allows you to set properties that will be attached to all telemetry about the cloud placement of an application.
* @param \ApplicationInsights\Channel\Contracts\Cloud $cloudContext
*/
public function setCloudContext(Channel\Contracts\Cloud $cloudContext)
{
$this->_cloudContext = $cloudContext;
}
/**
* The application context object. Allows you to set properties that will be attached to all telemetry about the application.
* @return \ApplicationInsights\Channel\Contracts\Application
*/
public function getApplicationContext()
{
return $this->_applicationContext;
}
/**
* Sets application context object. Allows you to set properties that will be attached to all telemetry about the application.
* @param \ApplicationInsights\Channel\Contracts\Application $applicationContext
*/
public function setApplicationContext(Channel\Contracts\Application $applicationContext)
{
$this->_applicationContext = $applicationContext;
}
/**
* The user context object. Allows you to set properties that will be attached to all telemetry about the user.
* @return \ApplicationInsights\Channel\Contracts\User
*/
public function getUserContext()
{
return $this->_userContext;
}
/**
* Set user context object. Allows you to set properties that will be attached to all telemetry about the user.
* @param \ApplicationInsights\Channel\Contracts\User $userContext
*/
public function setUserContext(Channel\Contracts\User $userContext)
{
$this->_userContext = $userContext;
}
/**
* The location context object. Allows you to set properties that will be attached to all telemetry about the location.
* @return \ApplicationInsights\Channel\Contracts\Location
*/
public function getLocationContext()
{
return $this->_locationContext;
}
/**
* Set location context object. Allows you to set properties that will be attached to all telemetry about the location.
* @param \ApplicationInsights\Channel\Contracts\Location $locationContext
*/
public function setLocationContext(Channel\Contracts\Location $locationContext)
{
$this->_locationContext = $locationContext;
}
/**
* The operation context object. Allows you to set properties that will be attached to all telemetry about the operation.
* @return \ApplicationInsights\Channel\Contracts\Operation
*/
public function getOperationContext()
{
return $this->_operationContext;
}
/**
* Set operation context object. Allows you to set properties that will be attached to all telemetry about the operation.
* @param \ApplicationInsights\Channel\Contracts\Operation $operationContext
*/
public function setOperationContext(Channel\Contracts\Operation $operationContext)
{
$this->_operationContext = $operationContext;
}
/**
* The session context object. Allows you to set properties that will be attached to all telemetry about the session.
* @return \ApplicationInsights\Channel\Contracts\Session
*/
public function getSessionContext()
{
return $this->_sessionContext;
}
/**
* Set session context object. Allows you to set properties that will be attached to all telemetry about the session.
* @param \ApplicationInsights\Channel\Contracts\Session $sessionContext
*/
public function setSessionContext(Channel\Contracts\Session $sessionContext)
{
$this->_sessionContext = $sessionContext;
}
/**
* The session context object. Allows you to set internal details for troubleshooting.
* @return \ApplicationInsights\Channel\Contracts\Internal
*/
public function getInternalContext()
{
return $this->_internalContext;
}
/**
* Set session context object. Allows you to set internal details for troubleshooting.
* @param \ApplicationInsights\Channel\Contracts\Internal $internalContext
*/
public function setInternalContext(Channel\Contracts\Internal $internalContext)
{
$this->_internalContext = $internalContext;
}
/**
* Get the additional custom properties array.
* @return array Additional properties (name/value pairs) to append as custom properties to all telemetry.
*/
public function getProperties()
{
return $this->_properties;
}
/**
* Set the additional custom properties array.
* @param array $properties Additional properties (name/value pairs) to append as custom properties to all telemetry.
*/
public function setProperties($properties)
{
$this->_properties = $properties;
}
}