PHPackages                             whchi/laravel-application-insights - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. whchi/laravel-application-insights

Abandoned → [whchi/laravel-application-insights](/?search=whchi%2Flaravel-application-insights)ArchivedLibrary[Logging &amp; Monitoring](/categories/logging)

whchi/laravel-application-insights
==================================

send log into Microsoft application insights

0.0.1(5y ago)03MITPHPPHP &gt;=7.1

Since Jun 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/whchi/laravel-application-insights)[ Packagist](https://packagist.org/packages/whchi/laravel-application-insights)[ RSS](/packages/whchi-laravel-application-insights/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

A wrapper of [ApplicationInsights-PHP](https://github.com/Microsoft/ApplicationInsights-PHP)

Reference: [ms-application-insights-laravel](https://github.com/Marchie/ms-application-insights-laravel)

Installation
============

[](#installation)

1. require package

```
composer require whchi/application-insights
```

2. publish vendor

```
php artisan vendor:publish --provider="Whchi\LaravelApplicationInsights\AppInsightsServiceProvider"
```

3. setup config `config/appinsights.php`

```
return [
    'instrumentationKey' => 'find it on Microsoft Azure portal (https://portal.azure.com)'
    'initWithGuzzleHttpClient' => true, // 如果要用 event queue 則設定為 false
];
```

4. start use

- with facade

```
'aliases' => [
   ...
   'AppInsights' => Whchi\LaravelApplicationInsights\Facades\AppInsights::class,
   ...
 ];
```

- with event queue

add event listener

```
// in EventServiceProvider
 protected $listen = [
      'App\Events\AppInsightsLogEvent' => [
          'App\Listeners\AppInsightsLogEventListener',
      ]
  ];
```

trigger event queue

```
$appInsightsObj = \App::make('AppInsights');
$appInsightsObj->setException(['exception' => new \Exception('exception'), 'created_at' => \Carbon\Carbon::now()]);
event(new \App\Events\AppInsightsLogEvent($appInsightsObj));
```

Usage
=====

[](#usage)

### use native methods

[](#use-native-methods)

see: [ApplicationInsights-PHP](https://github.com/Microsoft/ApplicationInsights-PHP)

### use wrap method

[](#use-wrap-method)

### 設定 operation context (MUST if use setRequest)

[](#設定-operation-context-must-if-use-setrequest)

```
AppInsights::setOperationCtx('operation id', 'operation name');
```

#### 設定裝置資訊 (SHOULD)

[](#設定裝置資訊-should)

```
AppInsights::setDeviceInfo(string $deviceType = '裝置類型(mobile/pc...)', string $osVersion = 'default: user-agent')
```

#### 設定 User-Agent (SHOULD), default: $\_SERVER\['HTTP\_USER\_AGENT'\]

[](#設定-user-agent-should-default-_serverhttp_user_agent)

```
AppInsights::setUserAgent(string $userAgent);
```

#### 設定ip (SHOULD)

[](#設定ip-should)

```
AppInsights::setIp('127.0.0.1');
```

#### 設定locale (SHOULD)

[](#設定locale-should)

比照 [RFC5646](https://tools.ietf.org/html/rfc5646)

```
AppInsights::setLocale('zh-TW');
```

#### 設定 userId (SHOULD)

[](#設定-userid-should)

```
AppInsights::setUserId('testuser@example.com');
```

### 發送log

[](#發送log)

#### exception

[](#exception)

```
$required = ['exception' => new \Exception('exception'), 'created_at' => \Carbon\Carbon::now()];
$optional = ['properties' => ['hello' => 'world'], 'measurments' => ['duration' => 123.12]];
AppInsights::setException($required + $optional);
AppInsights::send();
```

#### dependency

[](#dependency)

這個是屬於比較彈性的部分，可自定義類別提供資料，參考[微軟官方文件說明](https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-dependencies)

```
$required = ['name' => 'an identifier', 'type' => 'SQL', 'commandName' => 'SELECT * FROM TABLE', 'created_at' => \Carbon\Carbon::now()];
$optional = [
  'durationInMilliseconds' => 1000,
  'isSuccessful' => true,
  'resultCode' => 200,
  'properties' => ['hello' => 'world'],
];
AppInsights::setDependency($required + $optional);
AppInsights::send();
```

#### page view

[](#page-view)

```
$required = ['name' => 'an identifier', 'uri' => 'https://example.com/', 'created_at' => \Carbon\Carbon::now()];
$optional = [
  'duration' => 1000,
  'properties' => ['hello' => 'world'],
  'measurments' => ['duration' => 123.12]
];
AppInsights::setPageView($required + $optional);
AppInsights::send();
```

#### event

[](#event)

```
$required = ['event' => 'an identifier', 'created_at' => \Carbon\Carbon::now()];
$optional = [
  'properties' => ['hello' => 'world'],
  'measurments' => ['duration' => 123.12]
];
AppInsights::setEvent($required + $optional);
AppInsights::send();
```

#### request

[](#request)

```
$required = ['name' => 'an identifier', 'uri' => 'https://example.com/', 'created_at' => \Carbon\Carbon::now()];
$optional = [
  'durationInMilliseconds' => 1000,
  'isSuccessful' => true,
  'httpResponseCode' => 200,
  'properties' => ['hello' => 'world'],
  'measurments' => ['duration' => 123.12]
];
AppInsights::setRequest($required + $optional);
AppInsights::send();
```

#### metric

[](#metric)

自訂義的衡量標準，比如說在程式執行速度或是經過的class數量等，`stdDev`為標準差

type描述0Measurement1Aggregation```
$required = ['name' => 'an identifier', 'value' => 42.1, 'created_at' => \Carbon\Carbon::now()];
$optional = [
  'type' => 0,
  'count' => 124,
  'min' => 10.3,
  'max' => 99.2,
  'stdDev' => 1233.1,
  'properties' => ['hello' => 'world'],
];
AppInsights::setMetric($required + $optional);
AppInsights::send();
```

#### message

[](#message)

level描述0verbose1information2warning3error4critical```
$required = ['message' => 'message to send', 'created_at' => \Carbon\Carbon::now()];
$optional = [
  'level' => 0,
  'properties' => ['hello' => 'world'],
];
AppInsights::setMessage($required + $optional);
AppInsights::send();
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2163d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2dc92c7e48b95b84282bf4c3bc9f04eef31bd8117484fe862812082c55217026?d=identicon)[whchi](/maintainers/whchi)

---

Top Contributors

[![whchi](https://avatars.githubusercontent.com/u/11798731?v=4)](https://github.com/whchi "whchi (2 commits)")

### Embed Badge

![Health badge](/badges/whchi-laravel-application-insights/health.svg)

```
[![Health](https://phpackages.com/badges/whchi-laravel-application-insights/health.svg)](https://phpackages.com/packages/whchi-laravel-application-insights)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
