LEIP Events¶
- class events.App(*, id: Optional[str] = None, name: Optional[str] = None, version: Optional[str] = None, container_version: Optional[str] = None, org_name: str = 'Latent AI', org_url: str = 'https://latentai.com/')¶
Application metadata for events.
- Parameters
id (Optional[str]) –
name (Optional[str]) –
version (Optional[str]) –
container_version (Optional[str]) –
org_name (str) –
org_url (str) –
- Return type
None
- container_version: Optional[str]¶
Version of the running container, if applicable.
- id: Optional[str]¶
ID of the application.
- name: Optional[str]¶
Name of the application.
- org_name¶
Name of the organization that maintains the application.
- org_url¶
URL of the organization that maintains the application.
- version: Optional[str]¶
Version of the application.
- class events.EventLogger(*, app: App = App(id=None, name=None, version=None, container_version=None, org_name='Latent AI', org_url='https://latentai.com/'), buffer_directory: Optional[CreatedDirectoryPath] = None, buffer_limit: int = 200, http_url: str = '', http_headers: Dict[str, str] = {}, http_method: str = 'POST', user_id: Optional[str] = None, project_id: Optional[str] = None, session: Dict[str, Any] = {}, tags: List[str] = [])¶
Instances of this class log events to configured targets.
- Parameters
app (App) –
buffer_directory (Optional[CreatedDirectoryPath]) –
buffer_limit (int) –
http_url (str) –
http_headers (Dict[str, str]) –
http_method (str) –
user_id (Optional[str]) –
project_id (Optional[str]) –
session (Dict[str, Any]) –
tags (List[str]) –
- Return type
None
- app: events.payload.App¶
Application metadata.
- buffer_directory: Optional[commons.types.CreatedDirectoryPath]¶
Optional buffer directory where events are stored as JSON files.
- buffer_limit: int¶
Limit file count of the buffer directory. When the limit is reached, the oldest file is deleted after a new one was saved.
- classmethod from_json_file(path: Union[str, PathLike]) EventLogger ¶
Creates an instance from a JSON file.
- Parameters
path (Union[str, PathLike]) – Path to the input JSON file.
- Returns
The created instance.
- Return type
- http_headers: Dict[str, str]¶
Headers for the HTTP endpoint.
- http_method: str¶
Method used for the HTTP request.
- http_url: str¶
Optional HTTP endpoint where events are sent as JSON.
- log(name: str, category: Optional[str] = None, tags: List[str] = [], output_path: Optional[Union[str, PathLike]] = None, **kwargs) None ¶
Logs an instant event. The resulting event payload will include these fields:
- ts
A timestamp as milliseconds from the epoch.
- id
A UUID to identify the event.
- aid
The pre-configured application ID.
- did
A Docker container ID, if available.
- meta
The preconfigured application metadata and device metadata obtained from the O.S.
- session
The session object that this logger contains.
- uid
The user ID assigned to this logger.
- pid
The project ID assigned to this logger.
- name
The given name of the event.
- category
The given category of the event.
- tags
List of tags per user.
- data
Includes all other keyword arguments in this call.
- Parameters
name (str) – A name for the event, stored in name key of the payload.
category (Optional[str]) – A category for the event, stored in category key of the payload.
tags (List[str]) – List of tags to be included in the event.
output_path (Optional[Union[str, PathLike]]) – Directory path where to save event as a results.json file.
kwargs – Additional key-value pairs to include inside the data key of the payload.
- Return type
None
- project_id: Optional[str]¶
Project ID to include in events.
- session: Dict[str, Any]¶
Session data that all event payloads will contain.
- tags: List[str]¶
Default tags to add to all event payloads. Will combine with provided tags.
- track(name: str, category: Optional[str] = None, tags: List[str] = [], output_path: Union[str, PathLike] = None, session: Dict[str, Any] = {}, **kwargs) Iterator[Event] ¶
Context manager to execute code that logs an event when finished. The resulting event payload will include all fields described in log method, plus:
- stats
Start, end, and duration times in seconds.
- session
The session object that this logger contains merged with the provided session object. All events that are generated inside the context manager will also contain this merged session object.
Also, you can use the event object obtained from the context manager to add more keys inside data key of the payload by using its add method.
- Parameters
name (str) – A name for the event, stored in name key of the payload.
category (Optional[str]) – A category for the event, stored in category key of the payload.
tags (List[str]) – List of tags to be included in the event.
output_path (Union[str, PathLike]) – Directory path where to save event as a results.json file.
session (Dict[str, Any]) – A session object that is merged with this logger’s session object to store in session key of the payload.
kwargs – Additional key-value pairs to include inside the data key of the payload.
- Returns
An event object that may be used to add data to the event.
- Return type
Iterator[Event]
- user_id: Optional[str]¶
User ID to include in events.