PHP code example of easyops-cn / easykin

1. Go to this page and download the library: Download easyops-cn/easykin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

easyops-cn / easykin example snippets


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

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

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

$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));

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

EasyKin::trace();

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

$span->receive();

EasyKin::trace();