Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Opentelemetry Auto Class Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Observability-Driven Development: The package excels in automating distributed tracing for Laravel applications, reducing manual instrumentation effort while adhering to OpenTelemetry (OTel) standards. It aligns with modern observability practices, particularly for microservices, event-driven architectures, or high-complexity workflows (e.g., order processing, payment systems).
  • Laravel Synergy:
    • Service Layer: Ideal for tracing Laravel’s service classes (e.g., OrderService, PaymentGateway) where business logic resides. The #[Traceable] attribute integrates naturally with Laravel’s dependency injection and service container.
    • HTTP Layer: Complements Laravel’s middleware pipeline for request/response tracing, though manual spans may still be needed for custom logic (e.g., app/Http/Middleware/TraceRequests).
    • Queues/Jobs: Automatically traces async operations (e.g., Illuminate\Queue\Jobs) without requiring manual span creation in job classes.
  • Performance Considerations:
    • Overhead: Minimal runtime impact (~1–5% latency) for most use cases, but critical paths (e.g., API endpoints) should be benchmarked. OTel’s sampling can mitigate volume.
    • Memory: Span creation for every public method may increase memory usage. Exclude non-critical methods (e.g., getters/setters) to optimize.
  • Extensibility:
    • Customization: Supports method-level exclusions (exclude), argument filtering (#[Arguments]), and manual span configuration. Can be extended for custom span attributes (e.g., #[Traceable(tags: ['team' => 'payments'])]).
    • Framework Agnostic: Core works outside Laravel, but Laravel-specific integrations (e.g., auto-discovery) are available separately.

Integration Feasibility

  • Stack Compatibility:
    • PHP 8.2+: Required for attributes. Laravel 9+ supports this natively; older versions may need polyfills.
    • OTel PHP Extensions: Requires ext-opentelemetry (zero-code instrumentation). Conflicts possible with other OTel packages (e.g., spatie/laravel-otel). Mitigation: Use composer’s replace or conflict directives.
    • Laravel Components:
      • Service Container: No conflicts expected; attributes are resolved via reflection.
      • Middleware: Can integrate with Laravel’s middleware for HTTP tracing (e.g., TraceMiddleware to wrap #[Traceable] classes).
      • Queues: Async spans require context propagation (e.g., traceparent headers in queue payloads). Laravel’s queue drivers (Redis, database) must support this.
      • Eloquent/Database: Potential for auto-tracing repository methods (e.g., #[Traceable] on App\Repositories\UserRepository). Risk: May interfere with query caching or raw SQL.
  • Migration Path:
    • Phase 1: Pilot with non-critical services (e.g., UserService, NotificationService).
    • Phase 2: Integrate with HTTP layer (middleware) and queues.
    • Phase 3: Extend to database/ORM if needed (custom instrumentation).
  • Compatibility Risks:
    • Attribute Reflection: Legacy PHP (<8.2) or Laravel (<9.0) may require workarounds (e.g., nikic/php-parser).
    • OTel SDK Versioning: The package’s dependency on ext-opentelemetry may conflict with Laravel’s OTel integrations (e.g., spatie/laravel-otel). Solution: Standardize on one OTel package per project.
    • Testing: Unit tests may need mocking for OTel spans (e.g., Mockery or PHPUnit extensions).

Key Questions

  1. Observability Goals:
    • What are the top 3 use cases for tracing (e.g., latency debugging, audit logs, SLA monitoring)? Does this package address them?
    • Are there existing manual traces that could conflict or duplicate efforts?
  2. Performance:
    • Which methods are most critical to trace? Are they CPU-bound or I/O-bound?
    • What is the acceptable latency overhead for traced methods?
  3. Tooling:
    • Which OTel backend will be used (e.g., Jaeger, Honeycomb, Datadog)? Does the package support the required exporters?
    • How will traces be correlated with Laravel logs (e.g., X-Trace-ID headers)?
  4. Adoption:
    • Which teams will annotate classes? Is there a process for reviewing #[Traceable] usage?
    • How will false positives (e.g., over-tracing) be managed?
  5. Long-Term Maintenance:
    • How will the package be updated if OTel PHP SDK changes?
    • Is there a rollback plan if tracing introduces issues?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Layer: Annotate domain services (e.g., App\Services\OrderService) with #[Traceable]. Exclude trivial methods (e.g., getters).
    • HTTP Layer: Use middleware to trace incoming requests (e.g., app/Http/Middleware/TraceRequests) and wrap #[Traceable] controllers/services.
    • Queues/Jobs: Ensure context propagation (e.g., traceparent headers) in queue payloads. Annotate job classes (e.g., App\Jobs\ProcessOrder).
  • Database/ORM:
    • Option 1: Manually trace repository methods (e.g., #[Traceable] on App\Repositories\UserRepository).
    • Option 2: Use Laravel’s query logging to correlate SQL with traces (requires custom instrumentation).
  • Third-Party Integrations:
    • API Clients: Propagate context headers (e.g., traceparent) in HTTP clients (Guzzle, HTTP Client).
    • Event Dispatcher: Trace event handlers (e.g., #[Traceable] on App\Listeners\OrderCreated).

Migration Path

  1. Pilot Phase:
    • Scope: Start with 1–2 high-value services (e.g., PaymentService, OrderService).
    • Implementation:
      • Add #[Traceable] to public methods.
      • Register instrumentation in a service provider (e.g., App\Providers\ObservabilityServiceProvider).
      • Verify traces appear in the OTel backend (e.g., Jaeger).
    • Validation: Check for missing spans, false positives, or performance regressions.
  2. HTTP Layer Integration:
    • Middleware: Create TraceRequestsMiddleware to wrap #[Traceable] controllers.
    • Routing: Use middleware groups (e.g., Route::middleware([TraceRequests::class])) for critical routes.
  3. Async Workflows:
    • Queues: Annotate job classes and ensure context propagation.
    • Events: Trace event listeners/dispatchers.
  4. Database Tracing (Optional):
    • Custom Instrumentation: Extend the package or use OTel’s Span API to trace Eloquent queries.
    • Query Logging: Correlate Laravel’s query logs with trace IDs.

Compatibility

  • Laravel Versions:
    • Laravel 9+: Full support for PHP 8.2+ attributes.
    • Laravel 8.x: Use nikic/php-parser for attribute support (higher maintenance).
  • OTel Packages:
    • Conflict Resolution: If using spatie/laravel-otel, decide whether to:
      • Merge: Combine both packages’ instrumentation (risk of duplication).
      • Replace: Use only eerzho/opentelemetry-auto-class for class-level tracing.
  • Testing:
    • Unit Tests: Mock OTel spans (e.g., Mockery).
    • Integration Tests: Verify traces in a staging environment with the OTel backend.

Sequencing

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

Operational Impact

Maintenance

  • Package Updates:
    • Monitor eerzho/opentelemetry-auto-class for OTel SDK compatibility changes.
    • Strategy: Pin versions
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor