Test Failed
Push — master ( 86fa5f...d794d1 )
by Dmitry
02:18
created

ZipkinExporter::setEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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