Package Data | |
---|---|
Maintainer Username: | marchie |
Maintainer Contact: | marchie@marchie.net (Chris March) |
Package Create Date: | 2015-07-29 |
Package Last Update: | 2023-11-21 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:03:34 |
Package Statistics | |
---|---|
Total Downloads: | 4,039 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 13 |
Total Watchers: | 3 |
Total Forks: | 23 |
Total Open Issues: | 6 |
A simple Laravel implementation for Microsoft Application Insights
Update the require
section of your application's composer.json file:
"require": {
...
"marchie/ms-application-insights-laravel": "^0.2",
...
}
Add the service provider to the providers array in your application's config/app.php file:
'providers' => [
...
Marchie\MSApplicationInsightsLaravel\Providers\MSApplicationInsightsServiceProvider::class,
...
]
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,
...
]
The package will check your application's .env file for your Instrumentation Key.
Add the following to your .env file:
...
MS_INSTRUMENTATION_KEY=<your instrumentation key>
...
You can find your instrumentation key on the Microsoft Azure Portal.
Navigate to:
Microsoft Azure > Browse > Application Insights > (Application Name) > Settings > Properties
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:
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.
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.
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 <head>
section of your pages, in order to calculate the fullest extent of page load time on the client.
If you want to use any of the underlying ApplicationInsights-PHP functionality, you can call the methods directly from the server facade:
...
AIServer::trackEvent('Test event');
AIServer::flush();
...
See the ApplicationInsights-PHP page for more information on the available methods.