PHP code example of whchi / laravel-application-insights
1. Go to this page and download the library: Download whchi/laravel-application-insights library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
whchi / laravel-application-insights example snippets
return [
'instrumentationKey' => 'find it on Microsoft Azure portal (https://portal.azure.com)'
'initWithGuzzleHttpClient' => true, // 如果要用 event queue 則設定為 false
];
'aliases' => [
...
'AppInsights' => Whchi\LaravelApplicationInsights\Facades\AppInsights::class,
...
];
// in EventServiceProvider
protected $listen = [
'App\Events\AppInsightsLogEvent' => [
'App\Listeners\AppInsightsLogEventListener',
]
];
$appInsightsObj = \App::make('AppInsights');
$appInsightsObj->setException(['exception' => new \Exception('exception'), 'created_at' => \Carbon\Carbon::now()]);
event(new \App\Events\AppInsightsLogEvent($appInsightsObj));
AppInsights::setOperationCtx('operation id', 'operation name');
AppInsights::setDeviceInfo(string $deviceType = '裝置類型(mobile/pc...)', string $osVersion = 'default: user-agent')
AppInsights::setUserAgent(string $userAgent);
AppInsights::setIp('127.0.0.1');
AppInsights::setLocale('zh-TW');
AppInsights::setUserId('[email protected] ');
$$optional = ['properties' => ['hello' => 'world'], 'measurments' => ['duration' => 123.12]];
AppInsights::setException($
$$optional = [
'durationInMilliseconds' => 1000,
'isSuccessful' => true,
'resultCode' => 200,
'properties' => ['hello' => 'world'],
];
AppInsights::setDependency($
$$optional = [
'duration' => 1000,
'properties' => ['hello' => 'world'],
'measurments' => ['duration' => 123.12]
];
AppInsights::setPageView($
$$optional = [
'properties' => ['hello' => 'world'],
'measurments' => ['duration' => 123.12]
];
AppInsights::setEvent($
$$optional = [
'durationInMilliseconds' => 1000,
'isSuccessful' => true,
'httpResponseCode' => 200,
'properties' => ['hello' => 'world'],
'measurments' => ['duration' => 123.12]
];
AppInsights::setRequest($
$$optional = [
'type' => 0,
'count' => 124,
'min' => 10.3,
'max' => 99.2,
'stdDev' => 1233.1,
'properties' => ['hello' => 'world'],
];
AppInsights::setMetric($
$$optional = [
'level' => 0,
'properties' => ['hello' => 'world'],
];
AppInsights::setMessage($
bash
php artisan vendor:publish --provider="Whchi\LaravelApplicationInsights\AppInsightsServiceProvider"