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

Laravel Open Telemetry Laravel Package

spatie/laravel-open-telemetry

Add OpenTelemetry tracing to Laravel to measure performance and follow requests across dispatched jobs and services. Export traces to tools like Jaeger or Aspecto for end-to-end visibility and debugging. (Package still in development.)

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Observability Alignment: The package integrates OpenTelemetry (OTel) into Laravel, enabling distributed tracing, metrics, and logging—key components of modern observability stacks. This aligns well with microservices, event-driven architectures, or monolithic apps requiring deep performance insights.
  • Laravel Ecosystem Synergy: Leverages Laravel’s native components (e.g., queues, HTTP, events) to auto-instrument performance-critical paths, reducing boilerplate for telemetry collection.
  • Extensibility: OTel’s vendor-agnostic design allows integration with backends like Jaeger, Zipkin, Prometheus, or custom exporters, though the package’s maturity (archived) may limit built-in exporter support.

Integration Feasibility

  • Low-Coupling Design: Uses Laravel service providers and middleware, minimizing invasive changes. Existing telemetry libraries (e.g., laravel-monitoring) could be replaced with minimal refactoring.
  • Job/Queue Support: Explicitly targets Laravel queues (jobs, commands), which are often performance bottlenecks. Complements existing monitoring for HTTP routes (if using spatie/laravel-http-middleware).
  • Dependency Risk: Relies on open-telemetry/php (OTel PHP SDK), which may introduce versioning constraints or breaking changes if the package evolves independently.

Technical Risk

  • Archived Status: No active maintenance raises risks:
    • Bug fixes or security patches may stall.
    • Compatibility with newer Laravel/OTel versions untested.
  • OTel Complexity: Misconfigured spans/attributes could bloat telemetry data or mislead debugging. Requires understanding of OTel concepts (e.g., context propagation).
  • Vendor Lock-in: Custom instrumentation may need adjustments if migrating to alternative observability tools (e.g., Datadog, New Relic).

Key Questions

  1. Why Archived?
    • Is this a temporary pause, or is OTel support being deprecated in favor of other Spatie packages?
    • Are there upstream OTel PHP SDK limitations?
  2. Exporter Support
    • Does the package include pre-configured exporters (e.g., OTLP, Jaeger), or must they be added manually?
  3. Performance Overhead
    • What’s the baseline impact on Laravel’s runtime (e.g., memory, latency) when tracing is enabled?
  4. Migration Path
    • How would existing telemetry (e.g., from laravel-telescope or monolog) be consolidated or replaced?
  5. Team Expertise
    • Does the team have OTel experience, or will training be required for setup/debugging?

Integration Approach

Stack Fit

  • Laravel-Centric: Optimized for Laravel’s request lifecycle, queue workers, and events. Ideal for:
    • Microservices: Trace requests across services using OTel context propagation.
    • Serverless: Monitor Lambda/queue invocations (if using Laravel Vapor or similar).
    • Monoliths: Identify slow endpoints/jobs in complex applications.
  • OTel Ecosystem: Works alongside other OTel instruments (e.g., database drivers, HTTP clients) for end-to-end tracing.
  • Non-Fit Cases:
    • Legacy Apps: May require significant refactoring to instrument key paths.
    • Real-Time Systems: High-throughput apps might experience latency from tracing overhead.

Migration Path

  1. Pilot Phase:
    • Start with a non-production environment (e.g., staging).
    • Instrument a single queue worker or HTTP route to validate telemetry quality.
  2. Incremental Rollout:
    • Phase 1: Add package via Composer, configure basic exporter (e.g., OTLP to Jaeger).
    • Phase 2: Enable tracing for critical jobs/routes using middleware/service provider bindings.
    • Phase 3: Extend to events, database queries (if using OTel-instrumented drivers).
  3. Deprecation Handling:
    • If archived, document fallback plans (e.g., switch to opentelemetry/opentelemetry-php directly).
    • Cache package versions to avoid supply-chain risks.

Compatibility

  • Laravel Versions: Check composer.json for supported Laravel versions (likely 8.x–10.x). Test against your version.
  • PHP Extensions: Requires pcntl for async workers (if using Laravel Horizon). Verify ext-opentelemetry is available.
  • OTel Backend: Ensure your observability backend (e.g., Jaeger, Prometheus) supports OTel’s data model.
  • Conflicts: Potential overlap with:
    • spatie/laravel-monitoring (duplicate metrics).
    • laravel-telescope (alternative debugging tool).

Sequencing

  1. Prerequisites:
    • Set up an OTel collector or backend (e.g., Jaeger, Prometheus + Grafana).
    • Configure Laravel’s logging to exclude verbose OTel noise (e.g., via Monolog processors).
  2. Core Integration:
    • Publish the package’s config (php artisan vendor:publish --provider="Spatie\OpenTelemetry\OpenTelemetryServiceProvider").
    • Configure exporters and service names in .env.
  3. Instrumentation:
    • Use middleware for HTTP routes:
      use Spatie\OpenTelemetry\Middleware\TraceRequests;
      Route::middleware(TraceRequests::class)->group(...);
      
    • Bind jobs to the tracer:
      $this->app->bind(ShouldBeTracing::class, function () {
          return new ShouldBeTracing(app('tracer'));
      });
      
  4. Validation:
    • Verify spans appear in the backend for key user journeys.
    • Check for dropped contexts or high cardinality in attributes.

Operational Impact

Maintenance

  • Package Updates: Monitor open-telemetry/php for breaking changes. Pin versions in composer.json to avoid surprises.
  • Configuration Drift: Centralize OTel settings (e.g., sampling rates, resource attributes) in config files or environment variables.
  • Deprecation: Prepare to fork or replace if the package stagnates. Document customizations (e.g., exporter tweaks).

Support

  • Debugging:
    • OTel spans may lack context if not properly propagated (e.g., across queue workers). Use traceparent headers for HTTP or OTel context APIs for queues.
    • Log correlation IDs to tie telemetry to application logs.
  • Alerting:
    • Define SLOs based on span duration/errors (e.g., "99% of jobs complete in <500ms").
    • Avoid alerting on synthetic telemetry (e.g., internal spans).
  • Tooling:
    • Train teams on OTel-specific tools (e.g., Jaeger UI, Prometheus queries). Provide runbooks for common issues (e.g., missing spans).

Scaling

  • Sampling:
    • Enable probabilistic sampling in OTel to reduce volume (e.g., 10% of traces).
    • Adjust based on backend capacity (e.g., Jaeger may struggle with high cardinality).
  • Resource Attributes:
    • Tag spans with service.version, deployment.environment to filter noise in production.
  • Performance:
    • Profile tracing overhead in high-load scenarios. Disable in non-critical paths if needed.

Failure Modes

Failure Scenario Impact Mitigation
OTel backend unavailable Lost telemetry; blind spots Fallback to local logging; alert on backend health.
High cardinality in attributes Backend overload; slow queries Limit attributes (e.g., user_id only for errors).
Context propagation failures Broken end-to-end traces Validate traceparent headers; use Baggage.
Package version conflicts Broken instrumentation Pin versions; test upgrades in staging.
Laravel cache/queue issues Missing spans for jobs/routes Monitor queue workers; retry failed jobs.

Ramp-Up

  • Onboarding:
    • For Developers:
      • Document how to instrument custom code (e.g., @withSpan macros).
      • Example: Tracing a custom service:
        use Spatie\OpenTelemetry\Facades\OpenTelemetry;
        OpenTelemetry::tracer()->spanBuilder('custom.service')->startSpan(...);
        
    • For Ops:
      • Provide dashboards for key metrics (e.g., slowest jobs, error rates).
      • Share OTel backend access guidelines.
  • Training:
    • Workshop on OTel concepts (spans, contexts, exporters).
    • Demo tracing a user flow end-to-end.
  • Documentation:
    • Update internal runbooks with OTel-specific troubleshooting (e.g., "No spans for API calls").
    • Create a cheat sheet for common instrumentation patterns.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport