phuocdaivl/app-insights

Extends the Application Insights API surface to support

1.0.3 2019-12-05 02:20 UTC

This package is auto-updated.

Last update: 2024-05-05 11:55:53 UTC


README

Application Insight for Larvel

Latest Version on Packagist Software License Build Status Total Downloads

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, ...).

Download & Install

composer require phuocdaivl/app-insights

Add service provider

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.

Handle Error

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();
    
    ...
}

Log customize error

  • 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();