jcchavezs/zipkin-opentracing 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jcchavezs/zipkin-opentracing

最新稳定版本:2.0.4

Composer 安装命令:

composer require jcchavezs/zipkin-opentracing

包简介

A Zipkin bridge with OpenTracing

README 文档

README

Travis CI OpenTracing Badge Total Downloads Minimum PHP Version License

Zipkin implementation for OpenTracingTracer in PHP.

This library allows OpenTracing API consumers to use Zipkin as their tracing backend. For details on how to work with spans and traces we suggest looking at the documentation and README from the OpenTracing API.

Getting started

Required Reading

In order to understand OpenTracing API, one must first be familiar with the OpenTracing project and terminology more generally.

To understand how Zipkin works, you can look at Zipkin Architecture and Zipkin PHP documentation.

Installation

composer require jcchavezs/zipkin-opentracing

Usage

Firstly, we need to setup a tracer:

use OpenTracing\GlobalTracer;
use Psr\Log\NullLogger;
use Zipkin\Endpoint;
use Zipkin\Samplers\BinarySampler;
use Zipkin\TracingBuilder;
use Zipkin\Reporters\Http;

$endpoint = Endpoint::create('my_service', '127.0.0.1', null, 8081);
$reporter = new Zipkin\Reporters\Http();
$sampler = BinarySampler::createAsAlwaysSample();
$tracing = TracingBuilder::create()
    ->havingLocalEndpoint($endpoint)
    ->havingSampler($sampler)
    ->havingReporter($reporter)
    ->build();

$zipkinTracer = new ZipkinOpenTracing\Tracer($tracing);

GlobalTracer::set($zipkinTracer); // optional

Creating Spans

Propagation of context

Flushing Spans to the agent

PHP as a request scoped language has no simple means to pass the collected spans data to a background process without blocking the main request thread/process. It is mandatory to execute the Tracer::flush() after the response is served to the client by using register_shutdown_function.

use OpenTracing\GlobalTracer;

$application->run();

register_shutdown_function(function() {
    GlobalTracer::get()->flush();
});

Contribution

Run tests

composer test

Fix lint

composer fix-lint

统计信息

  • 总下载量: 2.75M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 1
  • 依赖项目数: 14
  • 推荐数: 2

GitHub 信息

  • Stars: 23
  • Watchers: 2
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04