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

Api Laravel Package

open-telemetry/api

OpenTelemetry API for PHP: vendor-neutral interfaces for tracing, metrics, and context propagation. Use it to instrument libraries/apps and connect to any OpenTelemetry SDK/exporter. Part of the OpenTelemetry PHP project (subtree split).

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Observability Alignment: The open-telemetry/api package provides a standardized, vendor-neutral API for OpenTelemetry instrumentation in PHP, aligning with modern observability best practices (traces, metrics, logs, and context propagation). It is a foundational dependency for any Laravel application aiming to integrate OpenTelemetry for distributed tracing, performance monitoring, or debugging.
  • Laravel Compatibility: Laravel’s ecosystem (e.g., Laravel Horizon, Scout, Echo, or custom middleware) can leverage OpenTelemetry for end-to-end request tracing, resource instrumentation, and structured logging. The API’s context propagation (e.g., TextMapPropagator) is particularly useful for microservices or serverless architectures.
  • Extensibility: The API is modular—it defines interfaces (e.g., Span, Meter, Logger) that can be implemented by SDKs (e.g., open-telemetry/sdk) or third-party exporters (e.g., Jaeger, Zipkin, Prometheus). This allows TPMs to swap implementations without breaking instrumentation logic.

Integration Feasibility

  • Low Friction for Laravel: The package is PHP 8.1+ compatible (Laravel 9+ uses PHP 8.1+) and integrates seamlessly with PSR-15 middleware, Laravel’s service container, and event listeners. Example use cases:
    • HTTP Request Tracing: Instrument Illuminate\Http\Request lifecycle with Span objects.
    • Database Query Tracking: Wrap Illuminate\Database queries in spans.
    • Queue Job Monitoring: Trace Illuminate\Queue jobs with Span context.
  • Dependency Graph:
    • Direct Dependencies: None (pure API).
    • Transitive Dependencies: Minimal (only ext-ctype, ext-json for PHP core).
    • Conflict Risk: Low—OpenTelemetry is a de facto standard with broad adoption.

Technical Risk

Risk Area Assessment Mitigation Strategy
Breaking Changes Deprecations in 1.9.0 (e.g., InstrumentationInterface) may require SDK updates. Monitor OpenTelemetry PHP releases and test with open-telemetry/sdk.
Performance Overhead Tracing/metrics add latency. Benchmark with open-telemetry/sdk before production rollout. Use sampling (e.g., Span::setAttribute('sampling.priority', 1)) for high-throughput apps.
Complexity Context propagation (e.g., W3C Trace Context) requires careful handling. Leverage Laravel’s context managers (e.g., Symfony\Component\HttpFoundation\Request::setAttribute()).
Vendor Lock-in API is standardized, but SDK/exporter choices may fragment. Prefer OTLP (OpenTelemetry Protocol) exporters for vendor neutrality.

Key Questions for TPM

  1. Observability Goals:
    • Are we targeting distributed tracing, metrics, or logs? (This dictates which OpenTelemetry components to prioritize.)
    • Example: For Laravel, traces (HTTP/DB/Queue) may be more valuable than metrics initially.
  2. Exporter Strategy:
    • Will we use OTLP (recommended for cloud-native), Jaeger, or Prometheus?
    • Does the team need custom spans (e.g., for business logic) or auto-instrumentation?
  3. Sampling Strategy:
    • How will we handle high-cardinality traces (e.g., in APIs with many endpoints)?
    • Options: Head-based sampling, tail sampling, or probabilistic sampling.
  4. Laravel-Specific Integration:
    • Should we instrument Laravel’s built-in components (e.g., Illuminate\Routing, Illuminate\Cache)?
    • How will we propagate context across Laravel Echo (WebSockets) or Horizon (queues)?
  5. Cost vs. Value:
    • What’s the expected ROI (e.g., debugging latency, SLA compliance)?
    • Will we sample aggressively to reduce costs (e.g., 1% of traces)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Traces: Integrate with Illuminate\Http\Request, Illuminate\Database, Illuminate\Queue.
    • Metrics: Use Meter for custom business metrics (e.g., orders.processed).
    • Logs: Correlate Logger output with spans using SpanContext.
  • Tech Stack Compatibility:
    • PHP 8.1+: Laravel 9/10 support is guaranteed.
    • Composer: Install via composer require open-telemetry/api.
    • PSR Standards: Aligns with PSR-3 (logging), PSR-15 (middleware), and PSR-11 (container).

Migration Path

  1. Phase 1: API Adoption (Low Risk)
    • Add open-telemetry/api to composer.json.
    • Implement basic tracing in a single route/controller (e.g., /health).
    • Example:
      use OpenTelemetry\API\Trace\TracerInterface;
      use OpenTelemetry\API\Trace\SpanKind;
      
      public function index(TracerInterface $tracer) {
          $span = $tracer->spanBuilder()->setName('user.profile')->setSpanKind(SpanKind::SPAN_KIND_SERVER)->startSpan();
          try {
              // Business logic
          } finally {
              $span->end();
          }
      }
      
  2. Phase 2: SDK Integration (Medium Risk)
    • Add open-telemetry/sdk and configure an exporter (e.g., OTLP to Jaeger).
    • Example config/opentelemetry.php:
      return [
          'exporter' => 'otlp',
          'otlp_endpoint' => env('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://localhost:4317'),
      ];
      
  3. Phase 3: Auto-Instrumentation (High Value)
    • Use open-telemetry/auto-instrumentation for Laravel components (e.g., HTTP, DB, Queue).
    • Example: Auto-instrument Illuminate\Http\Request:
      OpenTelemetry\AutoInstrumentation\Instrumentation\HTTP::register();
      
  4. Phase 4: Context Propagation (Advanced)
    • Propagate traces across Laravel Echo (WebSockets) or Horizon (queues).
    • Example: Propagate context in a queue job:
      use OpenTelemetry\API\GlobalRegistry;
      
      public function handle() {
          $span = GlobalRegistry::get(span.class)->getCurrentSpan();
          // Queue logic with span context
      }
      

Compatibility

  • Laravel Services:
    • Service Container: Register TracerInterface, MeterInterface as singletons.
    • Middleware: Use OpenTelemetry\API\Trace\Span in middleware for request tracing.
    • Events: Correlate Span with Laravel events (e.g., Illuminate\Queue\Events\JobProcessed).
  • Third-Party Packages:
    • Laravel Scout: Instrument search queries with spans.
    • Laravel Horizon: Trace queue jobs with Span context.
    • Laravel Echo: Propagate traces via WebSocket headers.

Sequencing

Step Priority Dependencies Notes
1. Add API High None Start with open-telemetry/api.
2. Basic Tracing High open-telemetry/api Instrument critical paths (e.g., API routes).
3. SDK + Exporter Medium open-telemetry/sdk Choose OTLP, Jaeger, or Prometheus.
4. Auto-Instrument Medium open-telemetry/auto-instrumentation Add HTTP/DB/Queue instrumentation.
5. Context Prop Low Laravel Echo/Horizon Propagate traces across async boundaries.
6. Metrics/Logs Low open-telemetry/api Add Meter for custom metrics or correlate logs with spans.

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor open-telemetry/api for deprecations (e.g., InstrumentationInterface in 1.9.0).
    • Upgrade Path: Test with open-telemetry/sdk before major API changes.
  • **Configuration
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata