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

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

cryptoman0/elastic-apm-php
==========================

elastic/apm-agent-php wrapper to push PHP application transactions to APM Server

v2.1.2(3y ago)022MITPHPPHP ^7.2|^8

Since Jul 10Pushed 3y agoCompare

[ Source](https://github.com/cryptoman0/elastic-apm-php)[ Packagist](https://packagist.org/packages/cryptoman0/elastic-apm-php)[ RSS](/packages/cryptoman0-elastic-apm-php/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (2)Versions (9)Used By (0)

Elastic APM PHP
---------------

[](#elastic-apm-php)

⚠️ **WARNING: The package dependency [`ext-elastic_apm`](https://github.com/elastic/apm-agent-php) is in development mode that pushes breaking changes now and then. Also discouraged to use in a production environment. Thus this project will unmaintained till the stability of the dependency gets resolved. Feel free to fork and change accordingly. Or use any available alternative**

Requirements
------------

[](#requirements)

- The package depends on elastic's [apm-agent-php](https://github.com/elastic/apm-agent-php) extension.
- php `^7.2`
- If want to use with Laravel, Laravel version &gt;= `6.x`.

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

[](#installation)

To install the package with composer, run:

```
composer require anik/elastic-apm-php
```

Use the appropriate version while installing if you want any specific version. Above command will install the latest available version.

### Laravel

[](#laravel)

- This package uses Laravel's auto discovery feature. But, if you still want to install, then
    1. Add `Anik\ElasticApm\Providers\ElasticApmServiceProvider::class` in your `config/app.php`'s providers array.
    2. Add `Anik\ElasticApm\Facades\Agent::class` in your `config/app.php`'s facade array.
    3. `php artisan vendor:publish` and select the provider to publish the config file in your config directory. It'll copy `elastic-apm.php` in your config directory.

### Lumen

[](#lumen)

- To install this package with your lumen, you don't need to enable **Facade**.
- Register the service provider in your `bootstrap/app.php` with `$app->register(Anik\ElasticApm\Providers\ElasticApmServiceProvider::class);`
- Copy the `elastic-apm.php` from `vendor/anik/elastic-apm-php/src/config/elastic-apm.php` in your `config/app.php` file if you want to change the configuration.
- Register the copied config file `$app->configure('elastic-apm')` in your `bootstrap/app.php`

Usage
-----

[](#usage)

Error Tracking
--------------

[](#error-tracking)

If you want to keep the records of Errors, then

- For Laravel, in your `bootstrap/app.php`,

```
// COMMENT THIS SECTION
$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);
```

```
// USE THIS SECTION FOR LARAVEL singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\Handler(new App\Exceptions\Handler($app), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});
```

```
// USE THIS SECTION FOR LARAVEL >= 8
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\HandlerThrowable(new App\Exceptions\Handler($app), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});
```

- For Lumen, in your `bootstrap/app.php`,

```
// COMMENT THIS SECTION
$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);
```

```
// USE THIS SECTION FOR LUMEN singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\Handler(new App\Exceptions\Handler(), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});
```

```
// USE THIS SECTION FOR LUMEN >= 8
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\HandlerThrowable(new App\Exceptions\Handler(), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});
```

Request Response Tracking
-------------------------

[](#request-response-tracking)

If you want to keep the records of Request received and served by your application,

- For Laravel, in your `App\Http\Kernel`'s middleware, add `Anik\ElasticApm\Middleware\RecordForegroundTransaction` class.

```
