Application Insight for Larvel
This library uses the official Application Insights PHP API. To get started, you should have a basic knowledge of how Application Insights works (Tracking Event, Tracking Error, Tracking PageView, Tracking Request, ...).
composer require phuocdaivl/app-insights
Add the service provider to the providers array in the config/app.php
config file as follows:
'providers' => [
...
DaiDP\AppInsights\Providers\AzureAppInsightsProvider::class,
]
Well done.
Open file app/Exceptions/Handler.php
and add following code:
public function render($request, Exception $exception)
{
$telemetry = app()->get(\DaiDP\AppInsights\TelemetryClient::class);
$telemetry->trackException($exception);
$telemetry->flush();
...
}
- Add log from try catch
try {
// To do something
...
} catch(\Exception $ex) {
$telemetry = app()->get(\DaiDP\AppInsights\TelemetryClient::class);
$telemetry->trackException($ex);
$telemetry->flush();
}
- Add any customize log
$ex = new Exception('Some message');
$telemetry = app()->get(\DaiDP\AppInsights\TelemetryClient::class);
$telemetry->trackException($ex);
$telemetry->flush();