-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathZipkinExporterEndpoint.php
More file actions
61 lines (50 loc) · 1.89 KB
/
ZipkinExporterEndpoint.php
File metadata and controls
61 lines (50 loc) · 1.89 KB
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
<?php
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Trace;
use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Exporter\ExporterDsn;
use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Exporter\ExporterEndpointInterface;
use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Trace\SpanExporter\TraceExporterEnum;
use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Transport\TransportEnum;
use GuzzleHttp\Psr7\HttpFactory;
use Psr\Http\Message\UriFactoryInterface;
final class ZipkinExporterEndpoint implements ExporterEndpointInterface
{
private ?TransportEnum $transport;
private function __construct(
private readonly ExporterDsn $dsn,
private readonly UriFactoryInterface $uriFactory,
) {
if (TraceExporterEnum::Zipkin !== TraceExporterEnum::fromDsn($this->dsn)) {
throw new \InvalidArgumentException('Unsupported DSN exporter for this endpoint.');
}
$this->transport = TransportEnum::fromDsn($this->dsn);
}
public static function fromDsn(ExporterDsn $dsn): self
{
return new self($dsn, new HttpFactory());
}
public function __toString()
{
$uri = $this->uriFactory->createUri();
$uri = $uri
->withScheme($this->transport->getScheme())
->withHost($this->dsn->getHost())
->withPort($this->dsn->getPort() ?? 9411)
->withPath($this->dsn->getPath() ?? '/api/v2/spans');
if (null !== $this->dsn->getUser()) {
$uri = $uri->withUserInfo($this->dsn->getUser(), $this->dsn->getPassword());
}
return (string) $uri;
}
public function getTransport(): ?string
{
return $this->transport->value;
}
public function getExporter(): string
{
return 'zipkin';
}
public function getDsn(): ExporterDsn
{
return $this->dsn;
}
}