OpenTelemetry PHP

AutoRootSpan
in package
uses LogsMessagesTrait

Table of Contents

Properties

$capturedResponseHeaders  : array<string, array<string|int, string>>
$hookManager  : HookManagerInterface|null
$notifySpanEnded  : callable(): mixed|null
$request  : ServerRequestInterface|null
The request of the root span, kept to record its body when the span ends. Not set for the CLI.
$responseHeaderHookRegistered  : bool
$rootScope  : ContextStorageScopeInterface|null
$shutdownHandlerRegistered  : bool
Whether a shutdown handler is queued, which ends the root span and calls the callback.

Methods

isEnabled()  : bool
Whether a root span should be created for the current web request.
start()  : void
Creates the root span for the current request or CLI script, the same way the OpenTelemetry PHP distro does.
logDebug()  : void
logError()  : void
logInfo()  : void
logNotice()  : void
logWarning()  : void
captureRequestHeaders()  : 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.
getSpanName()  : non-empty-string
isWebSpanEnabled()  : bool
OTEL_PHP_TRANSACTION_SPAN_ENABLED wins when it is set (also to false), otherwise the legacy alias decides.
processPathMatchers()  : string
registerResponseHeaderHookIfNeeded()  : void
requestForBodyCapture()  : ServerRequestInterface|null
The request is kept only when its body is going to be recorded, a bad configuration must not break the request.
shouldLog()  : bool

Properties

$capturedResponseHeaders

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

Response headers captured via the header() hook, reset for each request

$notifySpanEnded

private static callable(): mixed|null $notifySpanEnded = null

called once, right before the root span ends

$request

The request of the root span, kept to record its body when the span ends. Not set for the CLI.

private static ServerRequestInterface|null $request = null

$responseHeaderHookRegistered

private static bool $responseHeaderHookRegistered = false

$shutdownHandlerRegistered

Whether a shutdown handler is queued, which ends the root span and calls the callback.

private static bool $shutdownHandlerRegistered = false

Methods

isEnabled()

Whether a root span should be created for the current web request.

public static isEnabled() : bool

OTEL_PHP_EXPERIMENTAL_AUTO_ROOT_SPAN is a legacy alias of OTEL_PHP_TRANSACTION_SPAN_ENABLED, used only when the latter is unset.

Return values
bool

start()

Creates the root span for the current request or CLI script, the same way the OpenTelemetry PHP distro does.

public static start([callable|null $notifySpanEnded = null ]) : void

Enabled by OTEL_PHP_TRANSACTION_SPAN_ENABLED (web; OTEL_PHP_EXPERIMENTAL_AUTO_ROOT_SPAN is a legacy alias used only when it is unset) or OTEL_PHP_TRANSACTION_SPAN_ENABLED_CLI (CLI). Both default to false, a distro can default them to true. When a root span was already started, for example by SdkAutoloader::autoload(), no second one is created, but a given callback is still registered, replacing one registered earlier. This lets an embedder call this method after the autoloader, whether or not the autoloader has already started the root span.

Parameters
$notifySpanEnded : callable|null = null

called once at shutdown, while the root span is still active and right before it ends; not called when no root span was created, for example for an excluded request

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> = []

captureRequestHeaders()

private static captureRequestHeaders(ServerRequestInterface $request, SpanInterface $span) : void
Parameters
$request : ServerRequestInterface
$span : SpanInterface

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>

getSpanName()

private static getSpanName(ServerRequestInterface $request[, bool $cli = false ]) : non-empty-string
Parameters
$request : ServerRequestInterface
$cli : bool = false
Return values
non-empty-string

isWebSpanEnabled()

OTEL_PHP_TRANSACTION_SPAN_ENABLED wins when it is set (also to false), otherwise the legacy alias decides.

private static isWebSpanEnabled() : bool
Return values
bool

processPathMatchers()

private static processPathMatchers(string $path) : string
Parameters
$path : string
Return values
string

registerResponseHeaderHookIfNeeded()

private static registerResponseHeaderHookIfNeeded() : void

requestForBodyCapture()

The request is kept only when its body is going to be recorded, a bad configuration must not break the request.

private static requestForBodyCapture(ServerRequestInterface $request) : ServerRequestInterface|null
Parameters
$request : ServerRequestInterface
Return values
ServerRequestInterface|null

shouldLog()

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

Search results