Flow PHP

Attributes

Read onlyYes
FinalYes

Immutable container for telemetry attributes.

Attributes are key-value pairs attached to spans, logs, metrics, resources, and events. Values can be strings, integers, floats, booleans, DateTimeInterface, Throwable, or arrays of primitive types.

Example usage:

$attributes = Attributes::create([
    'user.id' => '12345',
    'user.roles' => ['admin', 'user'],
    'timestamp' => new \DateTimeImmutable(),
    'error' => $exception,
]);

Methods

__construct()  : mixed
count()  : int
Get attribute count.
create()  : self
Create Attributes from key-value pairs.
empty()  : self
Create empty Attributes.
fromArray()  : self
Create Attributes from normalized array.
get()  : null|array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable
Get a specific attribute value.
has()  : bool
Check if attribute exists.
isEmpty()  : bool
Check if empty.
merge()  : self
Merge with another Attributes instance.
normalize()  : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>
Normalize to array representation.
with()  : self
Create new Attributes with additional attribute.

Methods

__construct()

public __construct([array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable$values = [] ]) : mixed
Parameters
$values : array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable> = []

count()

Get attribute count.

public count() : int
Return values
int

create()

Create Attributes from key-value pairs.

public static create([array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable$values = [] ]) : self
Parameters
$values : array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable> = []
Return values
self

empty()

Create empty Attributes.

public static empty() : self
Return values
self

fromArray()

Create Attributes from normalized array.

public static fromArray(array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable$data) : self
Parameters
$data : array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable>
Return values
self

get()

Get a specific attribute value.

public get(string $key) : null|array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable
Parameters
$key : string
Return values
null|array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable

has()

Check if attribute exists.

public has(string $key) : bool
Parameters
$key : string
Return values
bool

isEmpty()

Check if empty.

public isEmpty() : bool
Return values
bool

merge()

Merge with another Attributes instance.

public merge(self $other) : self

The other instance's attributes take precedence over this instance's attributes when keys overlap.

Parameters
$other : self
Return values
self

normalize()

Normalize to array representation.

public normalize() : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>

DateTimeInterface values are converted to ISO 8601 strings. Throwable values are converted to structured arrays with type, message, and stacktrace.

Return values
array<string, array<string|int, bool|float|int|string>|bool|float|int|string>

with()

Create new Attributes with additional attribute.

public with(string $key, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable $value) : self

If the key already exists, its value will be replaced.

Parameters
$key : string
$value : array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable
Return values
self

        
On this page

Search results