OpenTelemetry PHP

ReadWriteSpanInterface extends SpanInterface, ReadableSpanInterface

Represents a value that can be stored within {@see ContextInterface}.

Table of Contents

Methods

activate()  : ScopeInterface
Adds `$this` to the {@see Context::getCurrent() current context} and makes the new {@see Context} the current context.
addEvent()  : SpanInterface
addLink()  : SpanInterface
Records a link to another `SpanContext`.
end()  : void
fromContext()  : SpanInterface
Returns the {@see SpanInterface} from the provided *$context*, falling back on {@see SpanInterface::getInvalid()} if there is no span in the provided context.
getAttribute()  : mixed
Returns the value of the attribute with the provided *key*.
getContext()  : SpanContextInterface
getCurrent()  : SpanInterface
Returns the current {@see SpanInterface} from the current {@see ContextInterface}, falling back on {@see SpanInterface::getEmpty()} if there is no span in the current context.
getDuration()  : int
Returns the duration of the {@see API\SpanInterface} in nanoseconds.
getInstrumentationScope()  : InstrumentationScopeInterface
getInvalid()  : SpanInterface
Returns an invalid {@see SpanInterface} that is used when tracing is disabled, such s when there is no available SDK.
getKind()  : int
getName()  : string
getParentContext()  : SpanContextInterface
hasEnded()  : bool
isRecording()  : bool
recordException()  : SpanInterface
setAttribute()  : SpanInterface
setAttributes()  : SpanInterface
setStatus()  : SpanInterface
storeInContext()  : ContextInterface
Returns a new {@see ContextInterface} created by setting `$this` into the provided [@see ContextInterface}.
toSpanData()  : SpanDataInterface
Returns an immutable representation of this instance.
updateName()  : SpanInterface
wrap()  : SpanInterface
Returns a non-recording {@see SpanInterface} that hold the provided *$spanContext* but has no functionality.

Methods

activate()

Adds `$this` to the {@see Context::getCurrent() current context} and makes the new {@see Context} the current context.

public activate() : ScopeInterface

ScopeInterface::detach() MUST be called to properly restore the previous context.

This method is equivalent to Context::getCurrent().with($value).activate();.

Tags
todo:

Update this to suggest using the new helper method way to doing something in a specific context/span.

Return values
ScopeInterface

Records a link to another `SpanContext`.

public addLink(SpanContextInterface $context[, iterable<string|int, mixed> $attributes = [] ]) : SpanInterface

Adding links at span creation via is preferred to calling later, for contexts that are available during span creation, because head sampling decisions can only consider information present during span creation.

Parameters
$context : SpanContextInterface

span context to link

$attributes : iterable<string|int, mixed> = []

attributes to associate with the link

Tags
see
https://opentelemetry.io/docs/specs/otel/trace/api/#add-link
Return values
SpanInterface

this span

getAttribute()

Returns the value of the attribute with the provided *key*.

public getAttribute(string $key) : mixed

Returns null if there are no attributes set, or no attribute with that key exists.

Parameters
$key : string

getCurrent()

Returns the current {@see SpanInterface} from the current {@see ContextInterface}, falling back on {@see SpanInterface::getEmpty()} if there is no span in the current context.

public static getCurrent() : SpanInterface
Return values
SpanInterface

getDuration()

Returns the duration of the {@see API\SpanInterface} in nanoseconds.

public getDuration() : int

If still active, returns now() - start.

Return values
int

getInvalid()

Returns an invalid {@see SpanInterface} that is used when tracing is disabled, such s when there is no available SDK.

public static getInvalid() : SpanInterface
Return values
SpanInterface

setAttribute()

public setAttribute(non-empty-string $key, bool|int|float|string|array<string|int, mixed>|null $value) : SpanInterface
Parameters
$key : non-empty-string
$value : bool|int|float|string|array<string|int, mixed>|null

Note: arrays MUST be homogeneous, i.e. it MUST NOT contain values of different types.

Tags
see
https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#set-attributes

Adding attributes at span creation is preferred to calling setAttribute later, as samplers can only consider information already present during span creation

Return values
SpanInterface

setAttributes()

public setAttributes(iterable<non-empty-string, bool|int|float|string|array<string|int, mixed>|null> $attributes) : SpanInterface
Parameters
$attributes : iterable<non-empty-string, bool|int|float|string|array<string|int, mixed>|null>
Tags
see
https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#set-attributes

An attribute with a null key will be dropped, and an attribute with a null value will be dropped but also remove any existing attribute with the same key.

Return values
SpanInterface

wrap()

Returns a non-recording {@see SpanInterface} that hold the provided *$spanContext* but has no functionality.

public static wrap(SpanContextInterface $spanContext) : SpanInterface

It will not be exported and al tracing operations are no-op, but can be used to propagate a valid SpanContext downstream.

Parameters
$spanContext : SpanContextInterface
Tags
see
https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#wrapping-a-spancontext-in-a-span
Return values
SpanInterface

        
On this page

Search results