Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit b528e31

Browse files
author
Sergey Kanzhelev
committed
few fixes before release
1 parent 966cef4 commit b528e31

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
## 0.4.4
44

5+
- Initialize `name` and operation id for requests telemetry.
56
- Updated to the latest schemas. Few properties are no longer available.
67
- Enum `Dependency_Type` and `async` argument of `TrackDependency` were removed.
78
- New event type `Availability_Data`.
89
- Use `Cloud` context instead of `Device` context to set role name and role instance of an application.
910

10-
1111
## 0.4.3
1212

1313
- Support tracking Throwable and Error, not only Exceptions.

README.md

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
# Application Insights for PHP #
1+
# Application Insights for PHP
22

33
[![Build Status](https://travis-ci.org/Microsoft/ApplicationInsights-PHP.svg?branch=master)](https://travis-ci.org/Microsoft/ApplicationInsights-PHP)
44
[![Packagist Pre Release](https://img.shields.io/packagist/vpre/microsoft/application-insights.svg)](https://packagist.org/packages/microsoft/application-insights)
55

6+
This project extends the Application Insights API surface to support PHP.
7+
[Application
8+
Insights](http://azure.microsoft.com/services/application-insights/) is a
9+
service that allows developers to keep their application available, performing
10+
and succeeding. This PHP module will allow you to send telemetry of various
11+
kinds (event, trace, exception, etc.) to the Application Insights service where
12+
they can be visualized in the Azure Portal.
613

7-
This project extends the Application Insights API surface to support PHP. [Application Insights](http://azure.microsoft.com/en-us/services/application-insights/) is a service that allows developers to keep their application available, performing and succeeding. This PHP module will allow you to send telemetry of various kinds (event, trace, exception, etc.) to the Application Insights service where they can be visualized in the Azure Portal.
8-
9-
## Requirements ##
14+
## Requirements
1015

1116
PHP version >=5.4.2 is supported.
1217

1318
For opening the project in Microsoft Visual Studio you will need [PHP Tools for Visual Studio](http://www.devsense.com/products/php-tools). This is not required however.
1419

15-
## Installation ##
20+
## Installation
1621

1722
We've published a package you can find on [Packagist](https://packagist.org/packages/microsoft/application-insights). In order to use it, first, you'll need to get [Composer](https://getcomposer.org/).
1823

@@ -28,14 +33,15 @@ Make sure you add the require statement to pull in the library:
2833
require_once 'vendor/autoload.php';
2934
```
3035

31-
## Usage ##
36+
## Usage
3237

3338
Once installed, you can send telemetry to Application Insights. Here are a few samples.
3439

3540
>**Note**: before you can send data to you will need an instrumentation key. Please see the [Getting an Application Insights Instrumentation Key](https://github.com/Microsoft/AppInsights-Home/wiki#getting-an-application-insights-instrumentation-key) section for more information.
3641
42+
**Initializing the client and setting the instrumentation key and other optional
43+
configurations**
3744

38-
**Initializing the client and setting the instrumentation key and other optional configurations**
3945
```php
4046
$telemetryClient = new \ApplicationInsights\Telemetry_Client();
4147
$context = $telemetryClient->getContext();
@@ -56,74 +62,92 @@ $telemetryClient->flush();
5662

5763
**Setup Operation context**
5864

59-
For correct Application Insights reporting you need to setup Operation Context, reference to Request
65+
For correct Application Insights reporting you need to setup Operation Context,
66+
reference to Request
67+
6068
```php
6169
$telemetryClient->getContext()->getOperationContext()->setId('XX');
6270
$telemetryClient->getContext()->getOperationContext()->setName('GET Index');
6371
```
6472

6573
**Sending a simple event telemetry item with event name**
74+
6675
```php
6776
$telemetryClient->trackEvent('name of your event');
6877
$telemetryClient->flush();
6978
```
7079

7180
**Sending an event telemetry item with custom properties and measurements**
81+
7282
```php
7383
$telemetryClient->trackEvent('name of your event', ['MyCustomProperty' => 42, 'MyCustomProperty2' => 'test'], ['duration', 42]);
7484
$telemetryClient->flush();
7585
```
7686

77-
**Sending more than one telemetry item before sending to the service is also supported; the API will batch everything until you call flush()**
87+
**Sending more than one telemetry item before sending to the service is also
88+
supported; the API will batch everything until you call flush()**
89+
7890
```php
7991
$telemetryClient->trackEvent('name of your event');
8092
$telemetryClient->trackEvent('name of your second event');
8193
$telemetryClient->flush();
8294
```
8395

8496
**Sending a simple page view telemetry item with page name and url**
97+
8598
```php
8699
$telemetryClient->trackPageView('myPageView', 'http://www.foo.com');
87100
$telemetryClient->flush();
88101
```
89102

90-
**Sending a page view telemetry item with duration, custom properties and measurements**
103+
**Sending a page view telemetry item with duration, custom properties and
104+
measurements**
105+
91106
```php
92107
$telemetryClient->trackPageView('myPageView', 'http://www.foo.com', 256, ['InlineProperty' => 'test_value'], ['duration' => 42.0]);
93108
$telemetryClient->flush();
94109
```
95110

96111
**Sending a simple metric telemetry item with metric name and value***
112+
97113
```php
98114
$telemetryClient->trackMetric('myMetric', 42.0);
99115
$telemetryClient->flush();
100116
```
101117

102-
**Sending a metric telemetry item with point type, count, min, max, standard deviation and measurements**
118+
**Sending a metric telemetry item with point type, count, min, max, standard
119+
deviation and measurements**
120+
103121
```php
104122
$telemetryClient->trackMetric('myMetric', 42.0, \ApplicationInsights\Channel\Contracts\Data_Point_Type::Aggregation, 5, 0, 1, 0.2, ['InlineProperty' => 'test_value']);
105123
$telemetryClient->flush();
106124
```
107125

108-
**Sending a simple message telemetry item with message***
126+
**Sending a simple message telemetry item with message**
127+
109128
```php
110129
$telemetryClient->trackMessage('myMessage', \ApplicationInsights\Channel\Contracts\Message_Severity_Level::INFORMATION, ['InlineProperty' => 'test_value']);
111130
$telemetryClient->flush();
112131
```
113132

114-
**Sending a simple request telemetry item with request name, url and start time***
133+
**Sending a simple request telemetry item with request name, url and start
134+
time**
135+
115136
```php
116137
$telemetryClient->trackRequest('myRequest', 'http://foo.bar', time());
117138
$telemetryClient->flush();
118139
```
119140

120-
**Sending a request telemetry item with duration, http status code, whether or not the request succeeded, custom properties and measurements**
141+
**Sending a request telemetry item with duration, http status code, whether or
142+
not the request succeeded, custom properties and measurements**
143+
121144
```php
122145
$telemetryClient->trackRequest('myRequest', 'http://foo.bar', time(), 3754, 200, true, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]);
123146
$telemetryClient->flush();
124147
```
125148

126149
**Sending an exception telemetry, with custom properties and metrics**
150+
127151
```php
128152
try
129153
{
@@ -132,17 +156,18 @@ try
132156
catch (\Exception $ex)
133157
{
134158
$telemetryClient->trackException($ex, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]);
135-
$telemetryClient->flush();
159+
$telemetryClient->flush();
136160
}
137-
138161
```
139162

140163
**Set the Client to gzip the data before sending**
164+
141165
```php
142166
$telemetryClient->getChannel()->setSendGzipped(true);
143167
```
144168

145169
**Registering an exception handler**
170+
146171
```php
147172
class Handle_Exceptions
148173
{
@@ -151,7 +176,7 @@ class Handle_Exceptions
151176
public function __construct()
152177
{
153178
$this->_telemetryClient = new \ApplicationInsights\Telemetry_Client();
154-
$this->_telemetryClient->getContext()->setInstrumentationKey('YOUR INSTRUMENTATION KEY');
179+
$this->_telemetryClient->getContext()->setInstrumentationKey('YOUR INSTRUMENTATION KEY');
155180

156181
set_exception_handler(array($this, 'exceptionHandler'));
157182
}
@@ -168,24 +193,28 @@ class Handle_Exceptions
168193
```
169194

170195
**Sending a successful SQL dependency telemetry item**
196+
171197
```php
172198
$telemetryClient->trackDependency('Query table', "SQL", 'SELECT * FROM table;', time(), 122, true);
173199
$telemetryClient->flush();
174200
```
175201

176202
**Sending a failed HTTP dependency telemetry item**
203+
177204
```php
178205
$telemetryClient->trackDependency('method', "HTTP", "http://example.com/api/method", time(), 324, false, 503);
179206
$telemetryClient->flush();
180207
```
181208

182209
**Sending any other kind dependency telemetry item**
210+
183211
```php
184212
$telemetryClient->trackDependency('Name of operation', "service", 'Arguments', time(), 23, true);
185213
$telemetryClient->flush();
186214
```
187215

188216
**Changing the operation id (which links actions together)**
217+
189218
```php
190219
$telemetryClient->trackMetric('interestingMetric', 10);
191220
$telemetryClient->getContext()->getOperationContext()->setId(\ApplicationInsights\Channel\Contracts\Utils::returnGuid())

0 commit comments

Comments
 (0)