2017 © Pedro Peláez
 

library ms-application-insights-laravel

Microsoft Azure Application Insights for Laravel 5

image

marchie/ms-application-insights-laravel

Microsoft Azure Application Insights for Laravel 5

  • Tuesday, October 27, 2015
  • by marchie
  • Repository
  • 1 Watchers
  • 3 Stars
  • 631 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 9 Versions
  • 10 % Grown

The README.md

Microsoft Application Insights for Laravel 5

A simple Laravel implementation for Microsoft Application Insights, (*1)

Installation

Update the require section of your application's composer.json file:, (*2)

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

Instrumentation Key

The package will check your application's .env file for your Instrumentation Key., (*3)

Add the following to your .env file:, (*4)

...
MS_INSTRUMENTATION_KEY=<your instrumentation key>
...

You can find your instrumentation key on the Microsoft Azure Portal., (*5)

Navigate to:, (*6)

Microsoft Azure > Browse > Application Insights > (Application Name) > Settings > Properties, (*7)

On Laravel versions without Auto-Discovery (< 5.5):

Service Provider

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

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

Facade

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

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

Usage

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., (*10)


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

The request will send the following additional properties to Application Insights:, (*11)

  • 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., (*12)

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:, (*13)

...

# 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., (*14)

Client Side

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

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

NOTE: Microsoft recommend that you put the script in the <head> section of your pages, in order to calculate the fullest extent of page load time on the client., (*16)

Custom

If you want to use any of the underlying ApplicationInsights-PHP functionality, you can call the methods directly from the server facade:, (*17)

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

See the ApplicationInsights-PHP page for more information on the available methods., (*18)

Version History

0.2.4

  • 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

  • Corrected dingus mistake!

0.2.2

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

0.2.1

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

0.2.0

  • Server side implementation

0.1.2

  • Correcting silly mistake!

0.1.1

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

0.1.0

  • Client-side JavaScript only

The Versions

27/10 2015

dev-master

9999999-dev

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

27/10 2015

v0.2.4

0.2.4.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

16/09 2015

v0.2.3

0.2.3.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

09/09 2015

v0.2.2

0.2.2.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

01/09 2015

v0.2.1

0.2.1.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

07/08 2015

v0.2.0

0.2.0.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

29/07 2015

v0.1.2

0.1.2.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

29/07 2015

v0.1.1

0.1.1.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel logging azure microsoft monitoring application insights

29/07 2015

v0.1

0.1.0.0

Microsoft Azure Application Insights for Laravel 5

  Sources   Download

The Requires

 

The Development Requires

laravel logging azure microsoft monitoring application insights