/jaeger-php

Jaeger Bindings for PHP OpenTracing API

Primary LanguagePHPMIT LicenseMIT

jaeger-php

principle of Distributed Tracing

install

install via composer

vim composer.json

{
  "minimum-stability": "dev",
  "require":           {
    "jukylin/jaeger-php" : "^2.0",
    "opentracing/opentracing":"1.0.0-beta2"
  }
}

composer update

Init Jaeger-php

$config = Config::getInstance();
$tracer = $config->initTrace('example', '0.0.0.0:6831');

128bit

$config->gen128bit();

Extract from Superglobals

$spanContext = $tracer->extract(Formats\TEXT_MAP, $_SERVER);

Start Span

$serverSpan = $tracer->startSpan('example HTTP', ['child_of' => $spanContext]);

Distributed context propagation

$serverSpan->addBaggageItem("version", "2.0.0");

Inject into Superglobals

$clientTrace->inject($clientSapn1->spanContext, Formats\TEXT_MAP, $_SERVER);

Tags and Log

//can search in Jaeger UI
$span->addTags(['http.status' => "200"]);

//log record
$span->log(['error' => "HTTP request timeout"]);

Close Trace

$config->setDisabled(true);

Zipkin B3 Propagation

not support 128bit and Distributed context propagation

$config::$propagator = \Jaeger\Constants\PROPAGATOR_ZIPKIN;

finish span and flush Trace

$span->finish();
$config->flush();

more example

Features

  • Transports

    • via Thrift over UDP
  • Sampling

    • ConstSampler
    • ProbabilisticSampler

Reference

OpenTracing

Jaeger