PHPackages                             app-insights-php/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. app-insights-php/application-insights

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

app-insights-php/application-insights
=====================================

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

0.5.1(2y ago)4401.4k↓39.9%2[1 PRs](https://github.com/app-insights-php/applicationInsights-php/pulls)1MITPHPPHP ~8.1 || ~8.2

Since Dec 19Pushed 2y agoCompare

[ Source](https://github.com/app-insights-php/applicationInsights-php)[ Packagist](https://packagist.org/packages/app-insights-php/application-insights)[ Docs](https://github.com/app-insights-php/application-insights)[ RSS](/packages/app-insights-php-application-insights/feed)WikiDiscussions 1.x Synced 3d ago

READMEChangelog (5)Dependencies (1)Versions (24)Used By (1)

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

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

> This is a fork of project archived by microsoft.

[![Tests](https://github.com/app-insights-php/applicationInsights-php/actions/workflows/test.yml/badge.svg?branch=1.x)](https://github.com/app-insights-php/applicationInsights-php/actions/workflows/test.yml)

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: "app-insights-php/application-insights": "*"
```

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

```
composer require app-insights-php/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

43

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~154 days

Recently: every ~133 days

Total

22

Last Release

968d ago

Major Versions

0.5.1 → 1.x-dev2023-11-09

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

0.2.3PHP &gt;=5.4.0

0.4.6PHP ^7.4.0 || ~8.0 || ~8.1

0.5.0PHP ~8.1 || ~8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/52325810?v=4)[norbert-tech](/maintainers/norbert-tech)[@norbert-tech](https://github.com/norbert-tech)

---

Top Contributors

[![JakubOleksy](https://avatars.githubusercontent.com/u/6147691?v=4)](https://github.com/JakubOleksy "JakubOleksy (50 commits)")[![aeon-automation](https://avatars.githubusercontent.com/u/77585774?v=4)](https://github.com/aeon-automation "aeon-automation (9 commits)")[![SergeyKanzhelev](https://avatars.githubusercontent.com/u/9950081?v=4)](https://github.com/SergeyKanzhelev "SergeyKanzhelev (9 commits)")[![norberttech](https://avatars.githubusercontent.com/u/1921950?v=4)](https://github.com/norberttech "norberttech (7 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)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![Peter-Juhasz](https://avatars.githubusercontent.com/u/9047283?v=4)](https://github.com/Peter-Juhasz "Peter-Juhasz (4 commits)")[![wilsonge](https://avatars.githubusercontent.com/u/1986000?v=4)](https://github.com/wilsonge "wilsonge (3 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)")[![artberri](https://avatars.githubusercontent.com/u/454523?v=4)](https://github.com/artberri "artberri (2 commits)")[![kevinklinke](https://avatars.githubusercontent.com/u/92231227?v=4)](https://github.com/kevinklinke "kevinklinke (1 commits)")[![lukassteiner](https://avatars.githubusercontent.com/u/7202168?v=4)](https://github.com/lukassteiner "lukassteiner (1 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)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (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)")

---

Tags

logloggingmonitoringInsightstelemetry

### Embed Badge

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

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

###  Alternatives

[analog/analog

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

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

Honeybadger PHP library

381.6M5](/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

26929.6k](/packages/saasscaleup-laravel-log-alarm)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[gevans/honeybadger

Honeybadger PHP library

387.6k](/packages/gevans-honeybadger)

PHPackages © 2026

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