GenericEvent implements SpanEvent
Read onlyYes
FinalYes
Default implementation of SpanEvent.
GenericEvent provides a simple, immutable implementation for recording events within a span. Events are created with explicit timestamps.
Example usage:
$event = GenericEvent::create('user.login', $clock->now(), ['user.id' => '12345']);
echo $event->name(); // "user.login"
Interfaces
- SpanEvent
- Interface for events recorded within a span.
Methods
- __construct() : mixed
- attributes() : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>
- Get the event attributes.
- attributesObject() : Attributes
- Get the event attributes as an Attributes object.
- create() : self
- Create an event with an explicit timestamp.
- fromArray() : self
- Create a GenericEvent from a normalized array representation.
- name() : string
- Get the event name.
-
normalize()
: array{name: string, timestamp: string, attributes: array
} - Normalize the GenericEvent to an array representation for serialization.
- timestamp() : DateTimeImmutable
- Get the event timestamp.
Methods
__construct()
public
__construct(string $name, DateTimeImmutable $timestamp[, Attributes $attributesObject = new Attributes() ]) : mixed
Parameters
- $name : string
- $timestamp : DateTimeImmutable
- $attributesObject : Attributes = new Attributes()
attributes()
Get the event attributes.
public
attributes() : 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>attributesObject()
Get the event attributes as an Attributes object.
public
attributesObject() : Attributes
Return values
Attributescreate()
Create an event with an explicit timestamp.
public
static create(string $name, DateTimeImmutable $timestamp[, array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable> $attributes = [] ]) : self
Parameters
- $name : string
-
Event name
- $timestamp : DateTimeImmutable
-
Event timestamp
- $attributes : array<string, array<string|int, bool|DateTimeInterface|float|int|string|Throwable>|bool|DateTimeInterface|float|int|string|Throwable> = []
-
Event attributes
Return values
selffromArray()
Create a GenericEvent from a normalized array representation.
public
static fromArray(array{name: string, timestamp: string, attributes: array} $data) : self
Parameters
-
$data
: array{name: string, timestamp: string, attributes: array
} -
Normalized event data
Return values
selfname()
Get the event name.
public
name() : string
Return values
stringnormalize()
Normalize the GenericEvent to an array representation for serialization.
public
normalize() : array{name: string, timestamp: string, attributes: array}
Return values
array{name: string, timestamp: string, attributes: arraytimestamp()
Get the event timestamp.
public
timestamp() : DateTimeImmutable