<commit_before><?php
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php';


<commit_msg>add hprose example<commit_after><?php
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php';

use Hprose\Client;
use JaegerPhp\Config;
use OpenTracing\Propagator;
use OpenTracing\Carriers\TextMap;
use OpenTracing\SpanReference;


unset($_SERVER['argv']);

//init server span start
$traceConfig = Config::getInstance();
$trace = $traceConfig->initTrace('example', '0.0.0.0:5775');

$injectTarget = [];
$textMap = TextMap::create($injectTarget);
$spanContext = $trace->extract(Propagator::TEXT_MAP, $textMap);
$serverSpan = $trace->startSpan('example HTTP', SpanReference::createAsChildOf($spanContext));
$trace->inject($serverSpan->getContext(), Propagator::TEXT_MAP, $textMap);
$injectTarget = $textMap->getIterator()->getArrayCopy();
$_SERVER[\JaegerPhp\Helper::TracerStateHeaderName] = $injectTarget[\JaegerPhp\Helper::TracerStateHeaderName];
//init server span end

$clientTrace = $traceConfig->initTrace('Hprose');

//client span start
$header = [];
$textMap = TextMap::create($_SERVER);
$spanContext = $clientTrace->extract(Propagator::TEXT_MAP, $textMap);
$clientSapn = $clientTrace->startSpan('get', SpanReference::createAsChildOf($spanContext));
$clientTrace->inject($clientSapn->spanContext, Propagator::TEXT_MAP, $textMap);
$tmp = $textMap->getIterator()->getArrayCopy();
$header[\JaegerPhp\Helper::TracerStateHeaderName] = $tmp[\JaegerPhp\Helper::TracerStateHeaderName];

$url = 'http://0.0.0.0:8080/main';
$client = Client::create($url, false);

if($header){
    foreach($header as $key => $val){
        $client->setHeader($key, $val);
    }
}
$clientSapn->addTags(['http.url' => $url]);
$clientSapn->addTags(['http.method' => 'POST']);

$result =  $client->get("Hprose");

$clientSapn->log(['http.result' => $result]);
$clientSapn->finish();
//client span end


//server span end
$serverSpan->finish();
//trace flush
$traceConfig->flushTrace();

echo "success\r\n";


{'fraction_non_alphanumeric': 0.19492789656887122, 'fraction_numerical': 0.007956240676280457, 'mean_word_length': 7.672413793103448, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4508937', 'n_tokens_mistral': 692, 'n_tokens_neox': 676, 'n_words': 103}