interface TransactionInterface 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.

bool
isSampled()

Transactions that are 'sampled' will include all available information Transactions that are not sampled will not have 'spans' or 'context'.

string|null
getParentId()

Hex encoded 64 random bits ID of the parent transaction or span.

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

Begins a new span with the current execution segment as the new span's parent and sets as the new span as the current span for this transaction.

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

Begins a new span with the current execution segment as the new span's parent and sets the new span as the current span for this transaction.

getCurrentSpan()

Returns the current span.

context()

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

void
setResult(string|null $result)

The result of the transaction.

string|null
getResult()

No description

string
ensureParentId()

If the transaction does not have a parent ID yet, calling this method generates a new ID, sets it as the parent ID of this transaction, and returns it as a string.

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

bool isSampled()

Transactions that are 'sampled' will include all available information Transactions that are not sampled will not have 'spans' or 'context'.

Return Value

bool

string|null getParentId()

Hex encoded 64 random bits ID of the parent transaction or span.

Only a root transaction of a trace does not have a parent ID, otherwise it needs to be set.

Return Value

string|null

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

Begins a new span with the current execution segment as the new span's parent and sets as the new span as the current span for this transaction.

The current execution segment is the current span if there is one or this transaction itself otherwise.

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::getTimestamp() For the description.

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

Begins a new span with the current execution segment as the new span's parent and sets the new span as the current span for this transaction.

The current execution segment is the current span if there is one or this transaction itself otherwise.

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::getTimestamp() For the description.

SpanInterface getCurrentSpan()

Returns the current span.

Return Value

SpanInterface

The current span

TransactionContextInterface context()

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

void setResult(string|null $result)

The result of the transaction.

For HTTP-related transactions, this should be the status code formatted like 'HTTP 2xx'.

Parameters

string|null $result

Return Value

void

string|null getResult()

No description

Return Value

string|null

See also

setResult() For the description

string ensureParentId()

If the transaction does not have a parent ID yet, calling this method generates a new ID, sets it as the parent ID of this transaction, and returns it as a string.

Return Value

string