class SimpleSpanProcessor
Hierarchy
- class \OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor implements \OpenTelemetry\SDK\Trace\SpanProcessorInterface uses \OpenTelemetry\API\Behavior\LogsMessagesTrait
Expanded class hierarchy of SimpleSpanProcessor
1 file declares its use of SimpleSpanProcessor
- SpanProcessorFactory.php in vendor/
open-telemetry/ sdk/ Trace/ SpanProcessorFactory.php
File
-
vendor/
open-telemetry/ sdk/ Trace/ SpanProcessor/ SimpleSpanProcessor.php, line 20
Namespace
OpenTelemetry\SDK\Trace\SpanProcessorView source
class SimpleSpanProcessor implements SpanProcessorInterface {
use LogsMessagesTrait;
private ContextInterface $exportContext;
private bool $running = false;
/** @var SplQueue<array{Closure, string, bool, ContextInterface}> */
private SplQueue $queue;
private bool $closed = false;
public function __construct(SpanExporterInterface $exporter) {
$this->exportContext = Context::getCurrent();
$this->queue = new SplQueue();
}
public function onStart(ReadWriteSpanInterface $span, ContextInterface $parentContext) : void {
}
public function onEnd(ReadableSpanInterface $span) : void {
if ($this->closed) {
return;
}
if (!$span->getContext()
->isSampled()) {
return;
}
$spanData = $span->toSpanData();
$this->flush(fn() => $this->exporter
->export([
$spanData,
])
->await(), 'export', false, $this->exportContext);
}
public function forceFlush(?CancellationInterface $cancellation = null) : bool {
if ($this->closed) {
return false;
}
return $this->flush(fn(): bool => $this->exporter
->forceFlush($cancellation), __FUNCTION__, true, Context::getCurrent());
}
public function shutdown(?CancellationInterface $cancellation = null) : bool {
if ($this->closed) {
return false;
}
$this->closed = true;
return $this->flush(fn(): bool => $this->exporter
->shutdown($cancellation), __FUNCTION__, true, Context::getCurrent());
}
private function flush(Closure $task, string $taskName, bool $propagateResult, ContextInterface $context) : bool {
$this->queue
->enqueue([
$task,
$taskName,
$propagateResult && !$this->running,
$context,
]);
if ($this->running) {
return false;
}
$success = true;
$exception = null;
$this->running = true;
try {
while (!$this->queue
->isEmpty()) {
[
$task,
$taskName,
$propagateResult,
$context,
] = $this->queue
->dequeue();
$scope = $context->activate();
try {
$result = $task();
if ($propagateResult) {
$success = $result;
}
} catch (Throwable $e) {
if ($propagateResult) {
$exception = $e;
}
else {
self::logError(sprintf('Unhandled %s error', $taskName), [
'exception' => $e,
]);
}
} finally {
$scope->detach();
}
}
} finally {
$this->running = false;
}
if ($exception !== null) {
throw $exception;
}
return $success;
}
}
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 | ||
SimpleSpanProcessor::$closed | private | property | ||
SimpleSpanProcessor::$exportContext | private | property | ||
SimpleSpanProcessor::$queue | private | property | @var SplQueue<array{Closure, string, bool, ContextInterface}> | |
SimpleSpanProcessor::$running | private | property | ||
SimpleSpanProcessor::flush | private | function | ||
SimpleSpanProcessor::forceFlush | public | function | Export all ended spans to the configured Exporter that have not yet been exported. Returns `true` if the flush was successful, otherwise `false`. |
Overrides SpanProcessorInterface::forceFlush |
SimpleSpanProcessor::onEnd | public | function | Overrides SpanProcessorInterface::onEnd | |
SimpleSpanProcessor::onStart | public | function | Overrides SpanProcessorInterface::onStart | |
SimpleSpanProcessor::shutdown | public | function | Cleanup; after shutdown, calling onStart, onEnd, or forceFlush is invalid Returns `false` is the processor is already shutdown, otherwise `true`. |
Overrides SpanProcessorInterface::shutdown |
SimpleSpanProcessor::__construct | public | function |