class StreamTransport
@internal
@psalm-template CONTENT_TYPE of string @template-implements TransportInterface<CONTENT_TYPE>
Hierarchy
- class \OpenTelemetry\SDK\Common\Export\Stream\StreamTransport implements \OpenTelemetry\SDK\Common\Export\TransportInterface
Expanded class hierarchy of StreamTransport
File
-
vendor/
open-telemetry/ sdk/ Common/ Export/ Stream/ StreamTransport.php, line 28
Namespace
OpenTelemetry\SDK\Common\Export\StreamView source
final class StreamTransport implements TransportInterface {
/**
* @param resource|null $stream
*
* @psalm-param CONTENT_TYPE $contentType
*/
public function __construct($stream, string $contentType) {
}
public function contentType() : string {
return $this->contentType;
}
public function send(string $payload, ?CancellationInterface $cancellation = null) : FutureInterface {
if (!$this->stream) {
return new ErrorFuture(new BadMethodCallException('Transport closed'));
}
set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline) : bool {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
try {
$bytesWritten = fwrite($this->stream, $payload);
} catch (Throwable $e) {
return new ErrorFuture($e);
} finally {
restore_error_handler();
}
if ($bytesWritten !== strlen($payload)) {
return new ErrorFuture(new RuntimeException(sprintf('Write failure, wrote %d of %d bytes', $bytesWritten, strlen($payload))));
}
return new CompletedFuture(null);
}
public function shutdown(?CancellationInterface $cancellation = null) : bool {
if (!$this->stream) {
return false;
}
$flush = @fflush($this->stream);
$this->stream = null;
return $flush;
}
public function forceFlush(?CancellationInterface $cancellation = null) : bool {
if (!$this->stream) {
return false;
}
return @fflush($this->stream);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
StreamTransport::contentType | public | function | Overrides TransportInterface::contentType | |
StreamTransport::forceFlush | public | function | Overrides TransportInterface::forceFlush | |
StreamTransport::send | public | function | Overrides TransportInterface::send | |
StreamTransport::shutdown | public | function | Overrides TransportInterface::shutdown | |
StreamTransport::__construct | public | function | @psalm-param CONTENT_TYPE $contentType |