{"id":15102179,"url":"https://github.com/microsoft/applicationinsights-php","last_synced_at":"2025-12-16T17:36:36.991Z","repository":{"id":24020313,"uuid":"27404803","full_name":"microsoft/ApplicationInsights-PHP","owner":"microsoft","description":"Azure Application Insights SDK for PHP","archived":true,"fork":false,"pushed_at":"2020-05-17T12:04:27.000Z","size":198,"stargazers_count":109,"open_issues_count":14,"forks_count":92,"subscribers_count":92,"default_branch":"master","last_synced_at":"2024-09-25T18:48:23.116Z","etag":null,"topics":["application-insights","azure","distributed-tracing","logging","monitoring","php","sdk","telemetry"],"latest_commit_sha":null,"homepage":"https://azure.microsoft.com/services/application-insights/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-01T23:10:21.000Z","updated_at":"2024-05-31T08:22:45.000Z","dependencies_parsed_at":"2022-08-22T09:01:13.938Z","dependency_job_id":null,"html_url":"https://github.com/microsoft/ApplicationInsights-PHP","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FApplicationInsights-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FApplicationInsights-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FApplicationInsights-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2FApplicationInsights-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/ApplicationInsights-PHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219871828,"owners_count":16554457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application-insights","azure","distributed-tracing","logging","monitoring","php","sdk","telemetry"],"created_at":"2024-09-25T18:48:43.434Z","updated_at":"2025-09-27T00:31:00.277Z","avatar_url":"https://github.com/microsoft.png","language":"PHP","readme":"# Application Insights for PHP\n\n[![Build Status](https://travis-ci.org/Microsoft/ApplicationInsights-PHP.svg?branch=master)](https://travis-ci.org/Microsoft/ApplicationInsights-PHP) \n[![Packagist Pre Release](https://img.shields.io/packagist/vpre/microsoft/application-insights.svg)](https://packagist.org/packages/microsoft/application-insights)\n\nThis project extends the Application Insights API surface to support PHP.\n[Application\nInsights](https://azure.microsoft.com/services/application-insights/) is a\nservice that allows developers to keep their application available,  performing\nand succeeding. This PHP module will allow you to send telemetry of various\nkinds (event, trace, exception, etc.) to the Application Insights service where\nthey can be visualized in the Azure Portal.\n\n## Status\n\nThis SDK is NOT maintained or supported by Microsoft even though we've contributed to it in the past. Note that Azure Monitor only provides support when using the [supported SDKs](https://docs.microsoft.com/en-us/azure/azure-monitor/app/platforms#unsupported-community-sdks). We’re constantly assessing opportunities to expand our support for other languages, so follow our [GitHub Announcements](https://github.com/microsoft/ApplicationInsights-Announcements/issues) page to receive the latest SDK news.\n\n## Requirements\n\nPHP version \u003e=5.4.2 is supported.\n\nFor opening the project in Microsoft Visual Studio you will need [PHP Tools for Visual Studio](https://www.devsense.com/products/php-tools). This is not required however.\n\n## Installation\n\nWe've published a package you can find on [Packagist](https://packagist.org/packages/microsoft/application-insights). In order to use it, first, you'll need to get [Composer](https://getcomposer.org/).\n\nOnce you've setup your project to use Composer, just add a reference to our package with whichever version you'd like to use to your composer.json file.\n\n```json\nrequire: \"microsoft/application-insights\": \"*\"\n```\n\nOr you can use the composer command to automatically add the package to your composer.json file.\n\n```json\ncomposer require microsoft/application-insights\n```\n\nMake sure you add the require statement to pull in the library:\n\n```php\nrequire_once 'vendor/autoload.php';\n```\n\n## Usage\n\nOnce installed, you can send telemetry to Application Insights. Here are a few samples.\n\n\u003e**Note**: before you can send data to you will need an instrumentation key. Please see the [Getting an Application Insights Instrumentation Key](https://github.com/Microsoft/AppInsights-Home/wiki#getting-an-application-insights-instrumentation-key) section for more information.\n\n### Initializing the client and setting the instrumentation key and other optional configurations\n\n```php\n$telemetryClient = new \\ApplicationInsights\\Telemetry_Client();\n$context = $telemetryClient-\u003egetContext();\n\n// Necessary\n$context-\u003esetInstrumentationKey('YOUR INSTRUMENTATION KEY');\n\n// Optional\n$context-\u003egetSessionContext()-\u003esetId(session_id());\n$context-\u003egetUserContext()-\u003esetId('YOUR USER ID');\n$context-\u003egetApplicationContext()-\u003esetVer('YOUR VERSION');\n$context-\u003egetLocationContext()-\u003esetIp('YOUR IP');\n\n// Start tracking\n$telemetryClient-\u003etrackEvent('name of your event');\n$telemetryClient-\u003eflush();\n```\n\n### Setup Operation context\n\nFor correct Application Insights reporting you need to setup Operation Context,\nreference to Request\n\n```php\n$telemetryClient-\u003egetContext()-\u003egetOperationContext()-\u003esetId('XX');\n$telemetryClient-\u003egetContext()-\u003egetOperationContext()-\u003esetName('GET Index');\n```\n\n### Sending a simple event telemetry item with event name\n\n```php\n$telemetryClient-\u003etrackEvent('name of your event');\n$telemetryClient-\u003eflush();\n```\n\n### Sending an event telemetry item with custom properties and measurements\n\n```php\n$telemetryClient-\u003etrackEvent('name of your event', ['MyCustomProperty' =\u003e 42, 'MyCustomProperty2' =\u003e 'test'], ['duration', 42]);\n$telemetryClient-\u003eflush();\n```\n\n**Sending more than one telemetry item before sending to the service is also\nsupported; the API will batch everything until you call flush()**\n\n```php\n$telemetryClient-\u003etrackEvent('name of your event');\n$telemetryClient-\u003etrackEvent('name of your second event');\n$telemetryClient-\u003eflush();\n```\n\n### Sending a simple page view telemetry item with page name and url\n\n```php\n$telemetryClient-\u003etrackPageView('myPageView', 'http://www.foo.com');\n$telemetryClient-\u003eflush();\n```\n\n### Sending a page view telemetry item with duration, custom properties and measurements\n\n```php\n$telemetryClient-\u003etrackPageView('myPageView', 'http://www.foo.com', 256, ['InlineProperty' =\u003e 'test_value'], ['duration' =\u003e 42.0]);\n$telemetryClient-\u003eflush();\n```\n\n### Sending a simple metric telemetry item with metric name and value\n\n```php\n$telemetryClient-\u003etrackMetric('myMetric', 42.0);\n$telemetryClient-\u003eflush();\n```\n\n### Sending a metric telemetry item with point type, count, min, max, standard deviation and measurements\n\n```php\n$telemetryClient-\u003etrackMetric('myMetric', 42.0, \\ApplicationInsights\\Channel\\Contracts\\Data_Point_Type::Aggregation, 5, 0, 1, 0.2, ['InlineProperty' =\u003e 'test_value']);\n$telemetryClient-\u003eflush();\n```\n\n### Sending a simple message telemetry item with message\n\n```php\n$telemetryClient-\u003etrackMessage('myMessage', \\ApplicationInsights\\Channel\\Contracts\\Message_Severity_Level::INFORMATION, ['InlineProperty' =\u003e 'test_value']);\n$telemetryClient-\u003eflush();\n```\n\n**Sending a simple request telemetry item with request name, url and start\ntime**\n\n```php\n$telemetryClient-\u003etrackRequest('myRequest', 'http://foo.bar', time());\n$telemetryClient-\u003eflush();\n```\n\n### Sending a request telemetry item with duration, http status code, whether or not the request succeeded, custom properties and measurements\n\n```php\n$telemetryClient-\u003etrackRequest('myRequest', 'http://foo.bar', time(), 3754, 200, true, ['InlineProperty' =\u003e 'test_value'], ['duration_inner' =\u003e 42.0]);\n$telemetryClient-\u003eflush();\n```\n\n### Sending an exception telemetry, with custom properties and metrics\n\n```php\ntry\n{\n    // Do something to throw an exception\n}\ncatch (\\Exception $ex)\n{\n    $telemetryClient-\u003etrackException($ex, ['InlineProperty' =\u003e 'test_value'], ['duration_inner' =\u003e 42.0]);\n    $telemetryClient-\u003eflush();\n}\n```\n\n### Set the Client to gzip the data before sending\n\n```php\n$telemetryClient-\u003egetChannel()-\u003esetSendGzipped(true);\n```\n\n### Registering an exception handler\n\n```php\nclass Handle_Exceptions\n{\n    private $_telemetryClient;\n\n    public function __construct()\n    {\n        $this-\u003e_telemetryClient = new \\ApplicationInsights\\Telemetry_Client();\n        $this-\u003e_telemetryClient-\u003egetContext()-\u003esetInstrumentationKey('YOUR INSTRUMENTATION KEY');\n\n        set_exception_handler(array($this, 'exceptionHandler'));\n    }\n\n    function exceptionHandler(\\Exception $exception)\n    {\n        if ($exception != NULL)\n        {\n            $this-\u003e_telemetryClient-\u003etrackException($exception);\n            $this-\u003e_telemetryClient-\u003eflush();\n        }\n    }\n}\n```\n\n### Sending a successful SQL dependency telemetry item\n\n```php\n$telemetryClient-\u003etrackDependency('Query table', \"SQL\", 'SELECT * FROM table;', time(), 122, true);\n$telemetryClient-\u003eflush();\n```\n\n### Sending a failed HTTP dependency telemetry item\n\n```php\n$telemetryClient-\u003etrackDependency('method', \"HTTP\", \"http://example.com/api/method\", time(), 324, false, 503);\n$telemetryClient-\u003eflush();\n```\n\n### Sending any other kind dependency telemetry item\n\n```php\n$telemetryClient-\u003etrackDependency('Name of operation', \"service\", 'Arguments', time(), 23, true);\n$telemetryClient-\u003eflush();\n```\n\n### Changing the operation id (which links actions together)\n\n```php\n$telemetryClient-\u003etrackMetric('interestingMetric', 10);\n$telemetryClient-\u003egetContext()-\u003egetOperationContext()-\u003esetId(\\ApplicationInsights\\Channel\\Contracts\\Utils::returnGuid())\n$telemetryClient-\u003etrackMetric('differentOperationMetric', 11);\n$telemetryClient-\u003eflush();\n```\n## Code of conduct\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fapplicationinsights-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Fapplicationinsights-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fapplicationinsights-php/lists"}