-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for multiple log processors
- Loading branch information
Showing
11 changed files
with
132 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 MultiLogsProcessor 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters