PHPackages                             marchie/ms-application-insights-laravel - 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. marchie/ms-application-insights-laravel

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

marchie/ms-application-insights-laravel
=======================================

Microsoft Azure Application Insights for Laravel 5

v0.2.4(10y ago)134.0k↓33.3%21[6 PRs](https://github.com/Marchie/ms-application-insights-laravel/pulls)MITPHPPHP &gt;=5.4.0

Since Jul 29Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Marchie/ms-application-insights-laravel)[ Packagist](https://packagist.org/packages/marchie/ms-application-insights-laravel)[ RSS](/packages/marchie-ms-application-insights-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (13)Used By (0)

Microsoft Application Insights for Laravel 5
============================================

[](#microsoft-application-insights-for-laravel-5)

A simple Laravel implementation for [Microsoft Application Insights](http://azure.microsoft.com/en-gb/services/application-insights/)

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

[](#installation)

Update the `require` section of your application's **composer.json** file:

```
"require": {
	...
	"marchie/ms-application-insights-laravel": "^0.2",
	...
}
```

### Instrumentation Key

[](#instrumentation-key)

The package will check your application's **.env** file for your *Instrumentation Key*.

Add the following to your **.env** file:

```
...
MS_INSTRUMENTATION_KEY=
...

```

You can find your instrumentation key on the [Microsoft Azure Portal](https://portal.azure.com).

Navigate to:

**Microsoft Azure** &gt; **Browse** &gt; **Application Insights** &gt; *(Application Name)* &gt; **Settings** &gt; **Properties**

### On Laravel versions without Auto-Discovery (&lt; 5.5):

[](#on-laravel-versions-without-auto-discovery--55)

#### Service Provider

[](#service-provider)

Add the service provider to the *providers* array in your application's **config/app.php** file:

```
'providers' => [
	...
	Marchie\MSApplicationInsightsLaravel\Providers\MSApplicationInsightsServiceProvider::class,
	...
]
```

#### Facade

[](#facade)

Add the facades to the *aliases* array in your application's **config/app.php** file:

```
'aliases' => [
	...
	'AIClient' => Marchie\MSApplicationInsightsLaravel\Facades\MSApplicationInsightsClientFacade::class,
	'AIServer' => Marchie\MSApplicationInsightsLaravel\Facades\MSApplicationInsightsServerFacade::class,
	...
]
```

Usage
-----

[](#usage)

### Request Tracking Middleware

[](#request-tracking-middleware)

To monitor your application's performance with request tracking, add the middleware to your in your application, found in **app/Http/Kernel.php**. It has to be added after the StartSession middleware has been added.

```
protected $middleware = [
	...
	'MSApplicationInsightsMiddleware',
	...
]
```

The request will send the following additional properties to Application Insights:

- **ajax** *(boolean)*: *true* if the request is an AJAX request
- **ip** *(string)*: The client's IP address
- **pjax** *(boolean)*: *true* if the request is a PJAX request
- **secure** *(boolean)*: *true* if the request was sent over HTTPS
- **route** *(string)*: The name of the route, if applicable
- **user** *(integer)*: The ID of the logged in user, if applicable
- **referer** *(string)*: The HTTP\_REFERER value from the request, if available

The middleware is also used to estimate the time that a user has spent on a particular page. This is sent as a *trace* event named **browse\_duration**.

### Exception Handler

[](#exception-handler)

To report exceptions that occur in your application, use the provided exception handler. *Replace* the following line in your application's **app/Handlers/Exception.php** file:

```
...

# Delete this line
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

# Insert this line
use Marchie\MSApplicationInsightsLaravel\Handlers\MSApplicationInsightsExceptionHandler as ExceptionHandler;

...
```

The exception handler will send additional properties to Application Insights, as above.

### Client Side

[](#client-side)

In order to register page view information from the client with Application Insights, simply insert the following code into your Blade views:

```
{!! AIClient::javascript() !!}
```

NOTE: Microsoft recommend that you put the script in the `` section of your pages, in order to calculate the fullest extent of page load time on the client.

### Custom

[](#custom)

If you want to use any of the underlying [ApplicationInsights-PHP](https://github.com/Microsoft/ApplicationInsights-PHP) functionality, you can call the methods directly from the server facade:

```
...
AIServer::trackEvent('Test event');
AIServer::flush();
...
```

See the [ApplicationInsights-PHP](https://github.com/Microsoft/ApplicationInsights-PHP) page for more information on the available methods.

Version History
---------------

[](#version-history)

### 0.2.4

[](#024)

- Added try/catch blocks when flushing data to prevent RequestExceptions from killing the application if there is a problem connecting to Application Insights.

### 0.2.3

[](#023)

- Corrected dingus mistake!

### 0.2.2

[](#022)

- Added additional properties to exceptions
- Removed auto-flushing shutdown function

### 0.2.1

[](#021)

- Flush queue on exception (otherwise, if Laravel is daemonized, queue exceptions will not be reported)

### 0.2.0

[](#020)

- Server side implementation

### 0.1.2

[](#012)

- Correcting silly mistake!

### 0.1.1

[](#011)

- Empty key no longer results in an exception being thrown (no JavaScript is inserted into the view)

### 0.1.0

[](#010)

- Client-side JavaScript only

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor2

2 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 ~12 days

Recently: every ~20 days

Total

8

Last Release

3851d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2d937436e87de8280c7e7e2502a2a47122a23b7596aabd8435f6086dd4dcc2e?d=identicon)[marchie](/maintainers/marchie)

---

Top Contributors

[![enhendrickson](https://avatars.githubusercontent.com/u/2226780?v=4)](https://github.com/enhendrickson "enhendrickson (6 commits)")[![randompixel](https://avatars.githubusercontent.com/u/2316601?v=4)](https://github.com/randompixel "randompixel (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![marchie](https://avatars.githubusercontent.com/u/5711374?v=4)](https://github.com/marchie "marchie (2 commits)")[![nphmuller](https://avatars.githubusercontent.com/u/3781551?v=4)](https://github.com/nphmuller "nphmuller (2 commits)")

---

Tags

laravelloggingmonitoringmicrosoftazureApplication Insights

### Embed Badge

![Health badge](/badges/marchie-ms-application-insights-laravel/health.svg)

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

###  Alternatives

[rollbar/rollbar-laravel

Rollbar error monitoring integration for Laravel projects

14110.4M7](/packages/rollbar-rollbar-laravel)[jenssegers/raven

Sentry (Raven) error monitoring integration for Laravel projects

90197.2k1](/packages/jenssegers-raven)

PHPackages © 2026

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