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

Sdk Laravel Package

open-telemetry/sdk

OpenTelemetry PHP SDK implementing the OpenTelemetry API to collect traces and metrics. Use with compatible exporters; supports manual setup, SDK Builder, and optional auto-loading/registration via OTEL_* environment configuration.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

The OpenTelemetry PHP SDK aligns well with Laravel’s observability-first architecture, particularly for:

  • Distributed tracing (via Span instrumentation) for microservices, queues, and HTTP clients.
  • Metrics collection (via Meter) for performance monitoring (e.g., request latency, DB query counts).
  • Logs instrumentation (via Logger) for structured logging with correlation IDs.
  • Auto-instrumentation for frameworks like Symfony HTTP Client, Guzzle, and PSR-3 loggers (compatible with Laravel’s Log facade).

Key Fit Areas:

  1. Laravel’s Service Container: The SDK integrates seamlessly via Globals::tracerProvider()/Globals::meterProvider(), enabling dependency injection.
  2. Queue Workers: Supports async span propagation (e.g., Laravel\Queue\Jobs).
  3. HTTP Middleware: Auto-instrumentation for Illuminate\Http\Request/Response via TextMapPropagator.
  4. Database/ORM: Compatible with Laravel’s query builder (via Span context for SQL queries).

Integration Feasibility

Component Feasibility Notes
Laravel Core High Minimal boilerplate; autoloading via OTEL_PHP_AUTOLOAD_ENABLED.
Queues (Redis/Database) High Span context propagates across workers.
HTTP (API Routes) High Middleware for Span injection (e.g., OpenTelemetry\Context\Propagation).
Database (Eloquent) Medium Requires custom instrumentation (e.g., DB::listen).
Logging (Monolog) High PSR-3 logger integration via Logger API.
CLI Artisan Commands High Metrics/traces for background jobs.

Technical Risk

  1. Performance Overhead:

    • Risk: Span creation/metrics collection may impact high-throughput endpoints.
    • Mitigation: Use AlwaysRecordSampler sparingly; configure batching (e.g., OtlpHttpExporter with export_interval).
    • Laravel-Specific: Test with queue:work and schedule:run under load.
  2. Compatibility Gaps:

    • Risk: Laravel’s Event system lacks native OpenTelemetry support.
    • Mitigation: Use Meter for custom metrics (e.g., event.dispatching).
    • Risk: Older PHP versions (<8.1) may need polyfills (e.g., weaken for closures).
    • Mitigation: Target PHP 8.2+ for full feature support.
  3. Configuration Complexity:

    • Risk: Environment variables (OTEL_*) and OTEL_CONFIG_FILE may conflict with Laravel’s .env.
    • Mitigation: Use Laravel’s config() binding for SDK config (e.g., config('opentelemetry.exporter')).
  4. Exporter Dependencies:

    • Risk: OTLP exporters (e.g., otlp/otlp-http) require additional setup (e.g., Jaeger/Zipkin backend).
    • Mitigation: Start with ConsoleExporter for debugging, then migrate to OTLP.

Key Questions for TPM

  1. Observability Goals:

    • Are we prioritizing traces, metrics, or logs? (e.g., traces for APIs, metrics for queues).
    • Should we use sampling (e.g., TraceIdRatioBasedSampler) to reduce volume?
  2. Backend Integration:

    • Which OpenTelemetry Collector or backend (Jaeger, Honeycomb, Datadog) will we use?
    • Do we need custom attributes (e.g., Laravel’s auth()->user()->id) in spans?
  3. Laravel-Specific Needs:

    • Should we instrument Eloquent queries or Job failures?
    • How will we handle legacy code (e.g., non-PSR-3 loggers)?
  4. Operational Tradeoffs:

    • What’s the acceptable latency for span/metric collection?
    • Should we disable SDK in CI (via OTEL_PHP_AUTOLOAD_ENABLED=false)?

Integration Approach

Stack Fit

Laravel Component OpenTelemetry SDK Feature Integration Method
HTTP Requests Span, TextMapPropagator Middleware to inject/extract context from Request/Response.
Queues Span propagation Use OpenTelemetry\Context\Propagation::getCurrentContext() in HandleJobs.
Logging Logger Replace Log::channel() with OpenTelemetry\SDK\Logs\Logger.
Database Custom instrumentation Wrap DB::listen() to create spans for queries.
CLI/Artisan Meter Instrument Artisan::command() with metrics (e.g., meter->createCounter()).
Events Meter (no native support) Use Event::listen() to emit custom metrics (e.g., event_dispatched_total).

Migration Path

  1. Phase 1: Instrumentation (Low Risk)

    • Add SDK via Composer:
      composer require open-telemetry/sdk open-telemetry/otlp
      
    • Enable autoloading in .env:
      OTEL_PHP_AUTOLOAD_ENABLED=true
      OTEL_SERVICE_NAME="laravel-app"
      OTEL_EXPORTER_OTLP_ENDPOINT="http://collector:4318"
      
    • Verify basic traces/metrics in ConsoleExporter (debug mode).
  2. Phase 2: Core Integration (Medium Risk)

    • HTTP: Create middleware to propagate context:
      use OpenTelemetry\Context\Propagation;
      use OpenTelemetry\API\Globals;
      
      public function handle($request, Closure $next) {
          $carrier = new ArrayCarrier();
          Propagation::inject($carrier, Globals::getTextMapPropagator());
          $request->headers->add($carrier);
          return $next($request);
      }
      
    • Queues: Extend Illuminate\Queue\Jobs\Job to propagate context:
      public function handle() {
          $context = Propagation::extract(
              new ArrayCarrier($this->payload['headers']),
              Globals::getTextMapPropagator()
          );
          Propagation::setCurrentContext($context);
          // ... job logic
      }
      
  3. Phase 3: Advanced Use Cases (High Risk)

    • Database: Instrument DB::listen():
      DB::listen(function ($query) {
          $span = Globals::tracerProvider()->getTracer('db')->startSpan($query->sql);
          // ... attach attributes
      });
      
    • Custom Metrics: Define business metrics:
      $meter = Globals::meterProvider()->getMeter('business');
      $updates = $meter->createCounter('user_updates');
      $updates->add(1, ['user_id' => auth()->id()]);
      

Compatibility

Compatibility Check Status Notes
Laravel 10.x / PHP 8.2+ ✅ Fully Supported Target PHP 8.2+ for weaken and ArrayObject changes.
Laravel Queues (Redis/SQS) ✅ Supported Span context propagates via payload headers.
Monolog (Laravel’s default logger) ✅ Supported Use OpenTelemetry\SDK\Logs\Logger as a Monolog handler.
Symfony HTTP Client ✅ Supported Auto-instrumented via HttpClientDiscovery.
Guzzle 7.x ✅ Supported Requires guzzlehttp/guzzle:^7.0.
Legacy PHP (<8.1) ⚠️ Partial May need polyfills for weaken/match expressions.

Sequencing

  1. Start with Traces:
    • Instrument HTTP routes and queues first (highest ROI).
  2. Add Metrics:
    • Focus on critical paths (e.g., API latency, queue processing time).
  3. Logs Last:
    • Use Logger for structured logs with correlation IDs (requires backend support).

Avoid:

  • Over-instrumenting early (e.g., adding spans to every Eloquent query).
  • Mixing exporters (e.g., ConsoleExporter + OtlpExporter) during testing.

Operational Impact

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
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
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests