-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathZipkinTracerFactory.php
64 lines (55 loc) · 1.82 KB
/
ZipkinTracerFactory.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Auxmoney\OpentracingBundle\Factory;
use Exception;
use OpenTracing\NoopTracer;
use OpenTracing\Tracer;
use Psr\Log\LoggerInterface;
use Zipkin\Endpoint;
use Zipkin\Reporters\Http;
use Zipkin\TracingBuilder;
use ZipkinOpenTracing\Tracer as ZipkinTracer;
final class ZipkinTracerFactory implements TracerFactory
{
private $logger;
private $agentHostResolver;
private $samplerFactory;
public function __construct(
AgentHostResolver $agentHostResolver,
SamplerFactory $samplerFactory,
LoggerInterface $logger
) {
$this->agentHostResolver = $agentHostResolver;
$this->logger = $logger;
$this->samplerFactory = $samplerFactory;
}
/**
* @SuppressWarnings(PHPMD.StaticAccess)
* @param mixed $samplerValue
*/
public function create(
string $projectName,
string $agentHost,
string $agentPort,
string $samplerClass,
$samplerValue
): Tracer {
$tracer = new NoopTracer();
try {
$this->agentHostResolver->ensureAgentHostIsResolvable($agentHost);
$endpoint = Endpoint::create($projectName, gethostbyname($agentHost), null, (int) $agentPort);
$reporter = new Http();
$samplerValue = json_decode($samplerValue);
$sampler = $this->samplerFactory->createSampler($samplerClass, $samplerValue);
$tracing = TracingBuilder::create()
->havingLocalEndpoint($endpoint)
->havingSampler($sampler)
->havingReporter($reporter)
->build();
$tracer = new ZipkinTracer($tracing);
} catch (Exception $exception) {
$this->logger->warning(self::class . ': ' . $exception->getMessage());
}
return $tracer;
}
}