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

Abandoned → [philkra/elastic-apm-php-agent](/?search=philkra%2Felastic-apm-php-agent)Library[Logging &amp; Monitoring](/categories/logging)

samuelbednarcik/elastic-apm-agent
=================================

PHP Agent for Elastic APM

v0.2.1(7y ago)102.1k1[1 issues](https://github.com/samuelbednarcik/elastic-apm-php-agent/issues)2MITPHPPHP &gt;=7.2

Since Nov 20Pushed 5y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (5)Versions (5)Used By (2)

Elastic APM PHP agent
=====================

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

[![Packagist](https://camo.githubusercontent.com/78f489af3e15fb668101c4e25c0052890f4127147c294e1c24135bc5bf270fa9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d75656c6265646e617263696b2f656c61737469632d61706d2d6167656e742e737667)](https://packagist.org/packages/samuelbednarcik/elastic-apm-agent)[![Scrutinizer](https://camo.githubusercontent.com/4da4f17ac4fcc051cc6bcbc82d796ea1772aed2dd169ae73c42e89df5ad6842a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73616d75656c6265646e617263696b2f656c61737469632d61706d2d7068702d6167656e742e737667)](https://scrutinizer-ci.com/g/samuelbednarcik/elastic-apm-php-agent/)[![PHP from Packagist](https://camo.githubusercontent.com/612c89b246ca9a0a1c337cd2994c0a22371c2b50a7600f1091604514c02c7efb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616d75656c6265646e617263696b2f656c61737469632d61706d2d6167656e742e737667)](https://camo.githubusercontent.com/612c89b246ca9a0a1c337cd2994c0a22371c2b50a7600f1091604514c02c7efb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616d75656c6265646e617263696b2f656c61737469632d61706d2d6167656e742e737667)

Unofficial PHP agent for [Elastic APM](https://www.elastic.co/solutions/apm) (&gt;=6.5). **It is no longer maintained, use [this](https://github.com/philkra/elastic-apm-php-agent) package instead.**

This package also ships with the helpers for easy integration with your existing project and libraries like Doctrine, Guzzle etc.

**Collectors:**

- [guzzle](https://github.com/samuelbednarcik/guzzle-elastic-apm-collector)
- [doctrine](https://github.com/samuelbednarcik/doctrine-elastic-apm-collector)

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

[](#installation)

```
composer require samuelbednarcik/elastic-apm-agent
```

Usage
-----

[](#usage)

Create an agent configuration object

```
$config = new AgentConfiguration();
$config->setServiceName('name-of-your-project');
$config->setServerUrl('http://localhost:8200'); // elastic apm server

// create metadata which will be applied to the transaction
$metadata = new Metadata();
$metadata->setService(
    MetadataBuilder::buildService($config->getServiceName())
);
$config->setMetadata($metadata);
```

Create an agent instance

```
$agent = new Agent(
    $config,
    new Client(),
    new ElasticAPMSerializer()
);
```

Call start method as soon as possible in your code. Request start time is retrieved from the **REQUEST\_TIME\_FLOAT** server variable. If you don't provide a request instance, it will be created from the global variables. Start method will also return a transaction instance.

```
$transaction = $agent->start($request);
```

Call stop function at the end of the code. Optionally, if you are using symfony request/response, you can use transaction builder to generate a context for the transaction. By calling the stop method, all spans from collectors will be collected. This function will also return a transaction.

```
$transaction = $agent->stop();
$transaction->setContext(
    TransactionBuilder::buildContext($request, $response)
);
```

After that, you can call sendAll method which will send all informations to APM server.

```
try {
    $agent->sendAll();
} catch (GuzzleException $e) {
    // log an error
}
```

Span Collectors
---------------

[](#span-collectors)

Span collectors are used for extracting informations about events which happens in the external libraries like doctrine or guzzle.

You can register collectors when creating an agent instance

```
$agent = new Agent(
    $config,
    new Client(),
    new ElasticAPMSerializer(),
    [
        new MyCollector()
    ]
);
```

Agent will collect spans from all registered collectors after calling the stop method.

Distributed tracing
-------------------

[](#distributed-tracing)

Distributed tracing headers are automatically handled by the agent, the only thing you have to do is to send `elastic-traceparent-header` in request which you want to track.

```
$traceparent = new TraceParent(
    $transaction->getTraceId(),
    $transaction->getId(),
    '01'
);

$request->withHeader(
    TraceParent::HEADER_NAME,
    $traceparent->__toString()
);
```

If you are using Guzzle client, you can use `TracingGuzzleMiddleware`which will inject header for you.

```
$middleware = new TracingGuzzleMiddleware($agent)

$stack = HandlerStack::create();
$stack->push($middleware());
$client = new Client(['handler' => $stack])
```

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% 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

Every ~0 days

Total

3

Last Release

2729d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e2b32de8d5cfe6d0a02138a9f62af7918573c567f79899a1609e3e648bc1c8cf?d=identicon)[samuelbednarcik](/maintainers/samuelbednarcik)

---

Top Contributors

[![samuelbednarcik](https://avatars.githubusercontent.com/u/10451708?v=4)](https://github.com/samuelbednarcik "samuelbednarcik (13 commits)")[![themark147](https://avatars.githubusercontent.com/u/17779619?v=4)](https://github.com/themark147 "themark147 (1 commits)")

---

Tags

apm-clientelasticsearch

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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