PHPackages                             open-telemetry/context - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. open-telemetry/context

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

open-telemetry/context
======================

Context implementation for OpenTelemetry PHP.

1.5.0(7mo ago)1532.6M—8.4%20Apache-2.0PHPPHP ^8.1

Since Dec 31Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/opentelemetry-php/context)[ Packagist](https://packagist.org/packages/open-telemetry/context)[ RSS](/packages/open-telemetry-context/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (33)Used By (20)

[![Releases](https://camo.githubusercontent.com/46e38a504120203bf7615645011bcf2bb834e03e8eb0bc8e0f4864c729fd5baf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656c65617365732d707572706c65)](https://github.com/opentelemetry-php/context/releases)[![Source](https://camo.githubusercontent.com/cd73a491818157f64c4ef640a06da097bbdc379cd053bd415aadbfb644993d52/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d636f6e746578742d677265656e)](https://github.com/open-telemetry/opentelemetry-php/tree/main/src/Context)[![Mirror](https://camo.githubusercontent.com/34a3b1d6de973802d589187872ff458063f36ed27d3ff757e657eb1c571e9cab/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d6972726f722d6f70656e74656c656d657472792d2d7068703a636f6e746578742d626c7565)](https://github.com/opentelemetry-php/context)[![Latest Version](https://camo.githubusercontent.com/d24ce4030990fe22deb14291861a601ae12fdd8a7213781d216b5b50f4f59cad/687474703a2f2f706f7365722e707567782e6f72672f6f70656e2d74656c656d657472792f636f6e746578742f762f756e737461626c65)](https://packagist.org/packages/open-telemetry/context/)[![Stable](https://camo.githubusercontent.com/4ebfce8dcb9d5515166856227e290bcb2770d660f2ec7d363a9e88f6f800a5b4/687474703a2f2f706f7365722e707567782e6f72672f6f70656e2d74656c656d657472792f636f6e746578742f762f737461626c65)](https://packagist.org/packages/open-telemetry/context/)

OpenTelemetry Context
=====================

[](#opentelemetry-context)

Immutable execution scoped propagation mechanism, for further details see [opentelemetry-specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#context).

Installation
------------

[](#installation)

```
composer require open-telemetry/context
```

Usage
-----

[](#usage)

### Implicit propagation

[](#implicit-propagation)

```
$context = Context::getCurrent();
// modify context
$scope = $context->activate();
try {
    // run within new context
} finally {
    $scope->detach();
}
```

It is recommended to use a `try-finally` statement after `::activate()` to ensure that the created scope is properly `::detach()`ed.

### Debug scopes

[](#debug-scopes)

By default, scopes created by `::activate()` warn on invalid and missing calls to `::detach()` in non-production environments. This feature can be disabled by setting the environment variable `OTEL_PHP_DEBUG_SCOPES_DISABLED` to a truthy value. Disabling is only recommended for applications using `exit` / `die` to prevent unavoidable notices.

Async applications
------------------

[](#async-applications)

### Fiber support - automatic context propagation to newly created fibers

[](#fiber-support---automatic-context-propagation-to-newly-created-fibers)

Requires an NTS build, `ext-ffi`, and setting the environment variable `OTEL_PHP_FIBERS_ENABLED` to a truthy value. Additionally `vendor/autoload.php` has to be preloaded for non-CLI SAPIs if [`ffi.enable`](https://www.php.net/manual/en/ffi.configuration.php#ini.ffi.enable) is set to `preload`.

### Event loops

[](#event-loops)

Event loops have to restore the original context on callback execution. A basic implementation could look like the following, though implementations should avoid keeping unnecessary references to arguments if possible:

```
function bindContext(Closure $closure): Closure {
    $context = Context::getCurrent();
    return static function (mixed ...$args) use ($closure, $context): mixed {
        $scope = $context->activate();
        try {
            return $closure(...$args);
        } finally {
            $scope->detach();
        }
    };
}
```

Contributing
------------

[](#contributing)

This repository is a read-only git subtree split. To contribute, please see the main [OpenTelemetry PHP monorepo](https://github.com/open-telemetry/opentelemetry-php).

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance78

Regular maintenance activity

Popularity56

Moderate usage in the ecosystem

Community35

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Recently: every ~32 days

Total

32

Last Release

212d ago

Major Versions

0.0.16 → 1.0.0beta12022-11-25

0.0.17 → 1.0.0beta22022-11-25

1.2.1 → 2.x-dev2025-06-12

PHP version history (3 changes)0.0.9PHP ^7.4 || ^8.0

1.1.0beta1PHP ^8.1

2.x-devPHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4978962?v=4)[Brett McBride](/maintainers/brettmc)[@brettmc](https://github.com/brettmc)

![](https://avatars.githubusercontent.com/u/4099109?v=4)[Bob Strecansky](/maintainers/bobstrecansky)[@bobstrecansky](https://github.com/bobstrecansky)

![](https://www.gravatar.com/avatar/69cffb51399d5672406e66e7abb83f547f0f75755746d1b6144ce4042429c8e1?d=identicon)[otel-php-bot](/maintainers/otel-php-bot)

![](https://www.gravatar.com/avatar/6c8d11f4cc2c4bb65832357398092369df3b5ecda1171441be8c6a75e844f97f?d=identicon)[tidal](/maintainers/tidal)

---

Top Contributors

[![Nevay](https://avatars.githubusercontent.com/u/22509671?v=4)](https://github.com/Nevay "Nevay (14 commits)")[![brettmc](https://avatars.githubusercontent.com/u/4978962?v=4)](https://github.com/brettmc "brettmc (12 commits)")[![tidal](https://avatars.githubusercontent.com/u/57825?v=4)](https://github.com/tidal "tidal (11 commits)")[![Blacksmoke16](https://avatars.githubusercontent.com/u/12136995?v=4)](https://github.com/Blacksmoke16 "Blacksmoke16 (3 commits)")[![ycchuang99](https://avatars.githubusercontent.com/u/138915122?v=4)](https://github.com/ycchuang99 "ycchuang99 (2 commits)")[![PROFeNoM](https://avatars.githubusercontent.com/u/42672104?v=4)](https://github.com/PROFeNoM "PROFeNoM (1 commits)")[![stickeegreg](https://avatars.githubusercontent.com/u/48593081?v=4)](https://github.com/stickeegreg "stickeegreg (1 commits)")[![andypost](https://avatars.githubusercontent.com/u/73713?v=4)](https://github.com/andypost "andypost (1 commits)")[![yuktea](https://avatars.githubusercontent.com/u/73362292?v=4)](https://github.com/yuktea "yuktea (1 commits)")[![jerrytfleung](https://avatars.githubusercontent.com/u/8791493?v=4)](https://github.com/jerrytfleung "jerrytfleung (1 commits)")[![marcospassos](https://avatars.githubusercontent.com/u/943036?v=4)](https://github.com/marcospassos "marcospassos (1 commits)")[![morrisonlevi](https://avatars.githubusercontent.com/u/253316?v=4)](https://github.com/morrisonlevi "morrisonlevi (1 commits)")[![pieterocp](https://avatars.githubusercontent.com/u/68863060?v=4)](https://github.com/pieterocp "pieterocp (1 commits)")

---

Tags

opentelemetryotelContext

### Embed Badge

![Health badge](/badges/open-telemetry-context/health.svg)

```
[![Health](https://phpackages.com/badges/open-telemetry-context/health.svg)](https://phpackages.com/packages/open-telemetry-context)
```

###  Alternatives

[open-telemetry/api

API for OpenTelemetry PHP.

1933.0M214](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2322.9M248](/packages/open-telemetry-sdk)[open-telemetry/opentelemetry-auto-symfony

OpenTelemetry auto-instrumentation for Symfony

551.2M1](/packages/open-telemetry-opentelemetry-auto-symfony)[open-telemetry/context-swoole

Async Swoole/OpenSwoole context implementation for OpenTelemetry PHP.

1233.2k5](/packages/open-telemetry-context-swoole)[open-telemetry/opentelemetry-auto-pdo

OpenTelemetry auto-instrumentation for PDO

111.2M1](/packages/open-telemetry-opentelemetry-auto-pdo)[open-telemetry/opentelemetry-auto-wordpress

OpenTelemetry auto-instrumentation for Wordpress

17166.0k](/packages/open-telemetry-opentelemetry-auto-wordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
