PHPackages                             soilcapital/application-insights - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. soilcapital/application-insights

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

soilcapital/application-insights
================================

This project extends the Application Insights API surface to support PHP.

0.4.6(3y ago)03.1kMITPHPPHP &gt;=5.4.0

Since Dec 19Pushed 3y agoCompare

[ Source](https://github.com/Soil-Capital/ApplicationInsights-PHP)[ Packagist](https://packagist.org/packages/soilcapital/application-insights)[ Docs](https://github.com/Soil-Capital/ApplicationInsights-PHP)[ RSS](/packages/soilcapital-application-insights/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (3)Versions (18)Used By (0)

Application Insights for PHP
============================

[](#application-insights-for-php)

[![Build Status](https://camo.githubusercontent.com/f032d177fc5b183e1921027ab838f0e7115c025ec2525a21c213ec156a382cd5/68747470733a2f2f7472617669732d63692e6f72672f4d6963726f736f66742f4170706c69636174696f6e496e7369676874732d5048502e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Microsoft/ApplicationInsights-PHP)[![Packagist Pre Release](https://camo.githubusercontent.com/702e43b02723cde0cde9219fd83b2995cf637c2b14c19b5a352bfcecede4e7c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6d6963726f736f66742f6170706c69636174696f6e2d696e7369676874732e737667)](https://packagist.org/packages/microsoft/application-insights)

This project extends the Application Insights API surface to support PHP. [Application Insights](https://azure.microsoft.com/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.

Status
------

[](#status)

This SDK is NOT maintained or supported by Microsoft even though we've contributed to it in the past. Note that Azure Monitor only provides support when using the [supported SDKs](https://docs.microsoft.com/en-us/azure/azure-monitor/app/platforms#unsupported-community-sdks). We’re constantly assessing opportunities to expand our support for other languages, so follow our [GitHub Announcements](https://github.com/microsoft/ApplicationInsights-Announcements/issues) page to receive the latest SDK news.

Requirements
------------

[](#requirements)

PHP version &gt;=5.4.2 is supported.

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

Installation
------------

[](#installation)

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/).

Once you've setup your project to use Composer, just add a reference to our package with whichever version you'd like to use to your composer.json file.

```
require: "microsoft/application-insights": "*"
```

Or you can use the composer command to automatically add the package to your composer.json file.

```
composer require microsoft/application-insights
```

Make sure you add the require statement to pull in the library:

```
require_once 'vendor/autoload.php';
```

Usage
-----

[](#usage)

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

> **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.

### Initializing the client and setting the instrumentation key and other optional configurations

[](#initializing-the-client-and-setting-the-instrumentation-key-and-other-optional-configurations)

```
$telemetryClient = new \ApplicationInsights\Telemetry_Client();
$context = $telemetryClient->getContext();

// Necessary
$context->setInstrumentationKey('YOUR INSTRUMENTATION KEY');

// Optional
$context->getSessionContext()->setId(session_id());
$context->getUserContext()->setId('YOUR USER ID');
$context->getApplicationContext()->setVer('YOUR VERSION');
$context->getLocationContext()->setIp('YOUR IP');

// Start tracking
$telemetryClient->trackEvent('name of your event');
$telemetryClient->flush();
```

### Setup Operation context

[](#setup-operation-context)

For correct Application Insights reporting you need to setup Operation Context, reference to Request

```
$telemetryClient->getContext()->getOperationContext()->setId('XX');
$telemetryClient->getContext()->getOperationContext()->setName('GET Index');
```

### Sending a simple event telemetry item with event name

[](#sending-a-simple-event-telemetry-item-with-event-name)

```
$telemetryClient->trackEvent('name of your event');
$telemetryClient->flush();
```

### Sending an event telemetry item with custom properties and measurements

[](#sending-an-event-telemetry-item-with-custom-properties-and-measurements)

```
$telemetryClient->trackEvent('name of your event', ['MyCustomProperty' => 42, 'MyCustomProperty2' => 'test'], ['duration', 42]);
$telemetryClient->flush();
```

**Sending more than one telemetry item before sending to the service is also supported; the API will batch everything until you call flush()**

```
$telemetryClient->trackEvent('name of your event');
$telemetryClient->trackEvent('name of your second event');
$telemetryClient->flush();
```

### Sending a simple page view telemetry item with page name and url

[](#sending-a-simple-page-view-telemetry-item-with-page-name-and-url)

```
$telemetryClient->trackPageView('myPageView', 'http://www.foo.com');
$telemetryClient->flush();
```

### Sending a page view telemetry item with duration, custom properties and measurements

[](#sending-a-page-view-telemetry-item-with-duration-custom-properties-and-measurements)

```
$telemetryClient->trackPageView('myPageView', 'http://www.foo.com', 256, ['InlineProperty' => 'test_value'], ['duration' => 42.0]);
$telemetryClient->flush();
```

### Sending a simple metric telemetry item with metric name and value

[](#sending-a-simple-metric-telemetry-item-with-metric-name-and-value)

```
$telemetryClient->trackMetric('myMetric', 42.0);
$telemetryClient->flush();
```

### Sending a metric telemetry item with point type, count, min, max, standard deviation and measurements

[](#sending-a-metric-telemetry-item-with-point-type-count-min-max-standard-deviation-and-measurements)

```
$telemetryClient->trackMetric('myMetric', 42.0, \ApplicationInsights\Channel\Contracts\Data_Point_Type::Aggregation, 5, 0, 1, 0.2, ['InlineProperty' => 'test_value']);
$telemetryClient->flush();
```

### Sending a simple message telemetry item with message

[](#sending-a-simple-message-telemetry-item-with-message)

```
$telemetryClient->trackMessage('myMessage', \ApplicationInsights\Channel\Contracts\Message_Severity_Level::INFORMATION, ['InlineProperty' => 'test_value']);
$telemetryClient->flush();
```

**Sending a simple request telemetry item with request name, url and start time**

```
$telemetryClient->trackRequest('myRequest', 'http://foo.bar', time());
$telemetryClient->flush();
```

### Sending a request telemetry item with duration, http status code, whether or not the request succeeded, custom properties and measurements

[](#sending-a-request-telemetry-item-with-duration-http-status-code-whether-or-not-the-request-succeeded-custom-properties-and-measurements)

```
$telemetryClient->trackRequest('myRequest', 'http://foo.bar', time(), 3754, 200, true, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]);
$telemetryClient->flush();
```

### Sending an exception telemetry, with custom properties and metrics

[](#sending-an-exception-telemetry-with-custom-properties-and-metrics)

```
try
{
    // Do something to throw an exception
}
catch (\Exception $ex)
{
    $telemetryClient->trackException($ex, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]);
    $telemetryClient->flush();
}
```

### Set the Client to gzip the data before sending

[](#set-the-client-to-gzip-the-data-before-sending)

```
$telemetryClient->getChannel()->setSendGzipped(true);
```

### Registering an exception handler

[](#registering-an-exception-handler)

```
class Handle_Exceptions
{
    private $_telemetryClient;

    public function __construct()
    {
        $this->_telemetryClient = new \ApplicationInsights\Telemetry_Client();
        $this->_telemetryClient->getContext()->setInstrumentationKey('YOUR INSTRUMENTATION KEY');

        set_exception_handler(array($this, 'exceptionHandler'));
    }

    function exceptionHandler(\Exception $exception)
    {
        if ($exception != NULL)
        {
            $this->_telemetryClient->trackException($exception);
            $this->_telemetryClient->flush();
        }
    }
}
```

### Sending a successful SQL dependency telemetry item

[](#sending-a-successful-sql-dependency-telemetry-item)

```
$telemetryClient->trackDependency('Query table', "SQL", 'SELECT * FROM table;', time(), 122, true);
$telemetryClient->flush();
```

### Sending a failed HTTP dependency telemetry item

[](#sending-a-failed-http-dependency-telemetry-item)

```
$telemetryClient->trackDependency('method', "HTTP", "http://example.com/api/method", time(), 324, false, 503);
$telemetryClient->flush();
```

### Sending any other kind dependency telemetry item

[](#sending-any-other-kind-dependency-telemetry-item)

```
$telemetryClient->trackDependency('Name of operation', "service", 'Arguments', time(), 23, true);
$telemetryClient->flush();
```

### Changing the operation id (which links actions together)

[](#changing-the-operation-id-which-links-actions-together)

```
$telemetryClient->trackMetric('interestingMetric', 10);
$telemetryClient->getContext()->getOperationContext()->setId(\ApplicationInsights\Channel\Contracts\Utils::returnGuid())
$telemetryClient->trackMetric('differentOperationMetric', 11);
$telemetryClient->flush();
```

Code of conduct
---------------

[](#code-of-conduct)

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact  with any additional questions or comments.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~168 days

Recently: every ~392 days

Total

17

Last Release

1459d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.4.2

0.2.3PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/28834956?v=4)[qluc](/maintainers/qluc)[@qluc](https://github.com/qluc)

---

Top Contributors

[![JakubOleksy](https://avatars.githubusercontent.com/u/6147691?v=4)](https://github.com/JakubOleksy "JakubOleksy (50 commits)")[![SergeyKanzhelev](https://avatars.githubusercontent.com/u/9950081?v=4)](https://github.com/SergeyKanzhelev "SergeyKanzhelev (9 commits)")[![jondmcelroy](https://avatars.githubusercontent.com/u/4562548?v=4)](https://github.com/jondmcelroy "jondmcelroy (7 commits)")[![hajekj](https://avatars.githubusercontent.com/u/8337913?v=4)](https://github.com/hajekj "hajekj (6 commits)")[![Peter-Juhasz](https://avatars.githubusercontent.com/u/9047283?v=4)](https://github.com/Peter-Juhasz "Peter-Juhasz (4 commits)")[![QuentinLuc](https://avatars.githubusercontent.com/u/5237095?v=4)](https://github.com/QuentinLuc "QuentinLuc (3 commits)")[![wilsonge](https://avatars.githubusercontent.com/u/1986000?v=4)](https://github.com/wilsonge "wilsonge (3 commits)")[![artberri](https://avatars.githubusercontent.com/u/454523?v=4)](https://github.com/artberri "artberri (2 commits)")[![gardnerjr](https://avatars.githubusercontent.com/u/10158007?v=4)](https://github.com/gardnerjr "gardnerjr (2 commits)")[![Miloslav](https://avatars.githubusercontent.com/u/842147?v=4)](https://github.com/Miloslav "Miloslav (2 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![marchie](https://avatars.githubusercontent.com/u/5711374?v=4)](https://github.com/marchie "marchie (1 commits)")[![mattmccleary](https://avatars.githubusercontent.com/u/43887470?v=4)](https://github.com/mattmccleary "mattmccleary (1 commits)")[![mikeaag](https://avatars.githubusercontent.com/u/1278785?v=4)](https://github.com/mikeaag "mikeaag (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![evil-jakuboleksy](https://avatars.githubusercontent.com/u/168943538?v=4)](https://github.com/evil-jakuboleksy "evil-jakuboleksy (1 commits)")[![pgrimaud](https://avatars.githubusercontent.com/u/1866496?v=4)](https://github.com/pgrimaud "pgrimaud (1 commits)")[![Dmitry-Matveev](https://avatars.githubusercontent.com/u/12158043?v=4)](https://github.com/Dmitry-Matveev "Dmitry-Matveev (1 commits)")[![cberio](https://avatars.githubusercontent.com/u/4189217?v=4)](https://github.com/cberio "cberio (1 commits)")[![stayallive](https://avatars.githubusercontent.com/u/1090754?v=4)](https://github.com/stayallive "stayallive (1 commits)")

---

Tags

logloggingmonitoringInsightstelemetry

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/soilcapital-application-insights/health.svg)

```
[![Health](https://phpackages.com/badges/soilcapital-application-insights/health.svg)](https://phpackages.com/packages/soilcapital-application-insights)
```

###  Alternatives

[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[honeybadger-io/honeybadger-php

Honeybadger PHP library

381.5M4](/packages/honeybadger-io-honeybadger-php)[saasscaleup/laravel-log-alarm

Laravel log Alarm help you to set up alarm when errors occur in your system and send you a notification via Slack and email

27025.0k](/packages/saasscaleup-laravel-log-alarm)[lefuturiste/monolog-discord-handler

A simple monolog handler for support Discord webhooks

34111.6k4](/packages/lefuturiste-monolog-discord-handler)[oanhnn/laravel-logzio

Integrate Logz.io into PHP and Laravel 5.6+ Application

1062.8k](/packages/oanhnn-laravel-logzio)[hosmelq/laravel-logsnag

Integrate the power of LogSnag's real-time event tracking into your Laravel application.

237.9k](/packages/hosmelq-laravel-logsnag)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
