Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SpanExporter.php

class SpanExporter

@psalm-import-type SUPPORTED_CONTENT_TYPES from ProtobufSerializer

Hierarchy

  • class \OpenTelemetry\Contrib\Otlp\SpanExporter implements \OpenTelemetry\SDK\Trace\SpanExporterInterface uses \OpenTelemetry\API\Behavior\LogsMessagesTrait

Expanded class hierarchy of SpanExporter

File

vendor/open-telemetry/exporter-otlp/SpanExporter.php, line 19

Namespace

OpenTelemetry\Contrib\Otlp
View source
final class SpanExporter implements SpanExporterInterface {
    use LogsMessagesTrait;
    private ProtobufSerializer $serializer;
    
    /**
     * @psalm-param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport
     */
    public function __construct(TransportInterface $transport) {
        if (!class_exists('\\Google\\Protobuf\\Api')) {
            throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)');
        }
        $this->serializer = ProtobufSerializer::forTransport($this->transport);
    }
    public function export(iterable $batch, ?CancellationInterface $cancellation = null) : FutureInterface {
        return $this->transport
            ->send($this->serializer
            ->serialize((new SpanConverter($this->serializer))
            ->convert($batch)), $cancellation)
            ->map(function (?string $payload) : bool {
            if ($payload === null) {
                return true;
            }
            $serviceResponse = new ExportTraceServiceResponse();
            $this->serializer
                ->hydrate($serviceResponse, $payload);
            $partialSuccess = $serviceResponse->getPartialSuccess();
            if ($partialSuccess !== null && $partialSuccess->getRejectedSpans()) {
                self::logError('Export partial success', [
                    'rejected_spans' => $partialSuccess->getRejectedSpans(),
                    'error_message' => $partialSuccess->getErrorMessage(),
                ]);
                return false;
            }
            if ($partialSuccess !== null && $partialSuccess->getErrorMessage()) {
                self::logWarning('Export success with warnings/suggestions', [
                    'error_message' => $partialSuccess->getErrorMessage(),
                ]);
            }
            return 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);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
LogsMessagesTrait::doLog private static function
LogsMessagesTrait::logDebug protected static function
LogsMessagesTrait::logError protected static function
LogsMessagesTrait::logInfo protected static function
LogsMessagesTrait::logNotice protected static function
LogsMessagesTrait::logWarning protected static function
LogsMessagesTrait::shouldLog private static function
SpanExporter::$serializer private property
SpanExporter::export public function @psalm-return FutureInterface&lt;bool&gt; Overrides SpanExporterInterface::export
SpanExporter::forceFlush public function @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/sdk.md#forceflush-2 Overrides SpanExporterInterface::forceFlush
SpanExporter::shutdown public function @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/sdk.md#shutdown-2 Overrides SpanExporterInterface::shutdown
SpanExporter::__construct public function @psalm-param TransportInterface&lt;SUPPORTED_CONTENT_TYPES&gt; $transport
RSS feed
Powered by Drupal