eerzho/opentelemetry-auto-class
Framework-agnostic automatic OpenTelemetry tracing for PHP 8.2+ using #[Traceable]. Mark a class and public methods generate spans via ext-opentelemetry hook API. Supports excluding methods; Laravel/Symfony integrations available.
OrderService, PaymentGateway) where business logic resides. The #[Traceable] attribute integrates naturally with Laravel’s dependency injection and service container.app/Http/Middleware/TraceRequests).Illuminate\Queue\Jobs) without requiring manual span creation in job classes.getters/setters) to optimize.exclude), argument filtering (#[Arguments]), and manual span configuration. Can be extended for custom span attributes (e.g., #[Traceable(tags: ['team' => 'payments'])]).ext-opentelemetry (zero-code instrumentation). Conflicts possible with other OTel packages (e.g., spatie/laravel-otel). Mitigation: Use composer’s replace or conflict directives.TraceMiddleware to wrap #[Traceable] classes).traceparent headers in queue payloads). Laravel’s queue drivers (Redis, database) must support this.#[Traceable] on App\Repositories\UserRepository). Risk: May interfere with query caching or raw SQL.UserService, NotificationService).nikic/php-parser).ext-opentelemetry may conflict with Laravel’s OTel integrations (e.g., spatie/laravel-otel). Solution: Standardize on one OTel package per project.Mockery or PHPUnit extensions).X-Trace-ID headers)?#[Traceable] usage?App\Services\OrderService) with #[Traceable]. Exclude trivial methods (e.g., getters).app/Http/Middleware/TraceRequests) and wrap #[Traceable] controllers/services.traceparent headers) in queue payloads. Annotate job classes (e.g., App\Jobs\ProcessOrder).#[Traceable] on App\Repositories\UserRepository).traceparent) in HTTP clients (Guzzle, HTTP Client).#[Traceable] on App\Listeners\OrderCreated).PaymentService, OrderService).#[Traceable] to public methods.App\Providers\ObservabilityServiceProvider).TraceRequestsMiddleware to wrap #[Traceable] controllers.Route::middleware([TraceRequests::class])) for critical routes.Span API to trace Eloquent queries.nikic/php-parser for attribute support (higher maintenance).spatie/laravel-otel, decide whether to:
eerzho/opentelemetry-auto-class for class-level tracing.Mockery).| Phase | Tasks | Dependencies |
|---|---|---|
| Prep | - Install ext-opentelemetry and eerzho/opentelemetry-auto-class. |
PHP 8.2+, Laravel 9+ |
| - Set up OTel backend (e.g., Jaeger, Honeycomb). | ||
| Pilot | - Annotate 1–2 services with #[Traceable]. |
|
| - Register instrumentation in a service provider. | ||
| HTTP Integration | - Add TraceRequestsMiddleware. |
Pilot phase |
| Async Workflows | - Annotate job/event classes. | HTTP integration |
| Database | - (Optional) Instrument repositories or correlate queries. | Async workflows |
| Monitoring | - Set up alerts for missing/failed spans. | All phases |
eerzho/opentelemetry-auto-class for OTel SDK compatibility changes.How can I help you explore Laravel packages today?