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

ActiveLibrary

ivoglent/elastic-apm-php-agent
==============================

A php agent for Elastic APM

6.6.13(6y ago)03.9k2MITPHPPHP &gt;= 7.1

Since Feb 2Pushed 6y ago1 watchersCompare

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

READMEChangelogDependencies (6)Versions (39)Used By (0)

Elastic APM: PHP Agent
======================

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

---

**Please note 1:** This is not an official Elastic APM agent, the PHP APM agent is a [community developed agent](https://github.com/elastic/apm-contrib#community-developed-agents). **Please note 2:** This is a forked repository from [original repo](https://github.com/philkra/elastic-apm-php-agent). But I've modified too many things so I can not create PR to merge it back :). Anyway, thank to @philkra.

---

This is a PHP agent for Elastic.co's APM product: . **It's working on v2 APM' apis only**.

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

[](#installation)

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

Run the following composer command

```
php composer.phar require ivoglent/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)

```
$config = [
    'name' => 'Service Name',
    'secretToken' => 'APM api token',
    'transport' => [
        'host' => 'APM server host',
        'config' => [
            'base_uri' => 'base URL to APM server',
        ],
    ],
    'framework' => [
        'name' => 'Framework Name',
        'version' => 'Framework version',
    ]
];
$contexts = [
    'user' => [
        'id' => 'USER_ID',
        'username' => 'USER_NAME',
        'email' => 'EMAIL'
    ]
];
$agent = new \PhilKra\Agent($config, $contexts);
```

### 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` ().

```
$error = $agent->factory()->newError(new \Exception());
$error->setTransaction($transaction);
$error->setParentId($transaction->getId());
$agent->register($error);
```

### Usage of transaction and spans

[](#usage-of-transaction-and-spans)

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

```
//Create APM agent
$agent = new \PhilKra\Agent($config, $contexts);

//Create new transaction
$transaction = $agent->factory()->newTransaction($transactionName, $transactionType);
//Start current transaction
$transaction->start();

//Create new span
$span = $agent->factory()->newSpan($spanName, $spanType, $spanAction);
$span->setTransaction($transaction);
$span->setParentId($transaction->getId());

//Start span
$span->start();

//Add sql context to span
$context = new \PhilKra\Traces\SpanContexts\SpanContext();
$context->statement = 'SQL Query String';
$trace->addContext('db', $context);

//Stop span
$span->stop();

//Register span to agent
$agent->register($span);

//Stop transaction
$transaction->stop();

//Register transaction to agent
$agent->register($transaction);

//Send all data to APM server
$agent->send();
```

Tests
-----

[](#tests)

```
vendor/bin/phpunit
```

Knowledgebase
-------------

[](#knowledgebase)

### Disable Agent for CLI

[](#disable-agent-for-cli)

In case you want to disable the agent dynamically for hybrid SAPI usage, please use the following snippet.

```
'active' => PHP_SAPI !== 'cli'
```

In case for the Laravel APM provider:

```
'active' => PHP_SAPI !== 'cli' && env('ELASTIC_APM_ACTIVE', false)
```

Thank you to @jblotus, ([philkra/elastic-apm-laravel#19](https://github.com/philkra/elastic-apm-laravel/issues/19))

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~17 days

Recently: every ~8 days

Total

37

Last Release

2390d ago

Major Versions

0.1.2 → 6.2.02018-06-09

PHP version history (2 changes)0.1.2PHP &gt;= 7.0

6.5.9-alphaPHP &gt;= 7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/648b0a3019094426579d72fcbcdc0d88b7398dbface60d53a25f73c6b0c2538c?d=identicon)[ivoglent](/maintainers/ivoglent)

---

Top Contributors

[![philkra](https://avatars.githubusercontent.com/u/35487337?v=4)](https://github.com/philkra "philkra (58 commits)")[![tepeds](https://avatars.githubusercontent.com/u/162032891?v=4)](https://github.com/tepeds "tepeds (17 commits)")[![ivoglent](https://avatars.githubusercontent.com/u/4499973?v=4)](https://github.com/ivoglent "ivoglent (12 commits)")[![georgeboot](https://avatars.githubusercontent.com/u/884482?v=4)](https://github.com/georgeboot "georgeboot (12 commits)")[![thinkspill](https://avatars.githubusercontent.com/u/822133?v=4)](https://github.com/thinkspill "thinkspill (5 commits)")[![kankje](https://avatars.githubusercontent.com/u/5406982?v=4)](https://github.com/kankje "kankje (3 commits)")[![iainmckay](https://avatars.githubusercontent.com/u/1223726?v=4)](https://github.com/iainmckay "iainmckay (2 commits)")[![flexer23](https://avatars.githubusercontent.com/u/13817810?v=4)](https://github.com/flexer23 "flexer23 (2 commits)")[![eddycjy](https://avatars.githubusercontent.com/u/13746731?v=4)](https://github.com/eddycjy "eddycjy (2 commits)")[![L00Cyph3r](https://avatars.githubusercontent.com/u/10772371?v=4)](https://github.com/L00Cyph3r "L00Cyph3r (1 commits)")[![matthieutirelli](https://avatars.githubusercontent.com/u/25278098?v=4)](https://github.com/matthieutirelli "matthieutirelli (1 commits)")[![nishimura](https://avatars.githubusercontent.com/u/146196?v=4)](https://github.com/nishimura "nishimura (1 commits)")[![gueroverde](https://avatars.githubusercontent.com/u/1765489?v=4)](https://github.com/gueroverde "gueroverde (1 commits)")[![ricco24](https://avatars.githubusercontent.com/u/1409647?v=4)](https://github.com/ricco24 "ricco24 (1 commits)")[![strayobject](https://avatars.githubusercontent.com/u/2257473?v=4)](https://github.com/strayobject "strayobject (1 commits)")[![jblotus](https://avatars.githubusercontent.com/u/382230?v=4)](https://github.com/jblotus "jblotus (1 commits)")[![dstepe](https://avatars.githubusercontent.com/u/2804725?v=4)](https://github.com/dstepe "dstepe (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ivoglent-elastic-apm-php-agent/health.svg)

```
[![Health](https://phpackages.com/badges/ivoglent-elastic-apm-php-agent/health.svg)](https://phpackages.com/packages/ivoglent-elastic-apm-php-agent)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[google/cloud

Google Cloud Client Library

1.2k16.2M54](/packages/google-cloud)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[getdkan/dkan

DKAN Open Data Catalog

385135.4k2](/packages/getdkan-dkan)[torchlight/torchlight-laravel

A Laravel Client for Torchlight, the syntax highlighting API.

120452.8k11](/packages/torchlight-torchlight-laravel)

PHPackages © 2026

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