定制 jonahgeorge/jaeger-client-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jonahgeorge/jaeger-client-php

Composer 安装命令:

composer require jonahgeorge/jaeger-client-php

包简介

Jaeger Bindings for PHP OpenTracing API

README 文档

README

Build Status PHP version

Jaeger Bindings for PHP OpenTracing API

This is a client-side library that can be used to instrument PHP apps for distributed trace collection, and to send those traces to Jaeger. See the OpenTracing PHP API for additional detail.

Contributing and Developing

Please see CONTRIBUTING.md.

Installation

Jaeger client can be installed via Composer:

composer require jonahgeorge/jaeger-client-php

Getting Started

<?php

require_once 'vendor/autoload.php';

use Jaeger\Config;
use OpenTracing\GlobalTracer;

$config = new Config(
    [
        'sampler' => [
            'type' => Jaeger\SAMPLER_TYPE_CONST,
            'param' => true,
        ],
        'logging' => true,
    ],
    'your-app-name'
);
$config->initializeTracer();

$tracer = GlobalTracer::get();

$scope = $tracer->startActiveSpan('TestSpan', []);
$scope->close();

$tracer->flush();

Samplers

List of supported samplers, for more info about samplers, please read Jaeger Sampling guide.

Const sampler

This sampler either samples everything, or nothing.

Configuration
'sampler' => [
    'type' => Jaeger\SAMPLER_TYPE_CONST,
    'param' => true, // boolean wheter to trace or not
],

Probabilistic sampler

This sampler samples request by given rate.

Configuration
'sampler' => [
    'type' => Jaeger\SAMPLER_TYPE_PROBABILISTIC,
    'param' => 0.5, // float [0.0, 1.0]
],

Rate limiting sampler

Samples maximum specified number of traces (requests) per second.

Requirements
  • psr/cache PSR-6 cache component to store and retrieve sampler state between requests. Cache component is passed to Jaeger\Config trough its constructor.
  • hrtime() function, that can retrieve time in nanoseconds. You need either php 7.3 or PECL/hrtime extension.
Configuration
'sampler' => [
    'type' => Jaeger\SAMPLER_TYPE_RATE_LIMITING,
    'param' => 100 // integer maximum number of traces per second,
    'cache' => [
        'currentBalanceKey' => 'rate.currentBalance' // string
        'lastTickKey' => 'rate.lastTick' // string
    ]
],

Dispatch mode

The library supports 3 ways of sending data to Jaeger Agent:

  1. Zipkin.thrift over Compact protocol (socket - UDP) - default
  2. Jaeger.thrift over Binary protocol (socket - UDP)
  3. Jaeger.thrift over Binary protocol (HTTP)

If you want to enable "Jaeger.thrift over Binary protocol" one or other, than you need to set dispatch_mode config option or JAEGER_DISPATCH_MODE env variable.

Allowed values for dispatch_mode are:

  • jaeger_over_binary_udp
  • jaeger_over_binary_http
  • zipkin_over_compact_udp

There are 3 constants available, so it is better to use them:

class Config
{
    const ZIPKIN_OVER_COMPACT_UDP   = "zipkin_over_compact_udp";
    const JAEGER_OVER_BINARY_UDP    = "jaeger_over_binary_udp";
    const JAEGER_OVER_BINARY_HTTP   = "jaeger_over_binary_http";
    ...
}

A possible config with custom dispatch_mode can look like this:

// config.php

use Jaeger\Config;

return [
    'sampler' => [
        'type' => Jaeger\SAMPLER_TYPE_CONST,
        'param' => true,
    ],
    'logging' => true,
    "tags" => [
        // process. prefix works only with JAEGER_OVER_HTTP, JAEGER_OVER_BINARY
        // otherwise it will be shown as simple global tag
        "process.process-tag-key-1" => "process-value-1", // all tags with `process.` prefix goes to process section
        "process.process-tag-key-2" => "process-value-2", // all tags with `process.` prefix goes to process section
        "global-tag-key-1" => "global-tag-value-1", // this tag will be appended to all spans
        "global-tag-key-2" => "global-tag-value-2", // this tag will be appended to all spans
    ],
    "local_agent" => [
        "reporting_host" => "localhost", 
//        You can override port by setting local_agent.reporting_port value   
        "reporting_port" => 6832
    ],
//     Different ways to send data to Jaeger. Config::ZIPKIN_OVER_COMPACT - default):
    'dispatch_mode' => Config::JAEGER_OVER_BINARY_UDP,
];

The full example you can see at examples directory.

By default, for each dispatch_mode there is default reporting_port config value. Table with default values you can see below:

dispatch_mode default reporting_port
ZIPKIN_OVER_COMPACT_UDP 5775
JAEGER_OVER_BINARY_UDP 6832
JAEGER_OVER_BINARY_HTTP 14268

IPv6

In case you need IPv6 support you need to set ip_version Config variable. By default, IPv4 is used. There is an alias Config::IP_VERSION which you can use as an alternative to raw ip_version.

Example:

use Jaeger\Config;

$config = new Config(
    [
        "ip_version" => Config::IPV6, // <-- or use Config::IP_VERSION constant
        'logging' => true,
        'dispatch_mode' => Config::JAEGER_OVER_BINARY_UDP,
    ],
    'serviceNameExample',
);
$config->initializeTracer();

or

use Jaeger\Config;

$config = new Config(
    [
        Config::IP_VERSION => Config::IPV6, // <--
        'logging' => true,
        'dispatch_mode' => Config::JAEGER_OVER_BINARY_UDP,
    ],
    'serviceNameExample',
);
$config->initializeTracer();

Testing

Tests are located in the tests directory. See tests/README.md.

Roadmap

License

MIT License.

jonahgeorge/jaeger-client-php 适用场景与选型建议

jonahgeorge/jaeger-client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.65M 次下载、GitHub Stars 达 148, 最近一次更新时间为 2017 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「trace」 「tracing」 「jaeger」 「opentracing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jonahgeorge/jaeger-client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jonahgeorge/jaeger-client-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 jonahgeorge/jaeger-client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.65M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 148
  • 点击次数: 33
  • 依赖项目数: 21
  • 推荐数: 7

GitHub 信息

  • Stars: 148
  • Watchers: 6
  • Forks: 46
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-27