-
Notifications
You must be signed in to change notification settings - Fork 26
/
backend.php
41 lines (29 loc) · 1.04 KB
/
backend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
use Zipkin\Propagation\Map;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/functions.php';
$tracing = create_tracing('backend', '127.0.0.2');
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$carrier = array_map(function ($header) {
return $header[0];
}, $request->headers->all());
/* Extracts the context from the HTTP headers */
$extractor = $tracing->getPropagation()->getExtractor(new Map());
$extractedContext = $extractor($carrier);
/* Get users from DB */
$tracer = $tracing->getTracer();
$span = $tracer->nextSpan($extractedContext);
$span->start();
$span->setKind(Zipkin\Kind\SERVER);
$span->setName('parse_request');
$childSpan = $tracer->newChild($span->getContext());
$childSpan->start();
$childSpan->setKind(Zipkin\Kind\CLIENT);
$childSpan->setName('user:get_list:mysql_query');
usleep(50000);
$childSpan->finish();
$span->finish();
/* Sends the trace to zipkin once the response is served */
register_shutdown_function(function () use ($tracer) {
$tracer->flush();
});