定制 marchie/ms-application-insights-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marchie/ms-application-insights-laravel

Composer 安装命令:

composer require marchie/ms-application-insights-laravel

包简介

Microsoft Azure Application Insights for Laravel 5

README 文档

README

A simple Laravel implementation for Microsoft Application Insights

Installation

Update the require section of your application's composer.json file:

"require": {
	...
	"marchie/ms-application-insights-laravel": "^0.2",
	...
}

Instrumentation Key

The package will check your application's .env file for your Instrumentation Key.

Add the following to your .env file:

...
MS_INSTRUMENTATION_KEY=<your instrumentation key>
...

You can find your instrumentation key on the Microsoft Azure Portal.

Navigate to:

Microsoft Azure > Browse > Application Insights > (Application Name) > Settings > Properties

On Laravel versions without Auto-Discovery (< 5.5):

Service Provider

Add the service provider to the providers array in your application's config/app.php file:

'providers' => [
	...
	Marchie\MSApplicationInsightsLaravel\Providers\MSApplicationInsightsServiceProvider::class,
	...
]

Facade

Add the facades to the aliases array in your application's config/app.php file:

'aliases' => [
	...
	'AIClient' => Marchie\MSApplicationInsightsLaravel\Facades\MSApplicationInsightsClientFacade::class,
	'AIServer' => Marchie\MSApplicationInsightsLaravel\Facades\MSApplicationInsightsServerFacade::class,
	...
]

Usage

Request Tracking Middleware

To monitor your application's performance with request tracking, add the middleware to your in your application, found in app/Http/Kernel.php. It has to be added after the StartSession middleware has been added.

protected $middleware = [
	...
	'MSApplicationInsightsMiddleware',
	...
]

The request will send the following additional properties to Application Insights:

  • ajax (boolean): true if the request is an AJAX request
  • ip (string): The client's IP address
  • pjax (boolean): true if the request is a PJAX request
  • secure (boolean): true if the request was sent over HTTPS
  • route (string): The name of the route, if applicable
  • user (integer): The ID of the logged in user, if applicable
  • referer (string): The HTTP_REFERER value from the request, if available

The middleware is also used to estimate the time that a user has spent on a particular page. This is sent as a trace event named browse_duration.

Exception Handler

To report exceptions that occur in your application, use the provided exception handler. Replace the following line in your application's app/Handlers/Exception.php file:

...

# Delete this line
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

# Insert this line
use Marchie\MSApplicationInsightsLaravel\Handlers\MSApplicationInsightsExceptionHandler as ExceptionHandler;

...

The exception handler will send additional properties to Application Insights, as above.

Client Side

In order to register page view information from the client with Application Insights, simply insert the following code into your Blade views:

{!! AIClient::javascript() !!}

NOTE: Microsoft recommend that you put the script in the <head> section of your pages, in order to calculate the fullest extent of page load time on the client.

Custom

If you want to use any of the underlying ApplicationInsights-PHP functionality, you can call the methods directly from the server facade:

...
AIServer::trackEvent('Test event');
AIServer::flush();
...

See the ApplicationInsights-PHP page for more information on the available methods.

Version History

0.2.4

  • Added try/catch blocks when flushing data to prevent RequestExceptions from killing the application if there is a problem connecting to Application Insights.

0.2.3

  • Corrected dingus mistake!

0.2.2

  • Added additional properties to exceptions
  • Removed auto-flushing shutdown function

0.2.1

  • Flush queue on exception (otherwise, if Laravel is daemonized, queue exceptions will not be reported)

0.2.0

  • Server side implementation

0.1.2

  • Correcting silly mistake!

0.1.1

  • Empty key no longer results in an exception being thrown (no JavaScript is inserted into the view)

0.1.0

  • Client-side JavaScript only

marchie/ms-application-insights-laravel 适用场景与选型建议

marchie/ms-application-insights-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.05k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2015 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「logging」 「monitoring」 「azure」 「laravel」 「microsoft」 「Application Insights」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 marchie/ms-application-insights-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 marchie/ms-application-insights-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 marchie/ms-application-insights-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-29