open-telemetry/context
OpenTelemetry Context for PHP: immutable execution-scoped context propagation. Activate a context to create a scope and safely detach it (try/finally). Includes debug scope warnings, and optional async support for fibers and event loops.
Unified Observability for Laravel Ecosystem: Enables end-to-end trace propagation across HTTP requests, queues (Laravel Horizon, queues), async workers (Swoole, fibers), and CLI commands (Artisan). Directly supports the 2024 observability roadmap by adhering to OpenTelemetry’s context and baggage specification, ensuring compatibility with tools like Jaeger, Datadog, and Honeycomb. Critical for debugging latency in distributed systems or third-party integrations (e.g., payment gateways, APIs).
Async and Event-Driven Architecture: Automates context propagation in fibers and event loops, eliminating manual errors in callbacks. Enables high-concurrency patterns such as:
dispatchSync with trace correlation).bindContext().
Build vs. buy: Avoids reinventing context management for async PHP, reducing technical debt and ensuring consistency with OpenTelemetry standards.OpenTelemetry Integration:
Spec-compliant baggage propagation ensures trace IDs and metadata (e.g., user_id, tenant_id) flow seamlessly across services. Integrates with:
opentelemetry-php/sdk).Context::getBaggage().
Avoids vendor lock-in by adhering to open standards, ensuring flexibility in choosing observability backends.Compliance and Auditing: Associates trace IDs with user actions in logs, databases, or monitoring systems, simplifying:
Roadmap Phases:
| Phase | Focus Area | Key Deliverable |
|---|---|---|
| Q1 2024 | Core tracing | Instrument middleware, HTTP clients. |
| Q2 2024 | Async propagation | Fiber/event-loop support for queues/CLI. |
| Q3 2024 | Extended observability | Metrics/logs integration via baggage. |
| Q4 2024 | Compliance and auditing | Automated trace correlation for logs. |
opentelemetry-php/sdk or plan to integrate with OpenTelemetry-compatible backends (Jaeger, Datadog, Honeycomb).getAll in TextMap) are fully available and critical for async workflows.tenant_id, session_id) to traces or logs for enriched debugging.stack/stack or custom solutions exist but lack spec compliance and interoperability.OTEL_PHP_DEBUG_SCOPES_DISABLED only if your app uses exit/die frequently (not recommended for production due to potential memory leaks or missed detaches).*"This is a strategic investment in observability that will reduce debugging time by 40% and future-proof our Laravel stack as we scale microservices and async workloads.
The Problem: Today, tracing a user’s journey—from their first click to a failed payment API call—is like solving a puzzle with missing pieces. Without standardized trace IDs and metadata, we’re blind to latency bottlenecks, compliance gaps, and security risks. Our current logging and monitoring tools provide siloed data, making it difficult to correlate events across services.
The Solution: The OpenTelemetry Context package standardizes trace propagation across all services, ensuring every request, queue job, or fiber carries its trace ID and custom metadata. This isn’t just about logging—it’s about connecting the dots in real time with end-to-end visibility.
Why Now?
Ask: Approve a 6-month pilot to integrate this into our core Laravel stack, starting with middleware and queue instrumentation. The cost is minimal (developer time for integration), and the upside is transformative for our observability capabilities."
*"This package solves a critical gap in our observability stack by providing a standardized, spec-compliant way to propagate context across synchronous and asynchronous code in PHP. Here’s why it’s a game-changer:
Key Benefits:
End-to-End Trace Propagation:
Async-First Design:
ext-ffi).bindContext() utility to restore context in callbacks (ReactPHP, Amp, Swoole).Debugging and Safety:
detach() calls in non-production (configurable via OTEL_PHP_DEBUG_SCOPES_DISABLED).Compliance and Metadata:
user_id, tenant_id) to traces for enriched debugging and auditing.Implementation Plan:
Why Not Build This?
Next Steps:
*"This package is your secret weapon for observability in Laravel, especially if you work with:
How to Use It:
How can I help you explore Laravel packages today?