summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Logs/Exporter
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-10-20 17:12:29 +0300
committerAndrew Dolgov <[email protected]>2023-10-20 21:13:39 +0300
commitcdd7ad020e165fe680703b6d3319b908b682fb7a (patch)
treeb51eb09b7b4587e8fbc5624ac8d88d28cfcd0b04 /vendor/open-telemetry/sdk/Logs/Exporter
parent45a9ff0c88cbd33892ff16ab837e9059937d656e (diff)
jaeger-client -> opentelemetry
Diffstat (limited to 'vendor/open-telemetry/sdk/Logs/Exporter')
-rw-r--r--vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php106
-rw-r--r--vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php19
-rw-r--r--vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php48
-rw-r--r--vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php16
-rw-r--r--vendor/open-telemetry/sdk/Logs/Exporter/NoopExporter.php28
-rw-r--r--vendor/open-telemetry/sdk/Logs/Exporter/_register.php6
6 files changed, 223 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php
new file mode 100644
index 000000000..e34fa308c
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php
@@ -0,0 +1,106 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Logs\Exporter;
+
+use OpenTelemetry\SDK\Common\Export\TransportInterface;
+use OpenTelemetry\SDK\Common\Future\CancellationInterface;
+use OpenTelemetry\SDK\Common\Future\CompletedFuture;
+use OpenTelemetry\SDK\Common\Future\FutureInterface;
+use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
+use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
+use OpenTelemetry\SDK\Logs\ReadableLogRecord;
+use OpenTelemetry\SDK\Resource\ResourceInfo;
+
+/**
+ * A JSON console exporter for LogRecords. This is only useful for testing; the
+ * output is human-readable, and is not compatible with the OTLP format.
+ */
+class ConsoleExporter implements LogRecordExporterInterface
+{
+ private TransportInterface $transport;
+
+ public function __construct(TransportInterface $transport)
+ {
+ $this->transport = $transport;
+ }
+
+ /**
+ * @param iterable<mixed, ReadableLogRecord> $batch
+ */
+ public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
+ {
+ $resource = null;
+ $scopes = [];
+ foreach ($batch as $record) {
+ if (!$resource) {
+ $resource = $this->convertResource($record->getResource());
+ }
+ $key = $this->scopeKey($record->getInstrumentationScope());
+ if (!array_key_exists($key, $scopes)) {
+ $scopes[$key] = $this->convertInstrumentationScope($record->getInstrumentationScope());
+ }
+ $scopes[$key]['logs'][] = $this->convertLogRecord($record);
+ }
+ $output = [
+ 'resource' => $resource,
+ 'scopes' => array_values($scopes),
+ ];
+ $this->transport->send(json_encode($output, JSON_PRETTY_PRINT));
+
+ return new CompletedFuture(true);
+ }
+
+ public function forceFlush(?CancellationInterface $cancellation = null): bool
+ {
+ return true;
+ }
+
+ public function shutdown(?CancellationInterface $cancellation = null): bool
+ {
+ return true;
+ }
+ private function convertLogRecord(ReadableLogRecord $record): array
+ {
+ $spanContext = $record->getSpanContext();
+
+ return [
+ 'timestamp' => $record->getTimestamp(),
+ 'observed_timestamp' => $record->getObservedTimestamp(),
+ 'severity_number' => $record->getSeverityNumber(),
+ 'severity_text' => $record->getSeverityText(),
+ 'body' => $record->getBody(),
+ 'trace_id' => $spanContext !== null ? $spanContext->getTraceId() : '',
+ 'span_id' => $spanContext !== null ? $spanContext->getSpanId() : '',
+ 'trace_flags' => $spanContext !== null ? $spanContext->getTraceFlags() : null,
+ 'attributes' => $record->getAttributes()->toArray(),
+ 'dropped_attributes_count' => $record->getAttributes()->getDroppedAttributesCount(),
+ ];
+ }
+
+ private function convertResource(ResourceInfo $resource): array
+ {
+ return [
+ 'attributes' => $resource->getAttributes()->toArray(),
+ 'dropped_attributes_count' => $resource->getAttributes()->getDroppedAttributesCount(),
+ ];
+ }
+
+ private function scopeKey(InstrumentationScopeInterface $scope): string
+ {
+ return serialize([$scope->getName(), $scope->getVersion(), $scope->getSchemaUrl(), $scope->getAttributes()]);
+ }
+
+ private function convertInstrumentationScope(InstrumentationScopeInterface $scope): array
+ {
+ return [
+ 'name' => $scope->getName(),
+ 'version' => $scope->getVersion(),
+ 'attributes' => $scope->getAttributes()->toArray(),
+ 'dropped_attributes_count' => $scope->getAttributes()->getDroppedAttributesCount(),
+ 'schema_url' => $scope->getSchemaUrl(),
+ 'logs' => [],
+ ];
+ }
+}
diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php
new file mode 100644
index 000000000..a959540a0
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php
@@ -0,0 +1,19 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Logs\Exporter;
+
+use OpenTelemetry\SDK\Logs\LogRecordExporterFactoryInterface;
+use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
+use OpenTelemetry\SDK\Registry;
+
+class ConsoleExporterFactory implements LogRecordExporterFactoryInterface
+{
+ public function create(): LogRecordExporterInterface
+ {
+ $transport = Registry::transportFactory('stream')->create('php://stdout', 'application/json');
+
+ return new ConsoleExporter($transport);
+ }
+}
diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php
new file mode 100644
index 000000000..dca0531f3
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Logs\Exporter;
+
+use ArrayObject;
+use OpenTelemetry\SDK\Common\Future\CancellationInterface;
+use OpenTelemetry\SDK\Common\Future\CompletedFuture;
+use OpenTelemetry\SDK\Common\Future\FutureInterface;
+use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
+
+class InMemoryExporter implements LogRecordExporterInterface
+{
+ private ArrayObject $storage;
+
+ public function __construct(?ArrayObject $storage = null)
+ {
+ $this->storage = $storage ?? new ArrayObject();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
+ {
+ foreach ($batch as $record) {
+ $this->storage[] = $record;
+ }
+
+ return new CompletedFuture(true);
+ }
+
+ public function forceFlush(?CancellationInterface $cancellation = null): bool
+ {
+ return true;
+ }
+
+ public function shutdown(?CancellationInterface $cancellation = null): bool
+ {
+ return true;
+ }
+
+ public function getStorage(): ArrayObject
+ {
+ return $this->storage;
+ }
+}
diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php
new file mode 100644
index 000000000..6f24defe0
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php
@@ -0,0 +1,16 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Logs\Exporter;
+
+use OpenTelemetry\SDK\Logs\LogRecordExporterFactoryInterface;
+use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
+
+class InMemoryExporterFactory implements LogRecordExporterFactoryInterface
+{
+ public function create(): LogRecordExporterInterface
+ {
+ return new InMemoryExporter();
+ }
+}
diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/NoopExporter.php b/vendor/open-telemetry/sdk/Logs/Exporter/NoopExporter.php
new file mode 100644
index 000000000..8eeff62bd
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Logs/Exporter/NoopExporter.php
@@ -0,0 +1,28 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Logs\Exporter;
+
+use OpenTelemetry\SDK\Common\Future\CancellationInterface;
+use OpenTelemetry\SDK\Common\Future\CompletedFuture;
+use OpenTelemetry\SDK\Common\Future\FutureInterface;
+use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
+
+class NoopExporter implements LogRecordExporterInterface
+{
+ public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
+ {
+ return new CompletedFuture(true);
+ }
+
+ public function forceFlush(?CancellationInterface $cancellation = null): bool
+ {
+ return true;
+ }
+
+ public function shutdown(?CancellationInterface $cancellation = null): bool
+ {
+ return true;
+ }
+}
diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/_register.php b/vendor/open-telemetry/sdk/Logs/Exporter/_register.php
new file mode 100644
index 000000000..96958baa8
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Logs/Exporter/_register.php
@@ -0,0 +1,6 @@
+<?php
+
+declare(strict_types=1);
+
+\OpenTelemetry\SDK\Registry::registerLogRecordExporterFactory('console', \OpenTelemetry\SDK\Logs\Exporter\ConsoleExporterFactory::class);
+\OpenTelemetry\SDK\Registry::registerLogRecordExporterFactory('memory', \OpenTelemetry\SDK\Logs\Exporter\InMemoryExporterFactory::class);