open-telemetry/sdk
OpenTelemetry PHP SDK for generating and exporting traces, metrics, and logs. Use with compatible exporters and configure via code or environment variables. Supports Composer autoload-based SDK initialization and global tracer/meter providers.
bind()), event listeners, and middleware hooks. Works with Laravel’s built-in HTTP client (Guzzle) and queue systems (via Span propagation).Baggage and SpanContext) to attach telemetry to Laravel’s request lifecycle without monolithic instrumentation.HandleIncomingRequest/HandleOutgoingResponse middleware to auto-instrument HTTP spans.Illuminate\Queue\Jobs\Job via Span propagation in job payloads.| Risk Area | Mitigation Strategy |
|---|---|
| Performance Overhead | Use sampling (e.g., TraceIdRatioBasedSampler) to limit span volume. Benchmark with AlwaysRecordSampler disabled. |
| Breaking Changes | SDK follows semver; Laravel’s PHP 8.3+ support aligns with SDK’s PHP 8.1+ baseline. |
| Exporter Dependencies | Requires backend (e.g., Jaeger, OTLP, Zipkin). Test with console exporter first. |
| Context Propagation | Ensure TextMapPropagator is registered for cross-service tracing (e.g., API calls). |
| Configuration Complexity | Start with environment variables (OTEL_*), then migrate to OTEL_CONFIG_FILE. |
ServiceInfo)?/api/payments)?Illuminate\Http\Middleware\HandleIncomingRequest to start spans on incoming requests.TracerProvider and MeterProvider as singletons.Span to Illuminate\Queue\Events\JobProcessed.OpenTelemetry\Instrumentation\Guzzle for automatic span creation.OpenTelemetry\Instrumentation\SymfonyHttpClient.OpenTelemetry\Instrumentation\PDO for query tracing.Illuminate\Database\Eloquent\Model events (retrieved, saved).SpanContext in job payloads using OpenTelemetry\Context\Propagation\TextMapPropagator.Phase 1: Tracing (MVP)
open-telemetry/sdk and open-telemetry/exporter-otlp to composer.json..env:
OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_SERVICE_NAME="laravel-app"
OTEL_EXPORTER_OTLP_ENDPOINT="http://jaeger:4317"
// app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
\OpenTelemetry\Instrumentation\Laravel\Http\Middleware\TraceHttp::class,
// ...
],
];
/health).Phase 2: Metrics
user_signups_total).$meter = \OpenTelemetry\API\Globals::meterProvider()->getMeter('laravel');
$counter = $meter->createCounter('user_signups');
$counter->add(1, ['region' => 'us-west']);
Phase 3: Logs
use OpenTelemetry\API\Logs\Logger;
$logger = \OpenTelemetry\API\Globals::loggerProvider()->getLogger('app');
$logger->logRecordBuilder()
->setSeverityText('error')
->setBody('Failed to process payment')
->emit();
open-telemetry/api:1.5.ctype, json, and pcntl (for sampling). No bcmath dependency.open-telemetry/exporter-zipkin.open-telemetry/exporter-console).| Step | Priority | Dependencies |
|---|---|---|
| Set up OTLP exporter | High | Backend (Jaeger/Datadog) |
| Instrument HTTP | High | Laravel middleware |
| Add sampling | Medium | TraceIdRatioBasedSampler |
| Metrics for APIs | Medium | Business logic instrumentation |
| Queue job tracing | Low | Illuminate\Queue integration |
| Database queries | Low | PDO/Eloquent interceptors |
.env or config/opentelemetry.php.OTEL_CONFIG_FILE for complex setups (e.g., multiple environments).open-telemetry/api and open-telemetry/sdk for breaking changes (quarterly reviews).composer.json during stabilization:
"open-telemetry/sdk": "^1.14",
"open-telemetry/api": "^1.8"
OpenTelemetry\SDK\Logs\Logger to drop sensitive attributes (e.g., passwords) via Logger::setAttributeDroppingStrategy.OTEL_PHP_ERROR_MODE=always to log SDK errors to stderr.OTEL_PHP_EXPERIMENTAL_CONSOLE_EXPORTER_ENABLED=true
TextMapPropagator is registered and context is propagated.AttributeFilter to limit metric attributes.OpenTelemetry\SDK\Common\Retry.TraceIdRatioBasedSampler with ratio 0.1).$sampler = new \OpenTelemetry\SDK\Trace\Sampler\TraceIdRatioBasedSampler(0.1);
$provider = new \OpenTelemetry\SDK\Trace\TracerProvider($sampler);
OTEL_EXPORTER_OTLP_BATCH_SPAN_PROCESSOR to reduce backend load.OTEL_PHP_MEMORY_LIMIT_MB=256 (adjust based on workload).| Failure Scenario | Impact | Mitigation | |---------------------------------|--------------------------------
How can I help you explore Laravel packages today?