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).
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.TextMapPropagator) is particularly useful for microservices or serverless architectures.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.Illuminate\Http\Request lifecycle with Span objects.Illuminate\Database queries in spans.Illuminate\Queue jobs with Span context.ext-ctype, ext-json for PHP core).| 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. |
Illuminate\Routing, Illuminate\Cache)?Illuminate\Http\Request, Illuminate\Database, Illuminate\Queue.Meter for custom business metrics (e.g., orders.processed).Logger output with spans using SpanContext.composer require open-telemetry/api.open-telemetry/api to composer.json./health).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();
}
}
open-telemetry/sdk and configure an exporter (e.g., OTLP to Jaeger).config/opentelemetry.php:
return [
'exporter' => 'otlp',
'otlp_endpoint' => env('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://localhost:4317'),
];
open-telemetry/auto-instrumentation for Laravel components (e.g., HTTP, DB, Queue).Illuminate\Http\Request:
OpenTelemetry\AutoInstrumentation\Instrumentation\HTTP::register();
use OpenTelemetry\API\GlobalRegistry;
public function handle() {
$span = GlobalRegistry::get(span.class)->getCurrentSpan();
// Queue logic with span context
}
TracerInterface, MeterInterface as singletons.OpenTelemetry\API\Trace\Span in middleware for request tracing.Span with Laravel events (e.g., Illuminate\Queue\Events\JobProcessed).Span context.| 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. |
open-telemetry/api for deprecations (e.g., InstrumentationInterface in 1.9.0).open-telemetry/sdk before major API changes.How can I help you explore Laravel packages today?