Coverage for /home/runner/work/bijux-cli/bijux-cli/src/bijux_cli/contracts/telemetry.py: 100%
8 statements
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
1# SPDX-License-Identifier: MIT
2# Copyright © 2025 Bijan Mousavi
4"""Defines the contract for the fire-and-forget telemetry service.
6This module specifies the `TelemetryProtocol`, a formal interface that any
7service responsible for collecting and managing "fire-and-forget" telemetry
8or analytics events must implement.
9"""
11from __future__ import annotations
13from collections.abc import Coroutine
14from typing import Any, Protocol, runtime_checkable
17@runtime_checkable
18class TelemetryProtocol(Protocol):
19 """Defines the contract for fire-and-forget analytics collection.
21 This interface specifies the methods for recording telemetry events and
22 managing the lifecycle of the telemetry service.
23 """
25 def event(
26 self, name: str, payload: dict[str, Any]
27 ) -> None | Coroutine[Any, Any, None]:
28 """Records a telemetry event.
30 Args:
31 name (str): The name of the event (e.g., "COMMAND_START").
32 payload (dict[str, Any]): A dictionary of key-value pairs
33 containing the event data.
35 Returns:
36 Either None (sync) or an awaitable resolving to None (async).
37 """
38 ...
40 def flush(self) -> None:
41 """Flushes any buffered telemetry events to their destination."""
42 ...
44 def enable(self) -> None:
45 """Enables the collection of telemetry data."""
46 ...