Flow PHP

Resource

Read onlyYes
FinalYes

Entity metadata attached to all telemetry signals.

A Resource represents the entity producing telemetry data, such as a service, container, or host. Resources are immutable and provide context that is attached to all traces, logs, and metrics.

Common resource attributes include:

  • service.name: The logical name of the service
  • service.version: The version of the service
  • host.name: The hostname of the machine
  • process.pid: The process ID

Example usage:

$resource = Resource::create([
    'service.name' => 'my-service',
    'service.version' => '1.0.0',
]);

Properties

$attributes  : Attributes

Methods

__construct()  : mixed
all()  : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>
Get all attributes.
count()  : int
Get the number of attributes.
create()  : self
Create a new Resource with the given attributes.
empty()  : self
Create an empty Resource with no attributes.
fromArray()  : self
Create a Resource from a normalized array representation.
get()  : null|array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable
Get the value of an attribute.
has()  : bool
Check if an attribute exists.
isEmpty()  : bool
Check if the resource has no attributes.
merge()  : self
Merge this Resource with another, with the other's attributes taking precedence.
normalize()  : array{attributes: array}
Normalize the Resource to an array representation for serialization.
with()  : self
Create a new Resource with an additional attribute.

Properties

Methods

all()

Get all attributes.

public all() : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>
Return values
array<string, array<string|int, bool|float|int|string>|bool|float|int|string>

count()

Get the number of attributes.

public count() : int
Return values
int

create()

Create a new Resource with the given attributes.

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

empty()

Create an empty Resource with no attributes.

public static empty() : self
Return values
self

fromArray()

Create a Resource from a normalized array representation.

public static fromArray(array{attributes: array$data) : self
Parameters
$data : array{attributes: array}

Normalized Resource data

Return values
self

get()

Get the value of an attribute.

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

Attribute key

Return values
null|array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable

The attribute value, or null if not found

has()

Check if an attribute exists.

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

Attribute key

Return values
bool

isEmpty()

Check if the resource has no attributes.

public isEmpty() : bool
Return values
bool

merge()

Merge this Resource with another, with the other's attributes taking precedence.

public merge(self $other) : self
Parameters
$other : self

The Resource to merge with

Return values
self

New Resource with merged attributes

normalize()

Normalize the Resource to an array representation for serialization.

public normalize() : array{attributes: array}
Return values
array{attributes: array}

with()

Create a new Resource with an additional attribute.

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

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

Parameters
$key : string

Attribute key

$value : array<string|int, bool|float|int|string>|bool|float|int|string

Attribute value

Return values
self

New Resource with the added attribute


        
On this page

Search results