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

Open Telemetry Bundle Laravel Package

danilovl/open-telemetry-bundle

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony Native Integration: The bundle is designed specifically for Symfony 8.0+, leveraging its dependency injection (DI) and event systems. This aligns perfectly with Laravel’s ecosystem if using Symfony components (e.g., Symfony HTTP Foundation, Messenger, or Doctrine via Laravel Doctrine Bridge).
  • OpenTelemetry Standard Compliance: Adheres to OpenTelemetry’s tracing, metrics, and logging standards, ensuring compatibility with observability tools like Jaeger, Prometheus, and Grafana.
  • Modular Instrumentation: Supports granular instrumentation (HTTP, Doctrine, Redis, etc.), allowing selective enablement/disablement—ideal for Laravel’s layered architecture (e.g., skip tracing for CLI commands unless explicitly configured).

Integration Feasibility

  • Laravel Compatibility:
    • Symfony Components: If the Laravel app uses Symfony’s HttpFoundation, Messenger, or Doctrine, integration is straightforward (e.g., wrap HttpClient with HttpTracingMiddleware).
    • Non-Symfony Components: For native Laravel services (e.g., Illuminate\Http\Request, Illuminate\Database), custom span processors or decorators would be required (see Key Questions).
    • Queue Workers: Messenger integration is available, but Laravel’s queue workers (e.g., php artisan queue:work) would need custom instrumentation (e.g., via TraceableHookCompilerPass equivalent).
  • PHP Extension Conflict: The bundle disables OTEL_PHP_AUTOLOAD_ENABLED, which may conflict with Laravel’s auto-loading. A custom compiler pass would be needed to replicate the bundle’s initialization logic.

Technical Risk

Risk Area Mitigation Strategy
Symfony Dependency Use Symfony’s Laravel Bridge (e.g., symfony/http-foundation for HTTP) or abstract Symfony-specific code behind interfaces.
Performance Overhead Start with minimal instrumentation (e.g., HTTP + Doctrine) and profile. Disable unused modules (e.g., messenger if not used).
Custom Instrumentation Extend the bundle’s Traceable attribute or provider factories for Laravel-native services (e.g., Eloquent queries).
OTLP Exporter Ensure the OTLP collector (e.g., Jaeger, Tempo) is configured to receive data. Fallback to console exporter for testing.
Backward Compatibility Test with Laravel 10+ (PHP 8.1+) and Symfony 6.4+ components to avoid version skew.

Key Questions

  1. Symfony Component Adoption:
    • Which Symfony components (if any) are already in use? (e.g., Messenger, HttpClient, Doctrine)
    • If none, what’s the cost of adding them (e.g., symfony/http-client for HTTP tracing)?
  2. Laravel-Specific Instrumentation:
    • How to trace Eloquent queries without Doctrine? (Custom QueryObserver or Traceable attribute for repositories.)
    • How to instrument Laravel’s queue workers (e.g., Illuminate\Queue\Worker)?
  3. Exporter Configuration:
    • Is an OTLP collector (e.g., OpenTelemetry Collector) available, or will we use console exporter for development?
  4. Attribute Support:
    • Can Laravel’s attributes (PHP 8+) be used for #[Traceable] annotations, or is a custom macro needed?
  5. Performance Baseline:
    • What’s the acceptable overhead for tracing? (Benchmark with/without instrumentation.)

Integration Approach

Stack Fit

Laravel Component Bundle Instrumentation Integration Strategy
HTTP Requests http_server Use symfony/http-foundation + HttpTracingMiddleware (decorate Illuminate\Http\Request).
Database (Eloquent) doctrine Custom QueryObserver or wrap Illuminate\Database\Connection with tracing.
Redis redis/predis Decorate Illuminate\Redis\Connections\Connection with TracingPhpRedis.
Queues messenger/async Replace Laravel’s queue workers with Symfony Messenger + MessageBusTracingMiddleware.
Console Commands console Use TraceableHookCompilerPass to wrap command methods with spans.
Events events Decorate Illuminate\Events\Dispatcher with TracingEventDispatcher.
HTTP Client http_client Use symfony/http-client + HttpTracingMiddleware (replace Guzzle/HTTP client).

Migration Path

  1. Phase 1: Infrastructure Setup
    • Deploy an OTLP collector (e.g., OpenTelemetry Collector with Jaeger/Prometheus backends).
    • Configure environment variables:
      OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
      OTEL_SERVICE_NAME=laravel-app
      OTEL_PHP_AUTOLOAD_ENABLED=false
      
  2. Phase 2: Bundle Integration
    • Install the bundle via Composer (adjust for Laravel’s autoloader):
      composer require danilovl/open-telemetry-bundle
      
    • For Symfony components: Register the bundle in config/bundles.php (if using Symfony’s kernel).
    • For Laravel: Create a custom service provider to replicate the bundle’s compiler passes (see Sequencing).
  3. Phase 3: Instrumentation Configuration
    • Start with minimal config (config/packages/open_telemetry.yaml):
      danilovl_open_telemetry:
          service:
              name: 'laravel-app'
          instrumentation:
              http_server: { enabled: true, tracing: { enabled: true } }
              doctrine: { enabled: true, tracing: { enabled: true } }
      
    • Gradually enable other modules (e.g., redis, messenger).
  4. Phase 4: Custom Instrumentation
    • For Laravel-native services (e.g., Eloquent), create:
      • A custom Traceable attribute (PHP 8+).
      • A compiler pass to register hooks (mimic TraceableHookCompilerPass).
      • Example:
        // app/Providers/OpenTelemetryServiceProvider.php
        use Danilovl\OpenTelemetryBundle\CompilerPass\TraceableHookCompilerPass;
        
        public function register(): void
        {
            $this->app->register(TraceableHookCompilerPass::class);
        }
        

Compatibility

  • PHP 8.5+: The bundle requires PHP 8.5, but Laravel 10+ supports this. Downgrade may require forks.
  • Laravel Services:
    • Symfony-Compatible: Direct integration (e.g., Messenger, HttpClient).
    • Native Laravel: Requires custom decorators/observers (e.g., Eloquent, Queues).
  • Existing Tracing: If using Monolog or Stackdriver, configure the bundle to export to both via multiple exporters.

Sequencing

  1. Initialization Order:
    • Disable OTEL_PHP_AUTOLOAD_ENABLED before loading the bundle.
    • Load the bundle after Symfony components (if used) but before Laravel’s service providers.
  2. Compiler Passes:
    • Register OpenTelemetryCompilerPass early (e.g., in AppServiceProvider::boot()) to ensure all DI tags are resolved.
    • Example:
      $this->app->make('kernel')->getContainer()->addCompilerPass(
          new \Danilovl\OpenTelemetryBundle\DependencyInjection\Compiler\OpenTelemetryCompilerPass()
      );
      
  3. Runtime Initialization:
    • The SDK initializes lazily on the first request. For CLI apps, trigger initialization manually:
      $this->app->make(\Danilovl\OpenTelemetryBundle\OpenTelemetryInitializer::class)->initializeSdk();
      

Operational Impact

Maintenance

Task Effort Notes
Configuration Updates Low YAML-based config is straightforward; use environment variables for dynamic values.
Bundle Updates Medium Monitor for Symfony/Laravel version compatibility.
Custom Instrumentation High Requires PHP 8+ attributes or manual decorator registration.
Exporter Maintenance Medium OTLP collector requires updates (e.g., schema changes).
Debugging Traces Low Use OTEL_LOG_LEVEL=debug and check collector logs for malformed spans.

Support

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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope