Skip to content

Commit 4e3bb38

Browse files
authored
stabilize logger.enabled (#1580)
- update Logger.isEnabled signature to include context and severity number, per spec - accept event_name on a LogRecord - add event name to otlp logs payload - update or remove some comments that were based on the old logs-bridge specification
1 parent 199d7dd commit 4e3bb38

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

Logs/LateBindingLogger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace OpenTelemetry\API\Logs;
66

77
use Closure;
8+
use OpenTelemetry\Context\ContextInterface;
89

910
class LateBindingLogger implements LoggerInterface
1011
{
@@ -21,7 +22,7 @@ public function emit(LogRecord $logRecord): void
2122
($this->logger ??= ($this->factory)())->emit($logRecord);
2223
}
2324

24-
public function isEnabled(): bool
25+
public function isEnabled(?ContextInterface $context = null, ?int $severityNumber = null): bool
2526
{
2627
return true;
2728
}

Logs/LogRecord.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class LogRecord
1616
protected int $severityNumber = 0;
1717
protected ?string $severityText = null;
1818
protected array $attributes = [];
19+
protected ?string $eventName = null;
1920

2021
public function __construct(protected mixed $body = null)
2122
{
@@ -90,6 +91,13 @@ public function setBody(mixed $body = null): self
9091
return $this;
9192
}
9293

94+
public function setEventName(string $eventName): self
95+
{
96+
$this->eventName = $eventName;
97+
98+
return $this;
99+
}
100+
93101
/**
94102
* @param int|null $observedTimestamp Time, in nanoseconds since the unix epoch, when the event was observed by the collection system.
95103
*/

Logs/LoggerInterface.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44

55
namespace OpenTelemetry\API\Logs;
66

7+
use OpenTelemetry\Context\ContextInterface;
8+
79
interface LoggerInterface
810
{
9-
/**
10-
* This method should only be used when implementing a `log appender`
11-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.32.0/specification/logs/bridge-api.md#artifact-naming
12-
*/
1311
public function emit(LogRecord $logRecord): void;
1412

1513
/**
16-
* Determine if the logger is enabled. Logs bridge API authors SHOULD call this method each time they
17-
* are about to generate a LogRecord, to avoid performing computationally expensive work.
18-
* @experimental
14+
* Determine if the logger is enabled. Instrumentation authors SHOULD call this method each time they
15+
* emit a LogRecord, to ensure they have the most up-to-date response.
1916
*/
20-
public function isEnabled(): bool;
17+
public function isEnabled(?ContextInterface $context = null, ?int $severityNumber = null): bool;
2118
}

Logs/NoopLogger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace OpenTelemetry\API\Logs;
66

7+
use OpenTelemetry\Context\ContextInterface;
78
use Psr\Log\LoggerTrait;
89

910
class NoopLogger implements LoggerInterface
@@ -31,7 +32,7 @@ public function log($level, $message, array $context = []): void
3132
{
3233
}
3334

34-
public function isEnabled(): bool
35+
public function isEnabled(?ContextInterface $context = null, ?int $severityNumber = null): bool
3536
{
3637
return false;
3738
}

0 commit comments

Comments
 (0)