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"
Tags
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.
- droppedAttributeCount() : int
- Get the count of attributes that were dropped due to limits.
- fromArray() : self
- Create a GenericEvent from a normalized array representation.
- name() : string
- Get the event name.
-
normalize()
: array{name: string, timestamp: string, attributes: array
, droppedAttributeCount: int} - 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() ][, int $droppedAttributeCount = 0 ]) : mixed
Parameters
- $name : string
- $timestamp : DateTimeImmutable
- $attributesObject : Attributes = new Attributes()
- $droppedAttributeCount : int = 0
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[, Attributes|TAttributeValueMap $attributes = [] ][, int $droppedAttributeCount = 0 ]) : self
Parameters
- $name : string
-
Event name
- $timestamp : DateTimeImmutable
-
Event timestamp
- $attributes : Attributes|TAttributeValueMap = []
-
Event attributes
- $droppedAttributeCount : int = 0
-
Number of attributes dropped due to limits
Return values
selfdroppedAttributeCount()
Get the count of attributes that were dropped due to limits.
public
droppedAttributeCount() : int
Return values
intfromArray()
Create a GenericEvent from a normalized array representation.
public
static fromArray(array{name: string, timestamp: string, attributes: array, droppedAttributeCount?: int} $data) : self
Parameters
-
$data
: array{name: string, timestamp: string, attributes: array
, droppedAttributeCount?: int} -
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, droppedAttributeCount: int}
Return values
array{name: string, timestamp: string, attributes: arraytimestamp()
Get the event timestamp.
public
timestamp() : DateTimeImmutable