{"id":21424806,"url":"https://github.com/opentelemetry-php/context","last_synced_at":"2025-04-13T08:19:02.160Z","repository":{"id":39410675,"uuid":"495897988","full_name":"opentelemetry-php/context","owner":"opentelemetry-php","description":"[READONLY] Context implementation for OpenTelemetry PHP","archived":false,"fork":false,"pushed_at":"2025-01-09T03:00:39.000Z","size":64,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-17T12:08:10.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentelemetry-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-24T16:12:06.000Z","updated_at":"2024-12-08T17:12:54.000Z","dependencies_parsed_at":"2024-03-04T02:32:31.625Z","dependency_job_id":"faa9b98c-d765-4ca6-8bba-944431ed9ebd","html_url":"https://github.com/opentelemetry-php/context","commit_stats":{"total_commits":28,"total_committers":8,"mean_commits":3.5,"dds":0.6071428571428572,"last_synced_commit":"31814464bb54e62e39e79729bbe6b1fd82324897"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentelemetry-php%2Fcontext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentelemetry-php%2Fcontext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentelemetry-php%2Fcontext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentelemetry-php%2Fcontext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentelemetry-php","download_url":"https://codeload.github.com/opentelemetry-php/context/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245755672,"owners_count":20667027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T21:24:39.331Z","updated_at":"2025-03-27T00:09:56.371Z","avatar_url":"https://github.com/opentelemetry-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/context/releases)\n[![Source](https://img.shields.io/badge/source-context-green)](https://github.com/open-telemetry/opentelemetry-php/tree/main/src/Context)\n[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php:context-blue)](https://github.com/opentelemetry-php/context)\n[![Latest Version](http://poser.pugx.org/open-telemetry/context/v/unstable)](https://packagist.org/packages/open-telemetry/context/)\n[![Stable](http://poser.pugx.org/open-telemetry/context/v/stable)](https://packagist.org/packages/open-telemetry/context/)\n\n# OpenTelemetry Context\n\nImmutable execution scoped propagation mechanism, for further details see [opentelemetry-specification][1].\n\n## Installation\n\n```shell\ncomposer require open-telemetry/context\n```\n\n## Usage\n\n### Implicit propagation\n\n```php\n$context = Context::getCurrent();\n// modify context\n$scope = $context-\u003eactivate();\ntry {\n    // run within new context\n} finally {\n    $scope-\u003edetach();\n}\n```\n\nIt is recommended to use a `try-finally` statement after `::activate()` to ensure that the created scope is properly `::detach()`ed.\n\n### Debug scopes\n\nBy default, scopes created by `::activate()` warn on invalid and missing calls to `::detach()` in non-production\nenvironments. This feature can be disabled by setting the environment variable `OTEL_PHP_DEBUG_SCOPES_DISABLED` to a\ntruthy value. Disabling is only recommended for applications using `exit` / `die` to prevent unavoidable notices.\n\n## Async applications\n\n### Fiber support - automatic context propagation to newly created fibers\n\nRequires 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`.\n\n### Event loops\n\nEvent 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:\n\n```php\nfunction bindContext(Closure $closure): Closure {\n    $context = Context::getCurrent();\n    return static function (mixed ...$args) use ($closure, $context): mixed {\n        $scope = $context-\u003eactivate();\n        try {\n            return $closure(...$args);\n        } finally {\n            $scope-\u003edetach();\n        }\n    };\n}\n```\n\n## Contributing\n\nThis repository is a read-only git subtree split.\nTo contribute, please see the main [OpenTelemetry PHP monorepo](https://github.com/open-telemetry/opentelemetry-php).\n\n[1]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#context\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentelemetry-php%2Fcontext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentelemetry-php%2Fcontext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentelemetry-php%2Fcontext/lists"}