PHPackages                             hakantaskin/elastic-apm-php-agent - 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. hakantaskin/elastic-apm-php-agent

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

hakantaskin/elastic-apm-php-agent
=================================

A php agent for Elastic APM for php 5.3 v

09PHP

Since Jul 5Pushed 6y agoCompare

[ Source](https://github.com/hakantaskin/elastic-apm-php-agent)[ Packagist](https://packagist.org/packages/hakantaskin/elastic-apm-php-agent)[ RSS](/packages/hakantaskin-elastic-apm-php-agent/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Elastic APM: PHP Agent FOR PHP 5.3
==================================

[](#elastic-apm-php-agent-for-php-53)

[![Build Status](https://camo.githubusercontent.com/c7ada8442baac3fbaed09b3ffb6e59796380f253cba396aa18a5b4a30a973aa7/68747470733a2f2f7472617669732d63692e636f6d2f7068696c6b72612f656c61737469632d61706d2d7068702d6167656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/philkra/elastic-apm-php-agent)

This is a PHP agent for Elastic.co's APM product: . Laravel &amp; Lumen package

*Please note* that currently only the `v1` intake API of the APM server is supported, `v2` is in planing.

Installation
------------

[](#installation)

The recommended way to install the agent is through [Composer](http://getcomposer.org).

Run the following composer command

```
php composer.phar require hakantaskin/elastic-apm-php-agent
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

Usage
-----

[](#usage)

### Initialize the Agent with minimal Config

[](#initialize-the-agent-with-minimal-config)

```
$agent = new \HT\Agent(array('appName' => 'demo'));
```

When creating the agent, you can directly inject shared contexts such as user, tags and custom.

```
$agent = new \HT\Agent(array('appName' => 'with-custom-context'), array(
  'user' => array(
    'id'    => 12345,
    'email' => 'email@acme.com',
  ),
  'tags' => array(
    // ... more key-values
  ),
  'custom' => array(
    // ... more key-values
  )
) );
```

### Capture Errors and Exceptions

[](#capture-errors-and-exceptions)

The agent can capture all types or errors and exceptions that are implemented from the interface `Throwable` ().

```
$agent->captureThrowable( new Exception() );
```

### Adding spans

[](#adding-spans)

Addings spans () is easy. Please consult the documentation for your exact needs. Below is an example for adding a MySQL span.

```
$trxName = 'GET /some/transaction/name';

// create the agent
$agent = new \HT\Agent(array('appName' => 'Demo with Spans'));

// start a new transaction
$transaction = $agent->startTransaction($trxName);

// create a span
$spans = array();
$spans[] = array(
  'name' => 'Your Span Name. eg: ORM Query',
  'type' => 'db.mysql.query',
  'start' => 300, // when did tht query start, relative to the transaction start, in milliseconds
  'duration' => 23, // duration, in milliseconds
  'stacktrace' => array(
    array(
      'function' => "\\YourOrMe\\Library\\Class::methodCall()",
      'abs_path' => '/full/path/to/file.php',
      'filename' => 'file.php',
      'lineno' => 30,
      'library_frame' => false, // indicated whether this code is 'owned' by an (external) library or not
      'vars' => array(
        'arg1' => 'value',
        'arg2' => 'value2',
      ),
      'pre_context' => array( // lines of code leading to the context line
        '
