PHPackages                             eerzho/opentelemetry-auto-class - 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. eerzho/opentelemetry-auto-class

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

eerzho/opentelemetry-auto-class
===============================

Automatic OpenTelemetry tracing for PHP methods via the #\[Traceable\] attribute

v0.1.3(1mo ago)142MITPHPPHP &gt;=8.2

Since Apr 20Pushed 5d agoCompare

[ Source](https://github.com/eerzho/opentelemetry-auto-class)[ Packagist](https://packagist.org/packages/eerzho/opentelemetry-auto-class)[ RSS](/packages/eerzho-opentelemetry-auto-class/feed)WikiDiscussions main Synced 1w ago

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

opentelemetry-auto-class
========================

[](#opentelemetry-auto-class)

[![Version](https://camo.githubusercontent.com/1200eee201477685752242096c4d2785e95a6bc82b973adaf050f0b93266fd37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6565727a686f2f6f70656e74656c656d657472792d6175746f2d636c617373)](https://packagist.org/packages/eerzho/opentelemetry-auto-class)[![Downloads](https://camo.githubusercontent.com/7a11ce401fa0f6332c68301ec5be918bec94acbda5a3758b4d6fbafa160663e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6565727a686f2f6f70656e74656c656d657472792d6175746f2d636c617373)](https://packagist.org/packages/eerzho/opentelemetry-auto-class)[![PHP](https://camo.githubusercontent.com/a40d2511f3cd03f2fec89337c831dfd3f59930ad167e63261c3649ce182502dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6565727a686f2f6f70656e74656c656d657472792d6175746f2d636c6173732f706870)](https://packagist.org/packages/eerzho/opentelemetry-auto-class)[![License](https://camo.githubusercontent.com/c4275f76049119eee5eb7cf3e6f2630c49f85e0566fc4efa9f6ed9afb75201ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6565727a686f2f6f70656e74656c656d657472792d6175746f2d636c617373)](https://packagist.org/packages/eerzho/opentelemetry-auto-class)

Automatic OpenTelemetry tracing for PHP methods via the `#[Traceable]` attribute. Framework-agnostic core — mark any class with the attribute, and spans are created automatically using the `ext-opentelemetry` hook API.

This is a read-only sub-split. Please open issues and pull requests in the [monorepo](https://github.com/eerzho/opentelemetry-auto-class-monorepo).

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

[](#installation)

```
composer require eerzho/opentelemetry-auto-class
```

Requirements:

- [ext-opentelemetry](https://opentelemetry.io/docs/zero-code/php/)
- PHP 8.2+

Usage
-----

[](#usage)

### Basic

[](#basic)

Add `#[Traceable]` to a class — all public methods will be traced automatically:

```
use Eerzho\Instrumentation\Class\Attribute\Traceable;
use Eerzho\Instrumentation\Class\AttributeScanner;
use Eerzho\Instrumentation\Class\ClassInstrumentation;

#[Traceable]
class OrderService
{
    public function create(array $items): void
    {
        // span "OrderService::create" is created automatically
    }

    public function cancel(int $orderId): void
    {
        // span "OrderService::cancel" is created automatically
    }
}

// Register instrumentation
$map = AttributeScanner::scan([OrderService::class]);
ClassInstrumentation::register($map);
```

> For Laravel and Symfony, use the framework integrations that handle class discovery automatically: [opentelemetry-auto-class-laravel](https://github.com/eerzho/opentelemetry-auto-class-laravel) / [opentelemetry-auto-class-symfony](https://github.com/eerzho/opentelemetry-auto-class-symfony)

### Exclude methods

[](#exclude-methods)

Use the `exclude` parameter to skip specific methods from tracing:

```
use Eerzho\Instrumentation\Class\Attribute\Traceable;

#[Traceable(exclude: ['healthCheck', 'getVersion'])]
class PaymentService
{
    public function charge(int $amount, string $currency): void
    {
        // traced
    }

    public function healthCheck(): bool
    {
        // NOT traced
        return true;
    }

    public function getVersion(): string
    {
        // NOT traced
        return '1.0.0';
    }
}
```

### Exclude arguments

[](#exclude-arguments)

By default, all method arguments are captured as span attributes. Use `#[Arguments(exclude: [...])]` on a method to hide sensitive parameters:

```
use Eerzho\Instrumentation\Class\Attribute\Arguments;
use Eerzho\Instrumentation\Class\Attribute\Traceable;

#[Traceable]
class AuthService
{
    #[Arguments(exclude: ['password', 'token'])]
    public function login(string $email, string $password, string $token): void
    {
        // span captures "email" attribute only
        // "password" and "token" are excluded
    }

    public function logout(int $userId): void
    {
        // span captures "userId" attribute (no exclusions)
    }
}
```

### Without attributes

[](#without-attributes)

You can register classes for tracing without using `#[Traceable]` — build the method map manually and pass it to `ClassInstrumentation::register()`:

```
class OrderService
{
    public function create(array $items, int $priority, string $note): void {}

    public function cancel(int $orderId): void {}

    public function archive(int $orderId): void {}
}
```

```
use Eerzho\Instrumentation\Class\ClassInstrumentation;

ClassInstrumentation::register([
    OrderService::class => [
        // trace with arguments, skip 'priority' (position 1)
        'create' => ['items' => 0, 'note' => 2],
        // trace without capturing arguments
        'cancel' => [],
        // 'archive' is not listed — it will NOT be traced
    ],
]);
```

Each entry maps a class to its methods, and each method to its arguments (`parameter name => position`). Methods not listed are not traced. Arguments not listed are not captured.

How it works
------------

[](#how-it-works)

Each traced method call produces a span:

- Name: `ClassName::methodName`
- Kind: `INTERNAL`

With attributes:

AttributeValue`code.function.name``ClassName::methodName``code.file.path`File where the method is defined`code.line.number`Line number of the methodMethod argumentsParameter name → serialized valueIf a method throws an exception, the span records an `exception` event and sets status to `ERROR`:

Event attributeValue`exception.type`Exception class name`exception.message`Exception message`exception.stacktrace`Full stack traceArgument serialization
----------------------

[](#argument-serialization)

Arguments are serialized to span-compatible types:

TypeResultExample`string`, `int`, `float`, `bool`As-is`"hello"`, `42`, `3.14`, `true``null``"null"``null` → `"null"``BackedEnum`Backing value`Status::Active` → `"active"`Object with `__toString()`String cast`$money` → `"100 USD"`Object without `__toString()`Class name (FQCN)`$dto` → `"App\DTO\Order"``array`JSON string`[1, 2]` → `"[1,2]"`Other (`resource`, ...)`gettype()` result`"resource"`If JSON encoding of an array fails, the value is serialized as `"array"`.

Disabling instrumentation
-------------------------

[](#disabling-instrumentation)

To disable tracing at runtime, use the standard OpenTelemetry environment variable:

```
OTEL_PHP_DISABLED_INSTRUMENTATIONS=class
```

Limitations
-----------

[](#limitations)

- Only **public** methods are traced (protected and private are ignored)
- Abstract classes, interfaces, traits, and enums are skipped
- Requires `ext-opentelemetry` installed and loaded

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance95

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

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

4

Last Release

49d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f1db695a51a4fcdbee1067af7f1bdbd1bfd11916789994f36d3b2ba2b2e4466?d=identicon)[eerzho](/maintainers/eerzho)

---

Top Contributors

[![eerzho](https://avatars.githubusercontent.com/u/56928699?v=4)](https://github.com/eerzho "eerzho (7 commits)")

---

Tags

apmauto-instrumentationdistributed-tracinginstrumentationmonitoringobservabilityopentelemetryotelphp-attributesspanstelemetrytracestracingmonitoringapmtracingopentelemetryoteltelemetryobservabilityinstrumentationdistributed-tracingtracesphp-attributesspansauto-instrumentation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eerzho-opentelemetry-auto-class/health.svg)

```
[![Health](https://phpackages.com/badges/eerzho-opentelemetry-auto-class/health.svg)](https://phpackages.com/packages/eerzho-opentelemetry-auto-class)
```

###  Alternatives

[open-telemetry/opentelemetry-auto-laravel

OpenTelemetry auto-instrumentation for Laravel

582.4M8](/packages/open-telemetry-opentelemetry-auto-laravel)[open-telemetry/opentelemetry-auto-symfony

OpenTelemetry auto-instrumentation for Symfony

561.5M3](/packages/open-telemetry-opentelemetry-auto-symfony)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M315](/packages/open-telemetry-sdk)[open-telemetry/opentelemetry-auto-pdo

OpenTelemetry auto-instrumentation for PDO

111.5M2](/packages/open-telemetry-opentelemetry-auto-pdo)[traceway/opentelemetry-symfony

Pure-PHP OpenTelemetry instrumentation for Symfony — automatic HTTP, Console, HttpClient, Messenger, Doctrine DBAL, Cache, Twig tracing and Monolog log-trace correlation with response propagation, a lightweight Tracing helper, route templates, and semantic conventions. No C extension required (ext-protobuf recommended for production).

724.6k](/packages/traceway-opentelemetry-symfony)[open-telemetry/opentelemetry-auto-wordpress

OpenTelemetry auto-instrumentation for Wordpress

17194.7k](/packages/open-telemetry-opentelemetry-auto-wordpress)

PHPackages © 2026

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