eventit_py.event_logger module

class eventit_py.event_logger.EventLogger(default_event_type: Callable | None = None, **kwargs)

Bases: BaseEventLogger

event(func: Callable | None = None, description: str | None = None, tracking_details: dict[str, bool] | None = None, event_type: Type[BaseEvent] | None = None, group=None) Callable

Wrapper to be placed around functions that want logging functionality before they are called.

Parameters:
  • func (Callable, optional) – Function to be wrapped.

  • description (str, optional) – Description to be included with the event being logged.

  • tracking_details (dict[str, bool], optional) – Specific metrics to be tracked. Defaults to tracking all builtin metrics.

  • event_type (Callable) – Event type (as pydantic model) used for pydantic type validation

  • group – Group identifier for the event

Raises:

NotImplementedError – If logging backend specified in class constructor is not yet implemented

Returns:

wrapped function

Return type:

Callable

log_countable_event(api_event_details: dict, event_type: Type[BaseCountableEvent], group: str)
log_event(func: Callable | None = None, description: str | None = None, tracking_details: dict[str, bool] | None = None, event_type: Type[BaseEvent] | None = None, group: str | None = None) None

Main function used to log information. Inherits builtin metrics from BaseEventLogger.

Parameters:
  • func (Callable, optional) – Function that produced event we are logging. Defaults to None.

  • description (str, optional) – Description to be included with the event being logged.

  • tracking_details (dict[str, bool], optional) – Specific metrics to be tracked. Defaults to tracking all builtin metrics.

  • event_type (Callable) – Event type (as pydantic model) used for pydantic type validation.

Raises:

NotImplementedError – If logging backend specified in class constructor is not yet implemented.

This method is used to log information about an event. It takes in various parameters such as the function that produced the event, a description of the event, specific metrics to be tracked, the event type, and the event group. If no event type is provided, it defaults to the default event type specified in the class. If no event group is provided, it defaults to the default event group specified in the class.

The method first checks if the provided event type is derived from the default event type. If not, it raises a TypeError. It then prepares the tracking details by either using the provided tracking details or tracking all builtin metrics if none are provided. It creates a dictionary api_event_details to store the event details, including the description. It also creates a tracking_context dictionary to store additional context information for tracking.

The method then iterates over the tracking details and retrieves the corresponding metrics using the retrieve_metric method. The retrieved metrics are added to the api_event_details dictionary.

Finally, an event object is created using the event type and the api_event_details dictionary. The event is then logged to the chosen database client using the log_message method of the db_client.

Note: This method assumes the existence of a db_client attribute in the class, which is responsible for logging the event.

retrieve_metric(metric: str, func: Callable | None = None, context: dict[str, Any] | None = None) Any

Function where new metric retrieval code should be implemented.

Parameters:
  • metric (str) – _description_

  • func (Callable, optional) – _description_. Defaults to None.

Raises:

NotImplementedError – If retrieve_metric unimplemented for the specified metric

Returns:

The computed metric

Return type:

Any