2017 © Pedro Peláez
 

library easykin

A simple zipkin implementation for php.

image

easyops-cn/easykin

A simple zipkin implementation for php.

  • Wednesday, January 24, 2018
  • by cheukchiu
  • Repository
  • 6 Watchers
  • 7 Stars
  • 2,263 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 4 % Grown

The README.md

easykin

Software License Build Status, (*1)

这是一个简单的Zipkin PHP库,根据 官方概念文档 实现,主要用于PHP实现的web服务链路追踪,并针对B3 Propagation封装了专用的Trace类,方便Http服务的接入。, (*2)

Quick Start

初始化

定义服务基础信息:, (*3)

EasyKin::setEndpoint(
    'My service', // 服务名
    '127.0.0.1', // 服务IP
    80); // 服务端口

定义trace信息上报方式,提供FileLogger和HttpLogger两种方式,可以基于Logger接口实现更多上报方式:, (*4)

EasyKin::setLogger(
    new easyops\easykin\logger\HttpLogger(
        'http://127.0.0.1:9411/api/v1/spans', false));

初始化Trace, (*5)

对于前端(链路的源头):, (*6)

EasyKin::setTrace(new \easyops\easykin\core\Trace('get:/login'));

对于后端,需要提取请求Header中的B3信息:, (*7)

$traceId = !empty($_SERVER['HTTP_X_B3_TRACEID']) ? $_SERVER['HTTP_X_B3_TRACEID']) : null;
$parentSpanId = !empty($_SERVER['HTTP_X_B3_PARENTSPANID']) ? $_SERVER['HTTP_X_B3_PARENTSPANID'] : null;
$spanId = !empty($_SERVER['HTTP_X_B3_SPANID']) ? $_SERVER['HTTP_X_B3_SPANID'] : null;
$isSampled = !empty($_SERVER['HTTP_X_B3_SAMPLED'])) ? $_SERVER['HTTP_X_B3_SAMPLED'] : null;

EasyKin::setTrace(new \easyops\easykin\core\Trace('get:/login', $sampled, $traceId, $parentSpanId, $spanId));

也可以使用封装好的HttpTrace类,前后端调用方式都一致:, (*8)

EasyKin::setTrace(new \easyops\easykin\core\HttpTrace());

以上动作均需在你的服务程序入口处尽早完成,在程序结尾处执行上报方法:, (*9)

EasyKin::trace();

注意:如果服务程序因为异常而中断,EasyKin依然会上报trace信息, (*10)

新建一个Span

当你的服务发起请求时,需要新建一个Span来承载该请求的信息:, (*11)

$span = EasyKin::newSpan(
    'get:/users', // span名字,这里以请求url作为名字
    'users service',  // 请求的服务名
    '127.0.0.1',      // 请求的服务IP
    8080);            // 请求的服务端口

然后执行你的请求逻辑。当请求结果返回后,应尽快执行:, (*12)

$span->receive();

以便准确记录该请求的结束时间。, (*13)

执行上报

当服务应用程序处理完一次请求后,需要执行上报动作:, (*14)

EasyKin::trace();

The Versions

24/01 2018

dev-master

9999999-dev

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

zipkin

14/09 2017

0.3.5

0.3.5.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

08/09 2017

0.3.4

0.3.4.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

07/09 2017

0.3.3

0.3.3.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

07/09 2017

0.3.2

0.3.2.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

06/09 2017

0.3.1

0.3.1.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

06/09 2017

0.3.0

0.3.0.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

05/09 2017

0.2.1

0.2.1.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

05/09 2017

0.2.0

0.2.0.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

02/09 2017

0.1.2

0.1.2.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index

25/08 2017

0.1.0

0.1.0.0

A simple zipkin implementation for php.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by index