Passed
Push — master ( a7d12b...46dbe8 )
by Dmitry
03:07
created

ZipkinExporter::convert()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 32
ccs 20
cts 20
cp 1
rs 8.9617
cc 6
nc 18
nop 1
crap 6
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
            $row['tags'][$k] = $v;
34
        }
35
36 1
        foreach ($span->getEvents() as $event) {
37 1
            if (!array_key_exists('annotations', $row)) {
38 1
                $row['annotations'] = [];
39
            }
40 1
            $row['annotations'][] = [
41 1
                'timestamp' => round($event->getTimestamp()*1000000),
42 1
                'value' => $event->getName(),
43
            ];
44
        }
45
46 1
        return $row;
47
    }
48
49 1
    public function getEndpoint()
50
    {
51 1
        return $this->endpoint;
52
    }
53
54
    public function setEndpoint(array $endpoint) : self
55
    {
56
        $this->endpoint = $endpoint;
57
        return $this;
58
    }
59
}
60