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 for generating traces, metrics, and logs. Implements the API and works with exporters to emit telemetry. Supports manual setup, an SDK builder, and optional auto-registration via environment variables during Composer autoload.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Observability Alignment: The OpenTelemetry PHP SDK is a strong fit for Laravel applications, as it provides standardized instrumentation for traces, metrics, and logs, aligning with Laravel’s growing need for distributed tracing (e.g., microservices, queue workers, HTTP requests) and performance monitoring.
  • Laravel Ecosystem Synergy:
    • Integrates seamlessly with Laravel’s HTTP middleware, queue workers, and event listeners via OpenTelemetry’s auto-instrumentation.
    • Supports PSR-3 logging (via Logger interface), enabling compatibility with Laravel’s built-in Log facade.
    • Complements Laravel’s Horizon (queue monitoring) and Scout (search analytics) with structured telemetry.
  • Vendor Agnostic: Avoids lock-in to specific APM tools (e.g., Datadog, New Relic) by exporting to OTLP/Jaeger/ZPages, enabling multi-vendor observability.

Integration Feasibility

  • Low-Coupling Design: The SDK follows the OpenTelemetry API contract, allowing instrumentation to be added incrementally without monolithic refactoring.
    • Example: Wrap Laravel’s Illuminate\Http\Request handling in a Span without modifying core framework code.
  • Auto-Instrumentation: Supports automatic SDK initialization via OTEL_PHP_AUTOLOAD_ENABLED, reducing boilerplate.
  • Middleware Integration: Can instrument Laravel’s middleware pipeline (e.g., app/Http/Kernel.php) by injecting spans around handle() calls.
  • Queue Workers: Instrument Laravel Queues (e.g., Illuminate\Queue\Jobs\Job) with spans for job processing latency.

Technical Risk

Risk Area Mitigation Strategy
Performance Overhead Use sampling (TraceIdRatioBasedSampler) to limit trace volume. Profile with AlwaysRecordSampler disabled.
Configuration Complexity Leverage environment variables (OTEL_*) and declarative config (YAML/JSON) for dynamic tuning.
Exporter Dependencies Start with in-memory exporter for testing; migrate to OTLP/Jaeger in production.
PHP Version Compatibility Test against PHP 8.1+ (Laravel’s LTS support). SDK supports 8.0–8.4.
Log Correlation Ensure SpanContext is propagated via HTTP headers (traceparent) for cross-service tracing.

Key Questions

  1. Observability Goals:
    • Will this replace existing APM tools (e.g., Laravel Telescope) or augment them?
    • Are custom metrics (e.g., Laravel cache hit ratios) needed beyond traces/logs?
  2. Export Backend:
    • Preferred backend (e.g., Jaeger, Honeycomb, Datadog)? Affects exporter choice.
  3. Sampling Strategy:
    • Should sampling be static (e.g., 10% of requests) or dynamic (e.g., error-based)?
  4. Legacy Code:
    • How will existing Monolog or custom loggers integrate with OpenTelemetry’s Logger?
  5. Cost Implications:
    • Will high-cardinality metrics (e.g., per-user traces) require sampling or aggregation?

Integration Approach

Stack Fit

  • Laravel Core:
    • HTTP Layer: Instrument Illuminate\Http\Request/Response via middleware.
    • Queue Layer: Wrap Illuminate\Queue\Jobs\Job::handle() in spans.
    • Events: Instrument Illuminate\Events\Dispatcher for event latency.
  • Service Layer:
    • Repositories: Add spans around Eloquent/Query Builder operations.
    • API Clients: Instrument Guzzle HTTP Client or Laravel HTTP Client.
  • Background Jobs:
    • Artisan Commands: Add spans to Illuminate\Console\Command.
    • Scheduled Tasks: Instrument App\Console\Kernel methods.
  • Logging:
    • Extend Monolog handlers to emit OpenTelemetry logs with SpanContext.

Migration Path

  1. Phase 1: Instrumentation (Low Risk)
    • Add auto-instrumentation via OTEL_PHP_AUTOLOAD_ENABLED=true.
    • Configure basic sampling (e.g., OTEL_TRACES_SAMPLER=TraceIdRatioBased{ratio=0.1}).
    • Test with in-memory exporter (no backend dependency).
  2. Phase 2: Core Workflows (Medium Risk)
    • Instrument HTTP middleware, queue jobs, and critical routes.
    • Validate trace propagation across services (if applicable).
  3. Phase 3: Advanced Use Cases (High Risk)
    • Implement custom metrics (e.g., Laravel cache metrics).
    • Integrate with third-party services (e.g., Stripe, AWS SDK).
    • Optimize sampling based on production telemetry.

Compatibility

Component Compatibility Notes
Laravel 10/11 Full support (PHP 8.1+).
Laravel Queues Works with database, Redis, SQS drivers.
Monolog Can extend Processor to inject SpanContext into log records.
Guzzle HTTP Client Use OpenTelemetry\Instrumentation\Guzzle for automatic instrumentation.
Symfony HTTP Client Use OpenTelemetry\Instrumentation\SymfonyHttpClient.
Database (Eloquent) Instrument DB::connection() or use OpenTelemetry\Instrumentation\PDO.

Sequencing

  1. Prerequisites:
    • Upgrade to PHP 8.1+ (Laravel 9+).
    • Ensure Composer autoloading is configured (composer dump-autoload).
  2. Initial Setup:
    composer require open-telemetry/sdk open-telemetry/exporter-otlp
    
  3. Configuration:
    • Set environment variables (e.g., OTEL_SERVICE_NAME="laravel-app").
    • Configure exporter (e.g., OTLP to Jaeger):
      putenv('OTEL_EXPORTER_OTLP_ENDPOINT="http://jaeger:4317"');
      
  4. Instrumentation:
    • Add middleware for HTTP spans:
      use OpenTelemetry\API\Globals;
      use OpenTelemetry\API\Trace\SpanKind;
      
      $tracer = Globals::tracerProvider()->getTracer(__CLASS__);
      $span = $tracer->spanBuilder('HTTP Request')->setSpanKind(SpanKind::SPAN_KIND_SERVER)->startSpan();
      
  5. Validation:
    • Check traces in Jaeger UI or OTLP collector.
    • Verify context propagation in distributed requests.

Operational Impact

Maintenance

  • Configuration Drift:
    • Risk: Environment-specific OTEL_* variables may diverge.
    • Mitigation: Use declarative config files (OTEL_CONFIG_FILE) for consistency.
  • Dependency Updates:
    • Risk: OpenTelemetry PHP SDK updates may require API version alignment.
    • Mitigation: Pin open-telemetry/api version in composer.json.
  • Logging Overhead:
    • Risk: Excessive spans/logs may impact performance.
    • Mitigation: Enable attribute filtering and sampling.

Support

  • Debugging:
    • Pros: Traces provide end-to-end context for Laravel/queue issues.
    • Cons: Requires observability tooling (e.g., Jaeger) for analysis.
  • Error Handling:
    • Spans: Automatically record exceptions via Span::recordException().
    • Logs: Correlate logs with traces using trace_id.
  • Vendor Support:
    • Community: Active OpenTelemetry PHP community; issues filed in GitHub.
    • Laravel: Limited official support; rely on community extensions.

Scaling

  • Throughput:
    • Sampling: Reduces volume (e.g., TraceIdRatioBased{ratio=0.01} for high-traffic apps).
    • Batch Export: Use BatchSpanProcessor to minimize exporter calls.
  • Resource Usage:
    • Memory: In-memory exporters may grow under high load; prefer OTLP gRPC.
    • CPU: Span processing adds ~5–10% overhead; benchmark under load.
  • Horizontal Scaling:
    • Stateless: Works in Laravel Forge/Vagrant or Kubernetes deployments.
    • Distributed Tracing: Correlates traces across multiple Laravel instances.

Failure Modes

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
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi