Skip to content

Commit 939d3a2

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 05d9ceb commit 939d3a2

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Logs/Logger.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@
77
use OpenTelemetry\API\Behavior\LogsMessagesTrait;
88
use OpenTelemetry\API\Logs\LoggerInterface;
99
use OpenTelemetry\API\Logs\LogRecord;
10+
use OpenTelemetry\Context\ContextInterface;
1011
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
1112
use OpenTelemetry\SDK\Common\InstrumentationScope\Configurator;
1213

13-
/**
14-
* Note that this logger class is deliberately NOT psr-3 compatible, per spec: "Note: this document defines a log
15-
* backend API. The API is not intended to be called by application developers directly."
16-
*
17-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/bridge-api.md
18-
*/
1914
class Logger implements LoggerInterface
2015
{
2116
use LogsMessagesTrait;
@@ -33,6 +28,9 @@ public function __construct(
3328
$this->config = $configurator ? $configurator->resolve($scope) : LoggerConfig::default();
3429
}
3530

31+
/**
32+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.44.0/specification/logs/api.md#emit-a-logrecord
33+
*/
3634
public function emit(LogRecord $logRecord): void
3735
{
3836
//If a Logger is disabled, it MUST behave equivalently to No-op Logger.
@@ -52,12 +50,16 @@ public function emit(LogRecord $logRecord): void
5250
}
5351
}
5452

55-
public function isEnabled(): bool
53+
/**
54+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.44.0/specification/logs/api.md#enabled
55+
*/
56+
public function isEnabled(?ContextInterface $context = null, ?int $severityNumber = null): bool
5657
{
5758
return $this->config->isEnabled();
5859
}
5960

6061
/**
62+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.44.0/specification/logs/sdk.md#loggerconfigurator
6163
* @param Configurator<LoggerConfig> $configurator
6264
*/
6365
public function updateConfig(Configurator $configurator): void

Logs/ReadableLogRecord.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function __construct(
3737
$this->spanContext = Span::fromContext($context)->getContext();
3838
$this->severityNumber = $logRecord->severityNumber;
3939
$this->severityText = $logRecord->severityText;
40+
$this->eventName = $logRecord->eventName;
4041

4142
//convert attributes now so that excess data is not sent to processors
4243
$this->convertedAttributes = $this->loggerSharedState
@@ -94,6 +95,11 @@ public function getBody()
9495
return $this->body;
9596
}
9697

98+
public function getEventName(): ?string
99+
{
100+
return $this->eventName;
101+
}
102+
97103
public function getAttributes(): AttributesInterface
98104
{
99105
return $this->convertedAttributes;

0 commit comments

Comments
 (0)