PHPackages                             sett/hyperf-tracer-v2.1 - 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. sett/hyperf-tracer-v2.1

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

sett/hyperf-tracer-v2.1
=======================

A open tracing system implemented for Hyperf or other coroutine framework

v1.1(2y ago)1330MITPHPPHP &gt;=7.2

Since Aug 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/kxg3030/hyperf-tracer-v2.1)[ Packagist](https://packagist.org/packages/sett/hyperf-tracer-v2.1)[ Docs](https://hyperf.io)[ RSS](/packages/sett-hyperf-tracer-v21/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (13)Versions (2)Used By (0)

#### 介绍

[](#介绍)

适配Hyperf框架2.1.\*版本的链路追踪包，可以自定义设置链路的记录项

#### 特点

[](#特点)

- 支持自定义tag，通过闭包完全自定义
- 删除了冗余文件，增加代码可读性

#### 使用

[](#使用)

- 安装组件

```
composer require sett/hyperf-tracer-v2.1
```

- 安装依赖

> 如果不是使用的是jaeger作为链路，可以忽略这一步

```
composer require jonahgeorge/jaeger-client-php
```

- 发布配置

```
php bin/hyperf.php vendor:publish sett/hyperf-tracer-v2.1
```

- 添加配置

> 在config/autoload/opentracing.php文件中添加

```
# 以下配置是组件默认的配置，可以按照自己的需求修改
return [
    # 链路驱动
    'default' => env('TRACER_DRIVER', 'zipkin'),
    # 开启/关闭以下追踪
    'enable'  => [
        'guzzle'    => env('TRACER_ENABLE_GUZZLE', true),
        'redis'     => env('TRACER_ENABLE_REDIS', true),
        'db'        => env('TRACER_ENABLE_DB', true),
        'method'    => env('TRACER_ENABLE_METHOD', false),
        'exception' => env('TRACER_ENABLE_EXCEPTION', false),
    ],
    'tracer'  => [
        'zipkin' => [
            'driver'  => Hyperf\Tracer\Adapter\ZipkinTracerFactory::class,
            'app'     => [
                'name' => env('APP_NAME', 'skeleton'),
                'ipv4' => '127.0.0.1',
                'ipv6' => null,
                'port' => 9501,
            ],
            'options' => [
                'endpoint_url' => env('ZIPKIN_ENDPOINT_URL', 'http://localhost:9411/api/v2/spans'),
                'timeout'      => env('ZIPKIN_TIMEOUT', 1),
            ],
            'sampler' => BinarySampler::createAsAlwaysSample(),
        ],
        'jaeger' => [
            'driver'  => Hyperf\Tracer\Adapter\JaegerTracerFactory::class,
            'name'    => env('APP_NAME', 'skeleton'),
            'options' => [
                'sampler'     => [
                    'type'  => SAMPLER_TYPE_CONST,
                    'param' => true,
                ],
                'local_agent' => [
                    'reporting_host' => env('JAEGER_REPORTING_HOST', 'localhost'),
                    'reporting_port' => env('JAEGER_REPORTING_PORT', 5775),
                ],
                'max_buffer_length' => "1024"
            ],
        ],
    ],
    'tags'    => [
        # 请求外部接口记录
        'http_client' => function (Span $span, array $data) {
            $method = $data['keys']['method'] ?? 'null';
            $uri    = $data['keys']['uri'] ?? 'null';
            $span->setTag("http.url", $uri);
            $span->setTag("http.method", $method);
        },
        # redis
        'redis'       => function (Span $span, array $data) {
            $span->setTag("redis.arguments", Json::encode($data['arguments']));
        },
        # 数据库
        'db'          => function (Span $span, array $data) {
            $span->setTag("db.query", Json::encode($data['arguments'], JSON_UNESCAPED_UNICODE));
        },
        # 异常记录
        'exception'   => function (Span $span, \Throwable $throwable) {
            $span->setTag("exception.class", get_class($throwable));
            $span->setTag("exception.code", $throwable->getCode());
            $span->setTag("exception.error", $throwable->getMessage());
            $span->setTag("exception.trace", $throwable->getTraceAsString());
        },
        # 外部请求接口时记录的值
        'request'     => function (Span $span) {
            $request = Context::get(ServerRequestInterface::class);
            $span->setTag("http.get.params", Json::encode($request->getQueryParams(), JSON_UNESCAPED_UNICODE));
            $span->setTag("http.post.params", Json::encode($request->getParsedBody(), JSON_UNESCAPED_UNICODE));
        },
        # 记录协程ID
        'coroutine'   => function (Span $span, array $data) {
            $span->setTag("coroutine.id", Coroutine::id());
        },
        # 外部请求接口时记录返回值
        'response'    => function (Span $span) {
            /**@var $response ResponseInterface */
            $response = Context::get(ResponseInterface::class);
            $span->setTag("response.status", (string)$response->getStatusCode());
        },
    ],
]
```

- 添加中间件

> 在config/autoload/middlewares.php文件中添加

```
return [
    'http' => [
        \Hyperf\Tracer\Middleware\TraceMiddleware::class,
],
];
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

1061d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/48542529?v=4)[彩色函数](/maintainers/kxg3030)[@kxg3030](https://github.com/kxg3030)

---

Top Contributors

[![kxg2020](https://avatars.githubusercontent.com/u/22949288?v=4)](https://github.com/kxg2020 "kxg2020 (8 commits)")

---

Tags

phphyperfzipkinopen-tracing

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/sett-hyperf-tracer-v21/health.svg)

```
[![Health](https://phpackages.com/badges/sett-hyperf-tracer-v21/health.svg)](https://phpackages.com/packages/sett-hyperf-tracer-v21)
```

###  Alternatives

[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[friendsofhyperf/sentry

The sentry component for Hyperf.

1974.5k](/packages/friendsofhyperf-sentry)

PHPackages © 2026

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