app-insights-php/monolog-handler
最新稳定版本:0.3.1
Composer 安装命令:
composer require app-insights-php/monolog-handler
包简介
Microsoft App Insights monolog handler
README 文档
README
It provides to monolog handlers for AppInsights: for tracking dependency (AppInsightsDependencyHandler) and traces (AppInsightsTraceHandler).
Long running processes
It might be tricky to find a proper moment to flush everything to AppInsights for long running processes (e.g: consumers). One of the solution might be a Buffer Handler. You can easily wrap both handlers by Buffer Handler and set up an overflow buffer. They are designed to flush everything into AppInsight's when a buffer overflows.
Limitations
Size of the telemetry is limited to 64 kilobytes. Handlers checks the length of the telemetry before adding it to the AppInsights Client's queue. If it exceeds the limit it won't be added! It means that AppInsights should not be the only source for your data. You should always have a copy somewhere else where you don't have such limitations.
Usage example in Laravel:
- Update config/logging.php with a new entry:
'appinsights' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => \AppInsightsPHP\Monolog\Handler\AppInsightsTraceHandler::class,
'formatter' => \AppInsightsPHP\Monolog\Formatter\ContextFlatterFormatter::class
],
- Register a new service provider
php artisan make:provider AppInsightsLogProvider
2.1 Register servicer provider dependencies for the log handler in the boot() method.
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->app->bind(
AppInsightsTraceHandler::class,
function ($app) {
$telemetryClient = new \ApplicationInsights\Telemetry_Client();
$context = $telemetryClient->getContext();
$context->setInstrumentationKey(env('APPINSIGHTS_INSTRUMENTATIONKEY'));
/** @var CacheManager $cacheManager */
$failureCache = new FailureCache(Cache::repository(new NullStore()));
/** @var Logger $defaultLogger */
$defaultLogger = Log::getFacadeRoot();
$client = new Client($telemetryClient, Configuration::createDefault(), $failureCache, $defaultLogger);
$handler = new AppInsightsTraceHandler($client);
return $handler;
}
);
app-insights-php/monolog-handler 适用场景与选型建议
app-insights-php/monolog-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 391.56k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 app-insights-php/monolog-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 app-insights-php/monolog-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 391.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04