interface SpanInterface implements ExecutionSegmentInterface (View source)

Methods

string
getId()

Hex encoded 64 random bits (== 8 bytes == 16 hex digits) ID.

string
getTraceId()

Hex encoded 128 random bits (== 16 bytes == 32 hex digits) ID of the correlated trace.

float
getTimestamp()

Recorded time of the event.

beginChildSpan(string $name, string $type, string|null $subtype = null, string|null $action = null, float|null $timestamp = null)

Begins a new span with this execution segment as the new span's parent.

mixed
captureChildSpan(string $name, string $type, Closure $callback, string|null $subtype = null, string|null $action = null, float|null $timestamp = null)

Begins a new span with this execution segment as the new span's parent, runs the provided callback as the new span and automatically ends the new span.

void
setName(string $name)

  • For transactions: The name of this transaction.

void
setType(string $type)

Type is a keyword of specific relevance in the service's domain e.g.,

  • For transaction: 'db', 'external' for a span and 'request', 'backgroundjob' for a transaction, etc.

DistributedTracingData|null
getDistributedTracingData() deprecated

No description

void
injectDistributedTracingHeaders(Closure $headerInjector)

Returns distributed tracing data for the current span/transaction

void
end(float|null $duration = null)

Sets the end timestamp and finalizes this object's state.

bool
hasEnded()

Returns true if this execution segment has already ended.

string|null
createErrorFromThrowable(Throwable $throwable)

Creates an error based on the given Throwable instance with this execution segment as the parent.

string|null
createCustomError(CustomErrorData $customErrorData)

Creates an error based on the given Throwable instance with this execution segment as the parent.

void
setOutcome(string|null $outcome)

The outcome of the transaction/span: success, failure, or unknown.

string|null
getOutcome()

No description

bool
isNoop()

Returns true if this execution segment is a no-op (for example when recording is disabled).

void
discard()

Discards this execution segment.

string
getTransactionId()

Hex encoded 64 random bits ID of the correlated transaction.

string
getParentId()

Hex encoded 64 random bits ID of the parent.

void
setAction(string|null $action)

The specific kind of event within the sub-type represented by the span e.g., 'query' for type/sub-type 'db'/'mysql', 'connect' for type/sub-type 'db'/'cassandra'

void
setSubtype(string|null $subtype)

A further sub-division of the type e.g., 'mysql', 'postgresql' or 'elasticsearch' for type 'db', 'http' for type 'external', etc.

context()

Returns context (context allows to set labels, etc.)

void
endSpanEx(int $numberOfStackFramesToSkip, float|null $duration = null)

Extended version of ExecutionSegmentInterface::end()

Details

string getId()

Hex encoded 64 random bits (== 8 bytes == 16 hex digits) ID.

Return Value

string

string getTraceId()

Hex encoded 128 random bits (== 16 bytes == 32 hex digits) ID of the correlated trace.

Return Value

string

float getTimestamp()

Recorded time of the event.

For events that have non-zero duration this time corresponds to the start of the event. UTC based and in microseconds since Unix epoch.

Return Value

float

SpanInterface beginChildSpan(string $name, string $type, string|null $subtype = null, string|null $action = null, float|null $timestamp = null)

Begins a new span with this execution segment as the new span's parent.

Parameters

string $name

New span's name

string $type

New span's type

string|null $subtype

New span's subtype

string|null $action

New span's action

float|null $timestamp

Start time of the new span

Return Value

SpanInterface

New span

See also

\Elastic\Apm\SpanInterface::setName() For the description.
\Elastic\Apm\SpanInterface::setType() For the description.
SpanInterface::setSubtype For the description.
SpanInterface::setAction For the description.
\Elastic\Apm\SpanInterface::setTimestamp() For the description.

mixed captureChildSpan(string $name, string $type, Closure $callback, string|null $subtype = null, string|null $action = null, float|null $timestamp = null)

Begins a new span with this execution segment as the new span's parent, runs the provided callback as the new span and automatically ends the new span.

Parameters

string $name

New span's name

string $type

New span's type

Closure $callback

Callback to execute as the new span

string|null $subtype

New span's subtype

string|null $action

New span's action

float|null $timestamp

Start time of the new span

Return Value

mixed

The return value of $callback

See also

\Elastic\Apm\SpanInterface::setName() For the description.
\Elastic\Apm\SpanInterface::setType() For the description.
SpanInterface::setSubtype For the description.
SpanInterface::setAction For the description.
\Elastic\Apm\SpanInterface::setTimestamp() For the description.

void setName(string $name)

  • For transactions: The name of this transaction.

Generic designation of a transaction in the scope of a single service (eg: 'GET /users/:id').

  • For spans: Generic designation of a span in the scope of a transaction.

The length of this string is limited to 1024.

Parameters

string $name

Return Value

void

void setType(string $type)

Type is a keyword of specific relevance in the service's domain e.g.,

  • For transaction: 'db', 'external' for a span and 'request', 'backgroundjob' for a transaction, etc.

  • For span: 'db.postgresql.query', 'template.erb', etc.

The length of this string is limited to 1024.

Parameters

string $type

Return Value

void

DistributedTracingData|null getDistributedTracingData() deprecated

deprecated Deprecated since version 1.3 - use injectDistributedTracingHeaders() instead

No description

Return Value

DistributedTracingData|null

See also

injectDistributedTracingHeaders() Use it instead of this method Returns distributed tracing data

void injectDistributedTracingHeaders(Closure $headerInjector)

Returns distributed tracing data for the current span/transaction

$headerInjector is callback to inject headers with signature

(string $headerName, string $headerValue): void

Parameters

Closure $headerInjector

Callback that actually injects header(s) for the underlying transport

Return Value

void

void end(float|null $duration = null)

Sets the end timestamp and finalizes this object's state.

If any mutating method (for example any set... method is a mutating method) is called on a instance which has already then a warning is logged. For example, end() is a mutating method as well.

Parameters

float|null $duration

In milliseconds with 3 decimal points.

Return Value

void

bool hasEnded()

Returns true if this execution segment has already ended.

Return Value

bool

string|null createErrorFromThrowable(Throwable $throwable)

Creates an error based on the given Throwable instance with this execution segment as the parent.

Parameters

Throwable $throwable

Return Value

string|null

ID of the reported error event or null if no event was reported (for example, because recording is disabled)

string|null createCustomError(CustomErrorData $customErrorData)

Creates an error based on the given Throwable instance with this execution segment as the parent.

Parameters

CustomErrorData $customErrorData

Return Value

string|null

ID of the reported error event or null if no event was reported (for example, because recording is disabled)

void setOutcome(string|null $outcome)

The outcome of the transaction/span: success, failure, or unknown.

Outcome may be one of a limited set of permitted values describing the success or failure of the transaction/span. This field can be used for calculating error rates for incoming/outgoing requests.

Parameters

string|null $outcome

Return Value

void

string|null getOutcome()

No description

Return Value

string|null

See also

setOutcome() For the description

bool isNoop()

Returns true if this execution segment is a no-op (for example when recording is disabled).

Return Value

bool

void discard()

Discards this execution segment.

Return Value

void

string getTransactionId()

Hex encoded 64 random bits ID of the correlated transaction.

Return Value

string

string getParentId()

Hex encoded 64 random bits ID of the parent.

If this span is the root span of the correlated transaction the its parent is the correlated transaction otherwise its parent is the parent span.

Return Value

string

void setAction(string|null $action)

The specific kind of event within the sub-type represented by the span e.g., 'query' for type/sub-type 'db'/'mysql', 'connect' for type/sub-type 'db'/'cassandra'

The length of this string is limited to 1024.

Parameters

string|null $action

Return Value

void

void setSubtype(string|null $subtype)

A further sub-division of the type e.g., 'mysql', 'postgresql' or 'elasticsearch' for type 'db', 'http' for type 'external', etc.

The length of this string is limited to 1024.

Parameters

string|null $subtype

Return Value

void

SpanContextInterface context()

Returns context (context allows to set labels, etc.)

Return Value

SpanContextInterface

void endSpanEx(int $numberOfStackFramesToSkip, float|null $duration = null)

Extended version of ExecutionSegmentInterface::end()

Parameters

int $numberOfStackFramesToSkip

Number of stack frames to skip when capturing stack trace.

float|null $duration

In milliseconds with 3 decimal points.

Return Value

void

See also

ExecutionSegmentInterface::end For the description