diff options
Diffstat (limited to 'vendor/open-telemetry/api/Logs')
-rw-r--r-- | vendor/open-telemetry/api/Logs/EventLogger.php | 26 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/EventLoggerInterface.php | 13 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/LogRecord.php | 108 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/LoggerInterface.php | 10 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/LoggerProviderInterface.php | 18 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/Map/Psr3.php | 40 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/NoopLogger.php | 33 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/NoopLoggerProvider.php | 20 | ||||
-rw-r--r-- | vendor/open-telemetry/api/Logs/README.md | 19 |
9 files changed, 287 insertions, 0 deletions
diff --git a/vendor/open-telemetry/api/Logs/EventLogger.php b/vendor/open-telemetry/api/Logs/EventLogger.php new file mode 100644 index 000000000..68deb865c --- /dev/null +++ b/vendor/open-telemetry/api/Logs/EventLogger.php @@ -0,0 +1,26 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs; + +class EventLogger implements EventLoggerInterface +{ + private LoggerInterface $logger; + private string $domain; + + public function __construct(LoggerInterface $logger, string $domain) + { + $this->logger = $logger; + $this->domain = $domain; + } + + public function logEvent(string $eventName, LogRecord $logRecord): void + { + $logRecord->setAttributes([ + 'event.name' => $eventName, + 'event.domain' => $this->domain, + ]); + $this->logger->emit($logRecord); + } +} diff --git a/vendor/open-telemetry/api/Logs/EventLoggerInterface.php b/vendor/open-telemetry/api/Logs/EventLoggerInterface.php new file mode 100644 index 000000000..a2096b9b7 --- /dev/null +++ b/vendor/open-telemetry/api/Logs/EventLoggerInterface.php @@ -0,0 +1,13 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs; + +/** + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/event-api.md#events-api-interface + */ +interface EventLoggerInterface +{ + public function logEvent(string $eventName, LogRecord $logRecord): void; +} diff --git a/vendor/open-telemetry/api/Logs/LogRecord.php b/vendor/open-telemetry/api/Logs/LogRecord.php new file mode 100644 index 000000000..6833c71f9 --- /dev/null +++ b/vendor/open-telemetry/api/Logs/LogRecord.php @@ -0,0 +1,108 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs; + +use OpenTelemetry\Context\ContextInterface; + +class LogRecord +{ + public const NANOS_PER_SECOND = 1_000_000_000; + + protected ?int $timestamp = null; + protected ?int $observedTimestamp = null; + protected ?ContextInterface $context = null; + protected int $severityNumber = 0; + protected ?string $severityText = null; + protected $body = null; + protected array $attributes = []; + + /** + * @param mixed $body + */ + public function __construct($body = null) + { + $this->body = $body; + } + + /** + * @param int $timestamp Timestamp, in nanoseconds since the unix epoch, when the event occurred. + * @see https://opentelemetry.io/docs/reference/specification/logs/data-model/#field-timestamp + */ + public function setTimestamp(int $timestamp): self + { + $this->timestamp = $timestamp; + + return $this; + } + + public function setContext(?ContextInterface $context = null): self + { + $this->context = $context; + + return $this; + } + + /** + * @param int $severityNumber Severity number + * @see https://opentelemetry.io/docs/reference/specification/logs/data-model/#field-severitynumber + */ + public function setSeverityNumber(int $severityNumber): self + { + $this->severityNumber = $severityNumber; + + return $this; + } + + /** + * @param string $severityText Severity text, also known as log level + * @see https://opentelemetry.io/docs/reference/specification/logs/data-model/#field-severitynumber + */ + public function setSeverityText(string $severityText): self + { + $this->severityText = $severityText; + + return $this; + } + + /** + * @param iterable $attributes Additional information about the specific event occurrence. + * @see https://opentelemetry.io/docs/reference/specification/logs/data-model/#field-attributes + */ + public function setAttributes(iterable $attributes): self + { + foreach ($attributes as $name => $value) { + $this->setAttribute($name, $value); + } + + return $this; + } + + public function setAttribute(string $name, $value): self + { + $this->attributes[$name] = $value; + + return $this; + } + + /** + * @param mixed $body The log record body + */ + public function setBody($body = null): self + { + $this->body = $body; + + return $this; + } + + /** + * @param int|null $observedTimestamp Time, in nanoseconds since the unix epoch, when the event was observed by the collection system. + */ + public function setObservedTimestamp(int $observedTimestamp = null): self + { + $this->observedTimestamp = $observedTimestamp; + + return $this; + } +} diff --git a/vendor/open-telemetry/api/Logs/LoggerInterface.php b/vendor/open-telemetry/api/Logs/LoggerInterface.php new file mode 100644 index 000000000..89477c8d2 --- /dev/null +++ b/vendor/open-telemetry/api/Logs/LoggerInterface.php @@ -0,0 +1,10 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs; + +interface LoggerInterface +{ + public function emit(LogRecord $logRecord): void; +} diff --git a/vendor/open-telemetry/api/Logs/LoggerProviderInterface.php b/vendor/open-telemetry/api/Logs/LoggerProviderInterface.php new file mode 100644 index 000000000..e60353de2 --- /dev/null +++ b/vendor/open-telemetry/api/Logs/LoggerProviderInterface.php @@ -0,0 +1,18 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs; + +/** + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/bridge-api.md#get-a-logger + */ +interface LoggerProviderInterface +{ + public function getLogger( + string $name, + ?string $version = null, + ?string $schemaUrl = null, + iterable $attributes = [] //instrumentation scope attributes + ): LoggerInterface; +} diff --git a/vendor/open-telemetry/api/Logs/Map/Psr3.php b/vendor/open-telemetry/api/Logs/Map/Psr3.php new file mode 100644 index 000000000..8fd85fad0 --- /dev/null +++ b/vendor/open-telemetry/api/Logs/Map/Psr3.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs\Map; + +use Psr\Log\LogLevel; + +class Psr3 +{ + /** + * Maps PSR-3 severity level (string) to the appropriate opentelemetry severity number + * + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model-appendix.md#appendix-b-severitynumber-example-mappings + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber + */ + public static function severityNumber(string $level): int + { + switch (strtolower($level)) { + case LogLevel::DEBUG: + return 5; + case LogLevel::INFO: + return 9; + case LogLevel::NOTICE: + return 10; + case LogLevel::WARNING: + return 13; + case LogLevel::ERROR: + return 17; + case LogLevel::CRITICAL: + return 18; + case LogLevel::ALERT: + return 19; + case LogLevel::EMERGENCY: + return 21; + default: + return 0; + } + } +} diff --git a/vendor/open-telemetry/api/Logs/NoopLogger.php b/vendor/open-telemetry/api/Logs/NoopLogger.php new file mode 100644 index 000000000..faacd5e10 --- /dev/null +++ b/vendor/open-telemetry/api/Logs/NoopLogger.php @@ -0,0 +1,33 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs; + +use Psr\Log\LoggerTrait; + +class NoopLogger implements LoggerInterface +{ + use LoggerTrait; + + public static function getInstance(): self + { + static $instance; + + return $instance ??= new self(); + } + + /** + * @codeCoverageIgnore + */ + public function emit(LogRecord $logRecord): void + { + } + + /** + * @codeCoverageIgnore + */ + public function log($level, $message, array $context = []): void + { + } +} diff --git a/vendor/open-telemetry/api/Logs/NoopLoggerProvider.php b/vendor/open-telemetry/api/Logs/NoopLoggerProvider.php new file mode 100644 index 000000000..8b00b6637 --- /dev/null +++ b/vendor/open-telemetry/api/Logs/NoopLoggerProvider.php @@ -0,0 +1,20 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Logs; + +class NoopLoggerProvider implements LoggerProviderInterface +{ + public static function getInstance(): self + { + static $instance; + + return $instance ??= new self(); + } + + public function getLogger(string $name, ?string $version = null, ?string $schemaUrl = null, iterable $attributes = []): LoggerInterface + { + return NoopLogger::getInstance(); + } +} diff --git a/vendor/open-telemetry/api/Logs/README.md b/vendor/open-telemetry/api/Logs/README.md new file mode 100644 index 000000000..d0bdb923e --- /dev/null +++ b/vendor/open-telemetry/api/Logs/README.md @@ -0,0 +1,19 @@ +# Logs API + +This `Logger` API is not designed to be used by application developers, but rather by library developers for the purpose +of integrating existing logging libraries with OpenTelemetry. + +## Logging from 3rd party loggers + +3rd party loggers should log to OpenTelemetry in accordance with the +[logs bridge API](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/bridge-api.md) +specification. + +This means that a "log appender" in the 3rd party logging library (sometimes known as a "handler") should: +- accept an `OpenTelemetry\API\Logs\LoggerProviderInterface`, or obtain a globally registered one from `OpenTelemetry\API\Instrumentation\Globals` +- obtain a `Logger` from the logger provider (optionally adding any resources that should be associated with logs emitted) +- convert logs from its own log format into OpenTelemetry's `LogRecord` format +- send the logs to OpenTelemetry via `Logger::logRecord()` + +See [monolog-otel-integration](/examples/logs/features/monolog-otel-integration.php) for an example. + |