PHPackages                             sett/hyperf-tracer - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. sett/hyperf-tracer

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

sett/hyperf-tracer
==================

A open tracing system implemented for Hyperf or other coroutine framework

0386PHP

Since Sep 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kxg3030/hyperf-tracer)[ Packagist](https://packagist.org/packages/sett/hyperf-tracer)[ RSS](/packages/sett-hyperf-tracer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

#### 介绍

[](#介绍)

hyperf框架的链路追踪组件，基于官方包改造完成，要求框架版本^2.0，原来的官方包的tag是固定的，并不实用，代码质量堪忧，这个包在原有的基础上做了修改

#### 特点

[](#特点)

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

#### 使用

[](#使用)

- 安装组件

```
composer require hyperf/tracer
```

- 安装依赖

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

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

- 发布配置

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

- 添加配置

> 在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'  => Sett\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'  => Sett\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' => [
        \Sett\Tracer\Middleware\TraceMiddleware::class,
],
];
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e616afd31323d0e5e1270d55de007a565d67b4e7e87d6af25580fa06b7a81bc?d=identicon)[kxg3030](/maintainers/kxg3030)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[symfony/stopwatch

Provides a way to profile code

2.8k387.2M918](/packages/symfony-stopwatch)[fruitcake/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k662.9k29](/packages/fruitcake-laravel-debugbar)[spatie/ignition

A beautiful error page for PHP applications.

510147.6M69](/packages/spatie-ignition)[jokkedk/webgrind

Webgrind is a Xdebug profiling web frontend in PHP5. It implements a subset of the features of kcachegrind and installs in seconds and works on all platforms. For quick'n'dirty optimizations it does the job.

3.3k193.0k](/packages/jokkedk-webgrind)[koriym/printo

An object graph visualizer.

1421.8M2](/packages/koriym-printo)[soloterm/dumps

A Laravel command to intercept dumps from your Laravel application.

125285.7k3](/packages/soloterm-dumps)

PHPackages © 2026

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