open-telemetry/context
Composer 安装命令:
composer require open-telemetry/context
包简介
Context implementation for OpenTelemetry PHP.
关键字:
README 文档
README
OpenTelemetry Context
Immutable execution scoped propagation mechanism, for further details see opentelemetry-specification.
Installation
composer require open-telemetry/context
Usage
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
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
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 is set to preload.
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
This repository is a read-only git subtree split. To contribute, please see the main OpenTelemetry PHP monorepo.
open-telemetry/context 适用场景与选型建议
open-telemetry/context 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.6M 次下载、GitHub Stars 达 15, 最近一次更新时间为 2022 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Context」 「opentelemetry」 「otel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 open-telemetry/context 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 open-telemetry/context 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 open-telemetry/context 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Behat Context for testing Symfony Api
Context support (request, session and application scope) for n2n framework.
OpenTelemetry auto-instrumentation for PHP Session functions
OpenTelemetry SDK rule-based sampler
The Azure package for opentelemetry-php
OpenTelemetry auto-instrumentation for Laravel
统计信息
- 总下载量: 40.6M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 24
- 依赖项目数: 51
- 推荐数: 1
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2022-05-24