Passed
Push — master ( a7d12b...46dbe8 )
by Dmitry
03:07
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
            $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