Skip to content

Commit

Permalink
event logger spec compliance
Browse files Browse the repository at this point in the history
update event logger to conform to spec 1.34.0, specifically:
- implement ForceFlush, which delegates to the LoggerProvider
  • Loading branch information
brettmc committed Jun 14, 2024
1 parent eebf23a commit 128e92a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/SDK/Logs/EventLoggerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use OpenTelemetry\API\Common\Time\Clock;
use OpenTelemetry\API\Logs\EventLoggerInterface;
use OpenTelemetry\API\Logs\EventLoggerProviderInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;

class EventLoggerProvider implements EventLoggerProviderInterface
{
Expand All @@ -22,4 +20,9 @@ public function getEventLogger(string $name, ?string $version = null, ?string $s
Clock::getDefault(),
);
}

public function forceFlush(): bool
{
return $this->loggerProvider->forceFlush();
}
}
4 changes: 1 addition & 3 deletions src/SDK/Logs/EventLoggerProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace OpenTelemetry\SDK\Logs;

use OpenTelemetry\API\Logs\EventLoggerProviderInterface;
use OpenTelemetry\API\Logs\NoopEventLoggerProvider;
use OpenTelemetry\SDK\Sdk;

class EventLoggerProviderFactory
{
public function create(\OpenTelemetry\API\Logs\LoggerProviderInterface $loggerProvider): EventLoggerProviderInterface
public function create(LoggerProviderInterface $loggerProvider): EventLoggerProviderInterface
{
if (Sdk::isDisabled()) {
return NoopEventLoggerProvider::getInstance();
Expand Down
12 changes: 12 additions & 0 deletions src/SDK/Logs/EventLoggerProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Logs;

use OpenTelemetry\API\Logs as API;

interface EventLoggerProviderInterface extends API\EventLoggerProviderInterface
{
public function forceFlush(): bool;
}
22 changes: 22 additions & 0 deletions src/SDK/Logs/NoopEventLoggerProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Logs;

use OpenTelemetry\API\Logs as API;

class NoopEventLoggerProvider extends API\NoopEventLoggerProvider implements EventLoggerProviderInterface
{
public static function getInstance(): self
{
static $instance;

return $instance ??= new self();
}

public function forceFlush(): bool
{
return true;
}
}
4 changes: 2 additions & 2 deletions tests/Unit/SDK/Logs/EventLoggerProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace OpenTelemetry\Tests\Unit\SDK\Logs;

use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\API\Logs\NoopEventLoggerProvider;
use OpenTelemetry\SDK\Common\Configuration\Variables;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\EventLoggerProviderFactory;
use OpenTelemetry\SDK\Logs\LoggerProviderInterface;
use OpenTelemetry\SDK\Logs\NoopEventLoggerProvider;
use OpenTelemetry\Tests\TestState;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/SDK/Logs/EventLoggerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Unit\SDK\Logs;

use OpenTelemetry\API\Logs\LoggerInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\LoggerProviderInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/SDK/Logs/EventLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use OpenTelemetry\API\Common\Time\Clock;
use OpenTelemetry\API\Common\Time\TestClock;
use OpenTelemetry\API\Logs\LoggerInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\API\Logs\LogRecord;
use OpenTelemetry\API\Logs\Severity;
use OpenTelemetry\Context\Context;
use OpenTelemetry\SDK\Logs\EventLogger;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\LoggerProviderInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down

0 comments on commit 128e92a

Please sign in to comment.