wdalmut/php-zipkin

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

This package is not auto-updated.

Last update: 2024-09-14 00:01:54 UTC


README

Build Status

一个简单的ZipKin实现,用于跟踪您的基于微服务的应用

// 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();

搜索跨度

当您更改上下文时,可能会丢失跨度引用。您可以使用二进制注解来搜索特定的跨度

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

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

使用追踪器发送数据

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

// ...

$tracer->send();

Noop追踪器

如果您想切断追踪器,可以使用我们的 NoopTracer

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

// ...

$tracer->send();