Weave 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

Immutable, execution-scoped context propagation for PHP based on the OpenTelemetry specification. Activate contexts with scopes and detach them safely, with optional fiber support and guidance for event loops.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. open-telemetry/context is not an observability product; it is the propagation primitive underneath one. Its entire surface is a small set of contracts: an immutable Context, an ambient "current context" slot, activate() returning a Scope, and detach(). That is deliberately narrow, which is good for a TPM: it is a stable, low-coupling dependency you adopt once and rarely revisit, not a feature surface you negotiate requirements against. It is framework-agnostic and PSR-friendly, so it slots underneath Laravel rather than competing with Laravel's container, middleware, or logging stack.

The important architectural nuance for planning is that this package is necessary but not sufficient. It moves trace/span/baggage state across execution boundaries, but it does not create spans, sample them, export them, or instrument Laravel. Value only materializes when paired with the OpenTelemetry PHP API/SDK, exporters (OTLP/Zipkin), and Laravel-specific instrumentation. A TPM should treat context as a line item in an observability program of work, not as a deliverable.

The monorepo layout reinforces this: API/ holds interfaces and no-op implementations, SDK/ holds trace/metrics/logs/propagation/resource implementations, Context/ holds storage, scope management, and fiber support, and Contrib/ holds exporters. context is a shared substrate for the SDK layers, which is why it is consumed transitively.

Integration feasibility. Technically trivial: composer require open-telemetry/context, and in practice most teams get it pulled in by the SDK rather than requiring it explicitly. The integration risk is not installation — it is discipline. Every activate() must be paired with detach() in a finally block:

$scope = $context->activate();
try {
    // run within new context
} finally {
    $scope->detach();
}

The package mitigates this with debug scopes that warn on invalid or missing detach() calls in non-production environments. That is a genuine onboarding asset — it turns an invisible class of bug into a visible warning during development — and a TPM can lean on it as the primary safety net during rollout.

Technical risk. Ranked by what would actually affect a roadmap:

Risk Assessment Mitigation
Scope leakage (activate without detach) Moderate — causes wrong parent spans and context bleed between requests/jobs Keep debug scopes on in dev/staging; code review checklist; wrap in middleware/job decorators
Async/fiber support constraints Moderate — requires NTS build, ext-ffi, OTEL_PHP_FIBERS_ENABLED, and autoloader preloading for non-CLI SAPIs when ffi.enable=preload; fiber observers are explicitly unsafe on ZTS Validate the runtime (Octane/Swoole/RoadRunner/FrankenPHP) before committing to async coverage; fall back to manual event-loop binding
Event loops do not propagate automatically High effort, low ambiguity — must wrap callbacks (a documented bindContext pattern) Budget engineering time; this is instrumentation work, not a config flag
PHP version floor Unclear from public metadata — release notes show PHP 7.4 and 8.0 dropped, one summary claims 8.1+, while the monorepo's own agent guidance states PHP 8.2 is the minimum and default Confirm the floor empirically against the pinned tag before planning the upgrade path
Release/cadence signal quality Metadata reports a last release of 2023-09-07, yet the release notes include 1.5.0 and monorepo guidance references PHP 8.5 testing Do not trust the split-package metadata; track the monorepo's tags and its SDK compatibility matrix
exit/die skip detach() Low but real — produces unavoidable notices OTEL_PHP_DEBUG_SCOPES_DISABLED exists but is only recommended for apps that use exit/die; prefer fixing the call sites
Zero listed dependents Not a real risk — a false signal from subtree splitting Judge adoption via the SDK, not this counter

Key questions for engineering before commitment.

  1. Which OpenTelemetry PHP SDK version will we pin, and does it constrain this package's version independently?
  2. What is our actual PHP floor across all services, and does it clear the monorepo's supported matrix?
  3. Which runtimes are in scope — PHP-FPM only, or Octane/Swoole/RoadRunner/FrankenPHP? The answer changes the fiber and event-loop work substantially.
  4. Who owns instrumentation code (middleware, job wrappers, HTTP client hooks), and is that funded separately from "adopting the package"?
  5. Do we need baggage for tenant/request/workflow IDs, and who governs what goes into it (PII risk)?
  6. Is queue context propagation already covered by an existing Laravel instrumentation package, or do we build it?

Integration Approach

Stack fit. The package is a natural fit for a Laravel application that has decided on OpenTelemetry as its observability standard. It is not a fit for a monolith whose only requirement is local request logging — Laravel's logging, Monolog context, and Debugbar solve that with far less machinery. The decision to adopt is therefore a decision about the tracing architecture, and context should be presented to stakeholders that way.

Concretely, it underpins trace continuity across the boundaries where Laravel applications actually lose correlation:

  • HTTP request lifecycle (middleware entering/exiting a scope)
  • Queued jobs, retries, and failed-job handling (Horizon/Redis/database drivers)
  • Scheduled/Artisan commands
  • Outbound HTTP client calls
  • Websocket gateways and event-loop callbacks
  • Fiber-based concurrency, subject to the runtime constraints above

Migration path. Do not require open-telemetry/context directly. Adopt open-telemetry/sdk (plus open-telemetry/exporter-otlp or equivalent) and let context arrive transitively; pin the SDK and treat context as a resolved transitive version. This avoids the classic failure mode of a split package drifting from the SDK it was cut from. Contribution and issue tracking go to the monorepo — the split repo is read-only — so internal upgrade notes should always reference monorepo tags.

For an existing application, the migration is additive rather than disruptive: no schema changes, no data migration, no user-facing behavior change. The real "migration" is a codebase-wide convention that context is scoped and always detached.

Compatibility. Apache-2.0, PSR-friendly, no framework lock-in, no service dependency, no network calls. The compatibility edges that matter are PHP version, thread safety (NTS vs ZTS), the FFI extension for fiber support, and ffi.enable=preload requiring the Composer autoloader to be preloaded for non-CLI SAPIs. Each is discoverable in a short spike and should be explicitly recorded as a platform prerequisite rather than assumed.

Sequencing. Align delivery with the roadmap already implied by the package's value profile:

  1. Foundation — adopt SDK + exporter, establish a resource/service identity convention, agree on backend. Deliverable: traces visible end-to-end for one service.
  2. Request lifecycle and HTTP clients — middleware and HTTP client hooks. Deliverable: a user request produces a coherent trace with downstream calls attached. Highest value per unit of effort.
  3. Queues and scheduled jobs — job middleware that re-activates propagated context on dispatch and restores it on execution. Deliverable: an order or job can be followed from request into worker. This is where most of the business value (support workflows, incident triage) is unlocked.
  4. Async surfaces — event loops, websockets, fibers, gated on the runtime spike. Lowest priority, highest uncertainty.
  5. Correlation with logs and metrics, plus sampling policy and exporter/backend strategy review.

An important TPM guardrail: each phase must produce an observable artifact (a trace someone actually used to debug something). "Adopt the context package" is not a phase; it is a dependency of every phase and a milestone nobody should be asked to sign off on.

Operational Impact

Maintenance. Low churn on the code itself — the API is a handful of methods and the release history is dominated by small fixes, CI hygiene, and PHP-version compatibility work rather than behavioral change. The maintenance burden sits with the ecosystem: keeping SDK, exporter, and instrumentation versions aligned with the monorepo, and re-testing the fiber/event-loop paths whenever the PHP runtime or a long-running server (Octane, Swoole) is upgraded. Assign one named owner; a package with no direct dependents and no commercial support will not maintain itself by accident.

Support. Community-maintained, CNCF-governed, Apache-2.0, no vendor SLA. The split repo is read-only and contribution flows to the monorepo, so internal tickets cannot be filed upstream in the place engineers will naturally look. Expect to solve our own integration problems and to treat upstream only as a source of fixes for spec-level behavior. The debug-scope warnings are the best first-line support tool we get for free.

Scaling. The context layer itself is negligible: an immutable context object and a scope stack, with per-activation cost dominated by PHP object allocation, not by the package. Real scaling cost comes from span volume, sampling decisions, and exporter throughput — all owned by the SDK and backend choices, not by context. The one scaling caveat worth writing down is fiber propagation: it depends on FFI hooking, is explicitly unsafe on ZTS builds, and requires autoloader preloading under ffi.enable=preload. If horizontal scaling means moving to a persistent-worker runtime, re-validate this path rather than assuming it carries over.

Failure modes. Enumerate these in a runbook, because most are silent:

  • Scope leak — activate() without detach() leaves stale context active; downstream spans get the wrong parent and correlation becomes misleading rather than broken, which is worse. Detect via non-production debug-scope warnings; prevent via middleware and job decorators that own the try/finally.
  • Process-exit leaks — exit/die bypasses detach() by design; this is the documented reason OTEL_PHP_DEBUG_SCOPES_DISABLED exists, and it should only be used where exit/die is unavoidable.
  • Shutdown-time out-of-order destruction — historically addressed in patch releases; a reason to stay on a current patch rather than pinning an old minor.
  • Callback context capture in event loops — helpers that bind context to closures risk retaining references to large arguments if implemented naively; the documentation explicitly warns to avoid holding unnecessary references.
  • Missing fiber propagation — on unsupported runtimes, context silently does not follow into fibers, producing traces that look complete but are truncated. Treat "fiber coverage validated" as a gate, not an assumption.
  • Baggage creep — an unbounded, ungoverned baggage namespace is both a memory concern and a PII exposure path. Define allowed keys centrally.

Ramp-up. The API is learnable in an hour; the mental model is not. Engineers must internalize implicit vs. explicit propagation, the scope stack, and why an immutable context plus a detached scope is the correct pattern — otherwise they will pass context explicitly "to be safe," which defeats the point, or forget to detach, which corrupts traces quietly. Budget for a short internal enablement session, a documented convention (middleware and job wrappers as the only places that call activate()), a code-review checklist, and a working reference implementation in one service before asking other teams to follow. The debug scopes do most of the teaching for free if left enabled outside production.

Net TPM position: adopt this as the context primitive when OpenTelemetry is the chosen observability standard, fund the Laravel instrumentation around it as a separate and larger workstream, sequence queues ahead of async/fiber work, and validate the runtime matrix before promising coverage of long-running workers. The package is small, cheap, and standards-aligned; the program it enables is neither small nor cheap, and the roadmap should be honest about which one is being approved.

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.
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
adachsoft/changelog-linter