Passed
Push — master ( 6f2ed7...e5b8b5 )
by Dmitry
01:50
created

ZipkinExporter::setEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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