ZipkinExporter::getEndpoint()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OpenTelemetry\Exporter;
6
7
use OpenTelemetry\Exporter;
8
use OpenTelemetry\Tracing\Span;
9
use OpenTelemetry\Tracing\Tracer;
10
11
class ZipkinExporter extends Exporter
12
{
13
    private $endpoint;
14
15 1
    public function convertSpan(Span $span): array
16
    {
17
        $row = [
18 1
            'id' => $span->getSpanContext()->getSpanId(),
19 1
            'traceId' => $span->getSpanContext()->getTraceId(),
20 1
            'parentId' => $span->getParentSpanContext() ? $span->getParentSpanContext()->getSpanId() : null,
21 1
            'localEndpoint' => $this->getEndpoint(),
22
            'name' => $span->getName(),
23 1
            'timestamp' => (int) round($span->getStart() * 1000000),
24 1
            'duration' => (int) round($span->getEnd() * 1000000) - round($span->getStart() * 1000000),
25 1
        ];
26 1
27
        foreach ($span->getAttributes() as $k => $v) {
28
            if (!array_key_exists('tags', $row)) {
29 1
                $row['tags'] = [];
30 1
            }
31 1
            if (is_bool($v)) {
32
                $v = (string) $v;
33 1
            }
34
            $row['tags'][$k] = $v;
35
        }
36 1
37
        foreach ($span->getEvents() as $event) {
38
            if (!array_key_exists('annotations', $row)) {
39 1
                $row['annotations'] = [];
40 1
            }
41 1
            $row['annotations'][] = [
42
                'timestamp' => round($event->getTimestamp() * 1000000),
43 1
                'value' => $event->getName(),
44 1
            ];
45 1
        }
46
47
        return $row;
48
    }
49 1
50
    public function getEndpoint()
51
    {
52 1
        return $this->endpoint;
53
    }
54 1
55
    public function setEndpoint(array $endpoint): self
56
    {
57
        $this->endpoint = $endpoint;
58
        return $this;
59
    }
60
}
61