PHPackages                             felix021/xtracer - 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. felix021/xtracer

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

felix021/xtracer
================

317PHP

Since Mar 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/felix021/xtracer)[ Packagist](https://packagist.org/packages/felix021/xtracer)[ RSS](/packages/felix021-xtracer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

xtracer
=======

[](#xtracer)

tracer library for yii2, compatible with jaeger.

Usage
-----

[](#usage)

### 0. Install Yii2

[](#0-install-yii2)

`$ composer create-project --prefer-dist yiisoft/yii2-app-basic basic`

### 1. Install felix021/xtracer

[](#1-install-felix021xtracer)

`$ composer require felix021/xtracer:dev-master`

### 2. Config

[](#2-config)

#### 2.1 `config/web.php`

[](#21-configwebphp)

*NOTE*: you should set an identifiable name for each application.

```
$config = [
    'name' => '', # will be saved to log
    ...
    'on beforeAction' => ['XTracer\Tracer','beforeAction'],
    'on afterAction' => ['XTracer\Tracer','afterAction'],
    ...
    components => [
        ...
        'tracer' => [
            'class' => 'XTracer\Tracer',
            'maskRules' => [
                ['mobile', 'prefixSuffix', [3, 4]],
                ['password', 'all', [8]],
                ['name', 'prefix', [-1]],
            ],
        ],
        ...
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'XTracer\FileTarget',
                    'levels' => ['info', 'error', 'warning'],
                    'logVars' => [],
                ],
                [
                    'class' => 'XTracer\FileTarget',
                    'levels' => ['info'],
                    'categories' => ['jaeger'],
                    'logFile' => '@runtime/logs/jaeger.log',
                    'logVars' => [],
                ],
            ],
        ],
        ...
        # not necessary, but I'll leave it here as a guide
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        ...
    ],
];

```

#### 2.2 `config/console.php`

[](#22-configconsolephp)

```
$config = [
    'id' => '' # it should be the same as in `config/web.php`
    ...
    'on beforeAction' => ['XTracer\Tracer','beforeAction'],
    'on afterAction' => ['XTracer\Tracer','afterAction'],
    ...
    components => [
        ...
        'tracer' => [
            'class' => 'XTracer\Tracer',
            'maskRules' => [
                ['mobile', 'prefixSuffix', [3, 4]],
                ['password', 'all', [8]],
                ['name', 'prefix', [-1]],
            ],
        ],
        ...
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'XTracer\FileTarget',
                    'levels' => ['info', 'error', 'warning'],
                    'logVars' => [],
                ],
                [
                    'class' => 'XTracer\FileTarget',
                    'levels' => ['info'],
                    'categories' => ['jaeger'],
                    'logFile' => '@runtime/logs/jaeger.log',
                    'logVars' => [],
                ],
            ],
        ],
        ...
    ],
];

```

### 3. Trace &amp; Log

[](#3-trace--log)

Each time when yii receives a http request, or begins to execute a console commmand, a span will be created. After execution, trace info will be saved to `@app/runtime/logs/jaeger.log`, one line per span in json format. `jaeger.log` is supposed to be send to a backend storage like ElasticSearch for later analysis.

Use `Yii::info($message)` to log extra running information, which will be saved to `@app/runtime/logs/app.log`, one line per log in json format as well.

In addition, when a http request is received, a message containing `$_GET`, `$_POST` and `$_SERVER` will be saved to `@app/runtime/logs/app.log` for debug purpose.

### 4. Outbound Request

[](#4-outbound-request)

Initialize a `\Xtracer\Outbound` before issue an outbound request, which creates a sub span, and call its `finish` method to log the request.

Example:

```
# Initialize
$outbound = new \XTracer\Outbound($this->span);

# Pass the trace information to downstream services if they support jaeger's tracing standard
# $trace = $outbound->getTraceKey() . ': ' . $outbound->getTraceValue();

# Issue the call
$result = ...;

# logging
$outbound->addTag('request.status', 'int64', strval($result['code']));
$outbound->finish();

```

If it's a http request, `\XTracer\Http` will help you do all the above, including passing the traceid to downstream services in http header `uber-trace-id`, as is defined in jaeger's document.

Example:

```
use XTracer\Http;

$response = (new Http())->get("https://www.google.com");
if ($response['errno'] != 0) {
    throw new Exception("failed: " . $response['message']);
}
echo $response['body'], "\n";
Yii::info($response);

#more usage
$response = (new Http())->post("https://www.google.com", ['a'=>1]);
$response = (new Http())->call("POST", "https://www.google.com", '{"a": 1}', ['Content-Type: application/json']);
$response = (new Http())->call("POST", "https://www.google.com", '{"a": 1}', ['Content-Type: application/json'], [CURLOPT_SSL_VERIFYPEER => false]);

```

### 5. Mask

[](#5-mask)

Set the `maskRules` attribute for `\XTracer\Tracer` in `config['components']` to mask sensitive data in `$_GET`/`$_POST` which will be saved to `app.log`.

Rule format is `[$key, $method, $argArray]`, where `$method` can be one of the predefined action:

- `['password', 'unset', []]`: remote this key before logging
- `['password', 'all', [8]]`: replace all characters to 8 asterisks ('\*')
- `['name', 'prefix', [1]]`: keep only the first characters, and replace the remain to '\*'
- `['name', 'prefix', [-1]]`: replace only the first characters to '\*'
- `['name', 'suffix', [1]]`: keep only the last characters, and replace the remain to '\*'
- `['name', 'suffix', [-1]]`: replace only the last characters to '\*'
- `['mobile', 'prefixSuffix', [3, 4]]`: keep only the first 3 and last 4 characters
- `['mobile', 'prefixSuffix', [-3, -4]]`: replace only the first 3 and last 4 characters

`$method` can also be a self defined method. Refer to `XTracer\Mask::maskPrefix`.

If all above is not enough, you can set an extra `maskMethod` attribute for `\XTracer\Tracer`, which takes in the whole array, and return the masked array.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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/d01f11d67dc739ff6fa9d9b536746696a2fb6ab8d32ea3520f27cd2f9ce78b8a?d=identicon)[felix021](/maintainers/felix021)

---

Top Contributors

[![felix021](https://avatars.githubusercontent.com/u/367085?v=4)](https://github.com/felix021 "felix021 (19 commits)")

### Embed Badge

![Health badge](/badges/felix021-xtracer/health.svg)

```
[![Health](https://phpackages.com/badges/felix021-xtracer/health.svg)](https://phpackages.com/packages/felix021-xtracer)
```

###  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)
