-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpanExporter.php
61 lines (51 loc) · 1.74 KB
/
SpanExporter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace Instana;
use JsonException;
use OpenTelemetry\API\Behavior\LogsMessagesTrait;
use OpenTelemetry\SDK\Common\Export\TransportInterface;
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
use OpenTelemetry\SDK\Common\Future\FutureInterface;
use OpenTelemetry\SDK\Trace\Behavior\UsesSpanConverterTrait;
use OpenTelemetry\SDK\Trace\SpanConverterInterface;
use OpenTelemetry\SDK\Trace\SpanExporterInterface;
use Throwable;
class SpanExporter implements SpanExporterInterface
{
use LogsMessagesTrait;
use UsesSpanConverterTrait;
public function __construct(
private TransportInterface $transport,
SpanConverterInterface $spanConverter,
) {
$this->setSpanConverter($spanConverter);
}
/**
* @throws JsonException
*/
protected function serializeTrace(iterable $spans): string
{
return json_encode(
$this->getSpanConverter()->convert($spans),
JSON_THROW_ON_ERROR
);
}
public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
{
return $this->transport
->send($this->serializeTrace($batch), $cancellation)
->map(static fn(): bool => true)
->catch(static function (Throwable $throwable): bool {
self::logError('Export failure', ['exception' => $throwable]);
return false;
});
}
public function shutdown(?CancellationInterface $cancellation = null): bool
{
return $this->transport->shutdown($cancellation);
}
public function forceFlush(?CancellationInterface $cancellation = null): bool
{
return $this->transport->forceFlush($cancellation);
}
}