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.
Logger interface), enabling compatibility with Laravel’s built-in Log facade.Illuminate\Http\Request handling in a Span without modifying core framework code.OTEL_PHP_AUTOLOAD_ENABLED, reducing boilerplate.app/Http/Kernel.php) by injecting spans around handle() calls.Illuminate\Queue\Jobs\Job) with spans for job processing latency.| 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. |
Logger?Illuminate\Http\Request/Response via middleware.Illuminate\Queue\Jobs\Job::handle() in spans.Illuminate\Events\Dispatcher for event latency.Eloquent/Query Builder operations.Illuminate\Console\Command.App\Console\Kernel methods.Monolog handlers to emit OpenTelemetry logs with SpanContext.OTEL_PHP_AUTOLOAD_ENABLED=true.OTEL_TRACES_SAMPLER=TraceIdRatioBased{ratio=0.1}).| 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. |
composer dump-autoload).composer require open-telemetry/sdk open-telemetry/exporter-otlp
OTEL_SERVICE_NAME="laravel-app").putenv('OTEL_EXPORTER_OTLP_ENDPOINT="http://jaeger:4317"');
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();
OTEL_* variables may diverge.OTEL_CONFIG_FILE) for consistency.open-telemetry/api version in composer.json.Span::recordException().trace_id.TraceIdRatioBased{ratio=0.01} for high-traffic apps).BatchSpanProcessor to minimize exporter calls.How can I help you explore Laravel packages today?