OpenTelemetry PHP

Registry
in package
uses LogsMessagesTrait

A registry to enable central registration of components that the SDK requires but which may be provided by non-SDK modules, such as contrib and extension.

Components are registered either explicitly, with the register*() methods, or by a RegistrarInterface discovered through SPI. Registrars are loaded lazily on the first lookup, so the result does not depend on the order in which Composer includes autoload.files. A component registered explicitly before that wins over one contributed by a registrar, and one registered with $clobber always wins.

Tags
todo

[breaking] deprecate the explicit register*() methods, in favor of using SPI.

Table of Contents

Properties

$logRecordExporterFactories  : array<string|int, mixed>
$metricExporterFactories  : array<string|int, mixed>
$registrarCount  : int
$registrarsLoaded  : bool
$registrarsRun  : array<RegistrarInterface>, true>
$resourceDetectors  : array<string|int, mixed>
$responsePropagators  : array<string|int, mixed>
$spanExporterFactories  : array<string|int, mixed>
$textMapPropagators  : array<string|int, mixed>
$transportFactories  : array<string|int, mixed>

Methods

logRecordExporterFactory()  : LogRecordExporterFactoryInterface
metricExporterFactory()  : MetricExporterFactoryInterface
registerLogRecordExporterFactory()  : void
registerMetricExporterFactory()  : void
registerResourceDetector()  : void
registerResponsePropagator()  : void
registerSpanExporterFactory()  : void
registerTextMapPropagator()  : void
registerTransportFactory()  : void
resourceDetector()  : ResourceDetectorInterface
resourceDetectors()  : array<int, ResourceDetectorInterface>
responsePropagator()  : ResponsePropagatorInterface
spanExporterFactory()  : SpanExporterFactoryInterface
textMapPropagator()  : TextMapPropagatorInterface
transportFactory()  : TransportFactoryInterface
Get transport factory registered for protocol. If $protocol contains a content-type eg `http/xyz` then only the first part, `http`, is used.
logDebug()  : void
logError()  : void
logInfo()  : void
logNotice()  : void
logWarning()  : void
doLog()  : void
Logging is best effort: a failing log writer (for example an error handler that throws on `trigger_error`) must not break the code that is being observed.
isRegistered()  : bool
Whether a component is registered. The first lookup runs the registrars. On a miss they are looked up again, to pick up registrars that were registered with the service loader after the first lookup. That happens without the `tbachert/spi` Composer plugin, when `_register.php` files are included one after the other.
loadRegistrars()  : void
Runs the {@see RegistrarInterface} providers that were not run yet. A registrar that fails is logged and skipped, it must not keep the others from registering their components.
notRegistered()  : RuntimeException
Components are contributed by {@see RegistrarInterface} providers, which only become known through the generated SPI data of the `tbachert/spi` Composer plugin. Without the plugin a component can be missing for as long as the `autoload.files` that would register it have not been included, for example while the SDK autoloads.
shouldLog()  : bool

Properties

$logRecordExporterFactories

private static array<string|int, mixed> $logRecordExporterFactories = []

$metricExporterFactories

private static array<string|int, mixed> $metricExporterFactories = []

$registrarCount

private static int $registrarCount = 0

$registrarsLoaded

private static bool $registrarsLoaded = false

$registrarsRun

private static array<RegistrarInterface>, true> $registrarsRun = []

$resourceDetectors

private static array<string|int, mixed> $resourceDetectors = []

$responsePropagators

private static array<string|int, mixed> $responsePropagators = []

$spanExporterFactories

private static array<string|int, mixed> $spanExporterFactories = []

$textMapPropagators

private static array<string|int, mixed> $textMapPropagators = []

$transportFactories

private static array<string|int, mixed> $transportFactories = []

Methods

registerLogRecordExporterFactory()

public static registerLogRecordExporterFactory(string $exporter, LogRecordExporterFactoryInterface|LogRecordExporterFactoryInterface> $factory[, bool $clobber = false ]) : void
Parameters
$exporter : string
$factory : LogRecordExporterFactoryInterface|LogRecordExporterFactoryInterface>
$clobber : bool = false
Tags
throws
TypeError

registerMetricExporterFactory()

public static registerMetricExporterFactory(string $exporter, MetricExporterFactoryInterface|MetricExporterFactoryInterface> $factory[, bool $clobber = false ]) : void
Parameters
$exporter : string
$factory : MetricExporterFactoryInterface|MetricExporterFactoryInterface>
$clobber : bool = false
Tags
throws
TypeError

registerSpanExporterFactory()

public static registerSpanExporterFactory(string $exporter, SpanExporterFactoryInterface|SpanExporterFactoryInterface> $factory[, bool $clobber = false ]) : void
Parameters
$exporter : string
$factory : SpanExporterFactoryInterface|SpanExporterFactoryInterface>
$clobber : bool = false
Tags
throws
TypeError

registerTransportFactory()

public static registerTransportFactory(string $protocol, TransportFactoryInterface|TransportFactoryInterface> $factory[, bool $clobber = false ]) : void
Parameters
$protocol : string
$factory : TransportFactoryInterface|TransportFactoryInterface>
$clobber : bool = false
Tags
throws
TypeError

transportFactory()

Get transport factory registered for protocol. If $protocol contains a content-type eg `http/xyz` then only the first part, `http`, is used.

public static transportFactory(string $protocol) : TransportFactoryInterface
Parameters
$protocol : string
Return values
TransportFactoryInterface

logDebug()

protected static logDebug(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string
$context : array<string|int, mixed> = []

logError()

protected static logError(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string
$context : array<string|int, mixed> = []

logInfo()

protected static logInfo(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string
$context : array<string|int, mixed> = []

logNotice()

protected static logNotice(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string
$context : array<string|int, mixed> = []

logWarning()

protected static logWarning(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string
$context : array<string|int, mixed> = []

doLog()

Logging is best effort: a failing log writer (for example an error handler that throws on `trigger_error`) must not break the code that is being observed.

private static doLog(string $level, string $message, array<string|int, mixed> $context) : void
Parameters
$level : string
$message : string
$context : array<string|int, mixed>

isRegistered()

Whether a component is registered. The first lookup runs the registrars. On a miss they are looked up again, to pick up registrars that were registered with the service loader after the first lookup. That happens without the `tbachert/spi` Composer plugin, when `_register.php` files are included one after the other.

private static isRegistered(array<string, mixed> &$registered, string $key) : bool
Parameters
$registered : array<string, mixed>
$key : string
Return values
bool

loadRegistrars()

Runs the {@see RegistrarInterface} providers that were not run yet. A registrar that fails is logged and skipped, it must not keep the others from registering their components.

private static loadRegistrars([bool $rescan = false ]) : void
Parameters
$rescan : bool = false

notRegistered()

Components are contributed by {@see RegistrarInterface} providers, which only become known through the generated SPI data of the `tbachert/spi` Composer plugin. Without the plugin a component can be missing for as long as the `autoload.files` that would register it have not been included, for example while the SDK autoloads.

private static notRegistered(string $message) : RuntimeException
Parameters
$message : string
Return values
RuntimeException

shouldLog()

private static shouldLog(string $level) : bool
Parameters
$level : string
Return values
bool
On this page

Search results