Event
Defines the Event schema, which represents an event emitted by the system.
Event
Bases: BaseModel
A data class to store an event attributes.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the event. Defaults to None. |
value |
str | bytes | dict[str, Any]
|
The value of the event. Defaults to an empty string. |
value_type |
EventValueType | None
|
The type of the value of the event. Defaults to None. |
level |
EventLevel
|
The severity level of the event. Defaults to EventLevel.INFO. |
type |
str
|
The type of the event. Defaults to EventType.RESPONSE. |
timestamp |
datetime
|
The timestamp of the event. Defaults to the current timestamp. |
metadata |
dict[str, Any]
|
The metadata of the event. Defaults to an empty dictionary. |
infer_or_validate_value_type()
Infers or validates the value type of the event.
This method infers or validates the value type of the event based on the payload type. If the value type is not specified, it will be inferred from the payload type. If the value type is specified, it will be validated against the compatible value types.
Returns:
| Name | Type | Description |
|---|---|---|
Event |
Event
|
The event with the inferred or validated value type. |
serialize_level(level)
Serializes an EventLevel object into its string representation.
This method serializes the given EventLevel object by returning its name as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
EventLevel
|
The EventLevel object to be serialized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the EventLevel object. |
serialize_value(value)
Serializes the value of the event.
This method is used to serialize the value of the event to a string or dictionary. If the value is a bytes object, it will be encoded to a base64 string. Otherwise, the value is returned as is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bytes | dict[str, Any]
|
The value of the event. |
required |
Returns:
| Type | Description |
|---|---|
str | dict[str, Any]
|
str | dict[str, Any]: The serialized value of the event. |