phuocdaivl / app-insights
扩展了 Application Insights API 接口,以支持
1.0.3
2019-12-05 02:20 UTC
Requires
- microsoft/application-insights: ^0.4.5
This package is auto-updated.
Last update: 2024-09-05 12:53:33 UTC
README
Laravel 的应用洞察
此库使用 官方 Application Insights PHP API。要开始使用,您应该对 Application Insights 的工作原理有基本了解(跟踪事件、跟踪错误、跟踪页面视图、跟踪请求等)。
下载 & 安装
composer require phuocdaivl/app-insights
添加服务提供者
将服务提供者添加到配置文件 config/app.php 中的 providers 数组,如下所示
'providers' => [ ... DaiDP\AppInsights\Providers\AzureAppInsightsProvider::class, ]
做得好。
处理错误
打开文件 app/Exceptions/Handler.php 并添加以下代码
public function render($request, Exception $exception) { $telemetry = app()->get(\DaiDP\AppInsights\TelemetryClient::class); $telemetry->trackException($exception); $telemetry->flush(); ... }
记录自定义错误
- 从 try-catch 添加日志
try {
// To do something
...
} catch(\Exception $ex) {
$telemetry = app()->get(\DaiDP\AppInsights\TelemetryClient::class);
$telemetry->trackException($ex);
$telemetry->flush();
}
- 添加任何自定义日志
$ex = new Exception('Some message'); $telemetry = app()->get(\DaiDP\AppInsights\TelemetryClient::class); $telemetry->trackException($ex); $telemetry->flush();