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

Context Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • 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:

    • Real-time WebSocket gateways (Laravel Echo, Pusher).
    • Background job workflows (e.g., dispatchSync with trace correlation).
    • Custom event loops (e.g., ReactPHP, Amp) via 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 (opentelemetry-php/sdk).
    • Existing exporters (e.g., Jaeger, Zipkin).
    • Future extensions (metrics, logs) via 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:

    • GDPR data subject requests.
    • Financial audits (e.g., transaction tracing).
    • Security investigations (e.g., tracking malicious requests). Reduces manual effort in correlating logs and traces across systems.
  • 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.

When to Consider This Package

Adopt This Package If:

  • Distributed tracing is a priority: Your Laravel application interacts with microservices, APIs, or async systems (e.g., Swoole, fibers) where trace correlation is critical for debugging and performance tuning.
  • Async PHP is in use: You leverage fibers, event loops (ReactPHP, Amp), or Swoole coroutines and need automatic context propagation to avoid manual errors in callbacks.
  • OpenTelemetry is already adopted or planned: You use opentelemetry-php/sdk or plan to integrate with OpenTelemetry-compatible backends (Jaeger, Datadog, Honeycomb).
  • Compliance or auditing requires traceability: GDPR, financial, or security use cases demand traceable request flows for auditing or investigations.
  • PHP 8.1+ is your baseline: Fiber support and modern features (e.g., getAll in TextMap) are fully available and critical for async workflows.
  • Observability roadmap includes baggage/metadata: You plan to attach custom metadata (e.g., tenant_id, session_id) to traces or logs for enriched debugging.

Look Elsewhere If:

  • No distributed tracing needed: Basic request logging (e.g., Monolog) suffices for monolithic apps without external dependencies or async workflows.
  • PHP < 8.1: Fiber support is unavailable; async features may require significant workarounds or alternative solutions.
  • Not using OpenTelemetry: This package is tightly coupled to the OpenTelemetry ecosystem. Alternatives like stack/stack or custom solutions exist but lack spec compliance and interoperability.
  • Async workloads are trivial: Simple Redis queues or synchronous jobs don’t require fiber/event-loop context propagation.
  • No observability tooling: Without an OpenTelemetry-compatible backend (e.g., Jaeger), the package’s value is limited to basic trace IDs without metadata or advanced features.
  • Debug scopes are problematic: Disable via 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).

How to Pitch It (Stakeholders)

For Executives:

*"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?

  • Aligns with our 2024 roadmap for observability and scalability, reducing technical debt by adopting open standards.
  • Future-proofs our architecture for microservices, async workloads, and compliance requirements without vendor lock-in.
  • Delivers immediate ROI by cutting mean time to resolution (MTTR) for critical issues by 40% through correlated traces.
  • Enables innovation in real-time systems (e.g., WebSockets, event-driven workflows) with seamless context propagation.

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."


For Engineering Teams:

*"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:

  1. End-to-End Trace Propagation:

    • Automatically carries trace IDs and baggage (custom metadata) across HTTP requests, queues, fibers, and event loops.
    • Works seamlessly with OpenTelemetry SDK and exporters (Jaeger, Datadog, etc.).
  2. Async-First Design:

    • Fiber support: Automatic context propagation to newly created fibers (with NTS build and ext-ffi).
    • Event loop integration: Simple bindContext() utility to restore context in callbacks (ReactPHP, Amp, Swoole).
    • Eliminates manual context management errors in async code.
  3. Debugging and Safety:

    • Debug scopes: Warns about missing detach() calls in non-production (configurable via OTEL_PHP_DEBUG_SCOPES_DISABLED).
    • Immutable context design prevents race conditions or leaks.
  4. Compliance and Metadata:

    • Attach custom metadata (e.g., user_id, tenant_id) to traces for enriched debugging and auditing.
    • Supports GDPR, financial audits, and security investigations out of the box.

Implementation Plan:

  • Phase 1 (Q1 2024): Instrument middleware, HTTP clients, and Artisan commands.
  • Phase 2 (Q2 2024): Add fiber/event-loop support for queues and async workers.
  • Phase 3 (Q3 2024): Integrate with OpenTelemetry SDK for metrics/logs.

Why Not Build This?

  • OpenTelemetry spec compliance: Avoids reinventing the wheel and ensures interoperability with industry standards.
  • Mature and tested: Backed by the OpenTelemetry community with active maintenance.
  • Low risk: Minimal boilerplate; integrates cleanly with existing Laravel services.

Next Steps:

  • Review the usage examples and async support.
  • Schedule a spike to test fiber/event-loop integration in our Swoole/ReactPHP workflows.
  • Align with the OpenTelemetry SDK team to ensure seamless baggage propagation."

For Developers:

*"This package is your secret weapon for observability in Laravel, especially if you work with:

  • Microservices or APIs: Propagate trace IDs across services automatically.
  • Async code: Fibers, event loops, or queues? Context is handled for you.
  • Debugging nightmares: Correlate logs, traces, and metrics with custom baggage.

How to Use It:

  1. Basic Context:
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport