wdalmut/php-zipkin

dev-master 2017-07-04 18:31 UTC

This package is not auto-updated.

Last update: 2024-10-26 00:36:47 UTC


README

Build Status

A simple ZipKin implementation to trace your microservices based application

// create the root span as server receive
$otherSpan = new ServerReceive("get_users", "oauth2", "auth.corley:80");
// add span to the tracer
$tracer->addSpan($otherSpan);

// restore the root span using headers (X-B3-TraceId, X-B3-SpanId, X-B3-ParentSpanId)
$otherSpan->restoreContextFromHeaders($request);

// add a binary annotation on this span
$otherSpan->getBinaryAnnotations()->set("http.method", "GET");

// create a new span (service call)
$span = new ClientSend("getVipUser", "oauth2");
// set span as child of the root span
$span->childOf($otherSpan);
// add span to the tracer
$tracer->addSpan($span);

// add binary annotation on this span
$span->getBinaryAnnotations()->set("error", true);

// sign a custom event on the current span
$span->add("reservedCustomer);

// close the client send span
$span->receive();

// close the server sent span
$otherSpan->sent();

Search for a Span

When you change your context may you lost a span reference. You can use your binary annotation to search for a particular span

$rootSpan = $tracer->findOneBy("kind", "app.flow");

$span = new ClientSend("getUsers", "user.corley");
$span->setChildOf($rootSpan);

Send data using the tracer

$logger = new HttpLogger($zipkinHost);
$tracer = new Tracer($logger);

// ...

$tracer->send();

Noop tracer

If you want to cut off the tracer your can use our NoopTracer

$logger = new NoopLogger($zipkinHost);
$tracer = new Tracer($logger);

// ...

$tracer->send();