summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Logs/Processor/MultiLogRecordProcessor.php
blob: 753a75df832486746942fe6cece01e7545d1e43f (plain)
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
62
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Logs\Processor;

use OpenTelemetry\Context\ContextInterface;
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface;
use OpenTelemetry\SDK\Logs\ReadWriteLogRecord;

class MultiLogRecordProcessor implements LogRecordProcessorInterface
{
    // @var LogRecordProcessorInterface[]
    private array $processors = [];

    public function __construct(array $processors)
    {
        foreach ($processors as $processor) {
            assert($processor instanceof LogRecordProcessorInterface);
            $this->processors[] = $processor;
        }
    }

    public function onEmit(ReadWriteLogRecord $record, ?ContextInterface $context = null): void
    {
        foreach ($this->processors as $processor) {
            $processor->onEmit($record, $context);
        }
    }

    /**
     * Returns `true` if all processors shut down successfully, else `false`
     * Subsequent calls to `shutdown` are a no-op.
     */
    public function shutdown(?CancellationInterface $cancellation = null): bool
    {
        $result = true;
        foreach ($this->processors as $processor) {
            if (!$processor->shutdown($cancellation)) {
                $result = false;
            }
        }

        return $result;
    }

    /**
     * Returns `true` if all processors flush successfully, else `false`.
     */
    public function forceFlush(?CancellationInterface $cancellation = null): bool
    {
        $result = true;
        foreach ($this->processors as $processor) {
            if (!$processor->forceFlush($cancellation)) {
                $result = false;
            }
        }

        return $result;
    }
}