eerzho/opentelemetry-auto-class-laravel

Trace what your Laravel methods received, returned, and threw — without writing a single span.

Maintainers

Package info

github.com/eerzho/opentelemetry-auto-class-laravel

pkg:composer/eerzho/opentelemetry-auto-class-laravel

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.5.1 2026-07-20 19:44 UTC

This package is auto-updated.

Last update: 2026-07-20 21:57:50 UTC


README

Version Downloads PHP License

Trace what your Laravel methods received, returned, and threw — without writing a single span.

The Laravel integration for opentelemetry-auto-class — your classes are discovered and registered automatically.

This is a read-only sub-split. Please open issues and pull requests in the monorepo.

Installation

composer require eerzho/opentelemetry-auto-class-laravel

Requirements:

Configuration

Scanned namespaces default to App\. To customize, publish the config:

php artisan vendor:publish --tag=trace-config
// config/trace.php
return [
    'namespaces' => [
        'App\\Services\\',
        'App\\Jobs\\',
        'Domain\\',
    ],
];

Usage

Add #[Trace] to any class in a scanned namespace:

namespace App\Services;

use Eerzho\Instrumentation\Class\Attribute\Trace;
use Eerzho\Instrumentation\Class\Attribute\TraceMethod;
use Eerzho\Instrumentation\Class\Attribute\TraceProperties;

#[Trace]                                   // mark the class for tracing
class OrderService
{
    // span "App\Services\OrderService::pay"
    #[TraceMethod(exclude: ['card'])]   // hide "card" from the span
    public function pay(int $orderId, string $card, Address $address): void {}

    public function healthCheck(): bool {}   // no #[TraceMethod] -> not traced
}

#[TraceProperties(exclude: ['zip'])]       // expand every prop but zip
class Address
{
    public function __construct(public string $city, public string $zip) {}
}

All three attributes and their options are fully documented in the core.

How it works

On boot the service provider:

  1. Reads namespaces from config/trace.php
  2. Discovers classes in those namespaces via Composer's ClassLoader::getClassMap()
  3. Scans them for the #[Trace] attribute
  4. Registers ext-opentelemetry hooks for matched methods

Only classes present in the Composer class map are discovered — run composer dump-autoload -o in production so nothing is missed.

Disabling instrumentation

OTEL_PHP_DISABLED_INSTRUMENTATIONS=class