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 for tracing and telemetry. Activate/detach scopes for implicit propagation, with debug warnings for scope leaks. Supports async apps with fiber-based propagation and event loop binding.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Unified Observability for Laravel Applications: Enables end-to-end traceability across HTTP requests, queues (Horizon), async workers (Swoole, fibers), and CLI commands (Artisan). Directly supports the observability roadmap by integrating with OpenTelemetry’s context propagation, ensuring compatibility with tools like Datadog APM, New Relic, and Lightstep. Critical for debugging latency in microservices, third-party integrations, and complex workflows.

  • Async and Event-Driven Architecture: Automates context propagation in fibers, event loops, and Swoole coroutines, eliminating manual errors in callbacks. Key use cases include:

    • Real-time WebSocket gateways (Laravel Echo, Pusher) with traceable event flows.
    • Background job workflows (e.g., dispatchSync with trace correlation for retries).
    • Custom event loops (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, span IDs, and custom metadata flow seamlessly across services. Integrates with:

    • OpenTelemetry PHP SDK (opentelemetry-php/sdk).
    • Existing exporters (e.g., Jaeger, Zipkin, OTLP).
    • Future extensions (metrics, logs) via Context::getBaggage(). Avoids vendor lock-in by adhering to open standards, ensuring compatibility with any OpenTelemetry-compatible backend.
  • Compliance and Auditing: Associates trace IDs with user actions in logs, databases, or monitoring systems, simplifying:

    • GDPR data subject requests (tracking user data flows).
    • Financial audits (e.g., transaction tracing for PCI DSS compliance).
    • Security investigations (e.g., tracking malicious requests or brute-force attempts).
  • Roadmap Alignment: Supports phased rollout for observability:

    • Q1 2024: Instrument Laravel middleware and HTTP clients (Guzzle, Symfony HTTP Client).
    • Q2 2024: Enable async propagation for fibers, event loops, and Swoole.
    • Q3 2024: Integrate metrics/logs via baggage for unified observability.
    • Q4 2024: Pre-built adapters for Datadog, New Relic, and Lightstep to reduce APM vendor costs.

When to Consider This Package

Adopt This Package If:

  • Distributed tracing is critical: Your Laravel app interacts with microservices, APIs, or async systems (e.g., Swoole, fibers) where trace correlation is essential for debugging.
  • 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, Lightstep).
  • Compliance/auditing requires traceability: GDPR, financial (PCI DSS), or security use cases demand traceable request flows for audits or investigations.
  • PHP 8.1+ is your baseline: Fiber support and modern features (e.g., getAll in TextMap) are fully available.
  • Observability roadmap includes baggage/metadata: You plan to attach custom metadata (e.g., tenant_id, request_id) to traces or logs for enriched debugging.
  • Laravel ecosystem is complex: You use queues (Horizon), WebSockets (Echo), or async job processing (Swoole) where context loss leads to debugging challenges.

Look Elsewhere If:

  • No distributed tracing needed: Basic request logging (e.g., Monolog, Laravel Debugbar) suffices for monolithic apps without external dependencies.
  • PHP < 8.1: Fiber support is unavailable; async features may require workarounds or alternative libraries like stack/stack.
  • Not using OpenTelemetry: This package is tightly coupled to the OpenTelemetry ecosystem. Alternatives like stack/stack or custom solutions exist but lack spec compliance.
  • 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, Datadog), the package’s value is limited to basic trace IDs.
  • Vendor lock-in is a concern: While OpenTelemetry is open, some backends (e.g., Datadog) may require proprietary extensions. Evaluate if this aligns with your multi-vendor strategy.

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 a WebSocket event to a payment processing job—requires piecing together logs from multiple services. Without context propagation, we lose critical traceability, increasing mean time to resolution (MTTR) and operational costs.

The Solution: The open-telemetry/context package enables end-to-end trace propagation across all Laravel components—HTTP requests, queues, fibers, and CLI commands—using OpenTelemetry’s industry-standard specification. This ensures:

  • 40% faster incident resolution by correlating traces across microservices.
  • 20% reduction in APM costs by leveraging open standards (OpenTelemetry) instead of vendor-specific solutions.
  • Compliance-ready auditing for GDPR, PCI DSS, and security investigations.
  • Seamless integration with existing tools like Datadog, New Relic, and Lightstep, reducing vendor lock-in risks.
  • Future-proof architecture for async PHP (fibers, Swoole) and microservices.

Ask: Approve a 6-week pilot to instrument our core Laravel services (API, queues, and WebSocket layers) with this package. We’ll measure MTTR improvements and cost savings against our current APM tools.

Risk: Minimal—this is a standardized, battle-tested OpenTelemetry component with no vendor lock-in. We’ll start with a non-production environment to validate performance."


For Engineering Teams:

*"This package solves three critical pain points in our Laravel observability stack:

  1. Async Context Propagation:

    • Automatically carries trace IDs through fibers, event loops (ReactPHP/Amp), and Swoole coroutines—no more manual span->setAttribute() hacks in callbacks.
    • Example: A WebSocket event triggered by a fiber now automatically inherits the parent trace, eliminating debugging dead ends.
  2. OpenTelemetry Compliance:

    • Spec-compliant baggage propagation ensures trace IDs, span IDs, and custom metadata (e.g., user_id) flow seamlessly across services.
    • Integrates with our existing opentelemetry-php/sdk setup, requiring zero changes to our exporters (Jaeger, OTLP).
  3. Debugging Superpowers:

    • Baggage API lets us attach metadata (e.g., tenant_id, request_id) to traces/logs for enriched debugging.
    • Debug scopes catch context leaks in development (e.g., forgotten detach() calls) without production noise.

Implementation Plan:

  • Week 1-2: Instrument Laravel middleware and HTTP clients (Guzzle) to propagate context.
  • Week 3-4: Add fiber/event-loop support for async services (Swoole, ReactPHP).
  • Week 5-6: Validate with a canary release in staging, focusing on trace correlation and baggage metadata.

Dependencies:

  • Requires PHP 8.1+ (for fibers) and ext-ffi for fiber support (enable via OTEL_PHP_FIBERS_ENABLED).
  • Works alongside our existing OpenTelemetry SDK—no breaking changes.

Alternatives Considered:

  • Custom context stack: Too much reinvention; this package is spec-compliant and maintained.
  • Vendor-specific tools: Locks us into Datadog/New Relic; OpenTelemetry is multi-vendor compatible.

Next Steps:

  • Review the usage docs for implicit propagation and fiber support.
  • Test the bindContext() pattern for our event loops (e.g., ReactPHP).
  • Schedule a sync to align on baggage metadata standards (e.g., X-Request-ID headers).

Goal: Reduce MTTR for async issues by 50% and enable compliance-ready tracing for audits."

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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle