segrails.monitoring.tracker =========================== .. py:module:: segrails.monitoring.tracker .. autoapi-nested-parse:: Monitoring tracker — writes inference metrics to Azure Table Storage. Mode no-op if azure-data-tables is not installed or no connection is configured. Writes are fire-and-forget in a background thread to avoid blocking predict(). Environment variables: AZURE_TABLES_CONNECTION_STRING: Storage account connection string. When set, used for direct authentication (local dev, CI). AZURE_TABLES_ACCOUNT_URL: Storage account table endpoint URL (e.g. ``https://deployment4dev.table.core.windows.net``). When set without a connection string, authenticates via DefaultAzureCredential (Managed Identity, az login, SP env vars). AZURE_TABLES_TABLE_NAME: Table name. Default: ``SegrailsInferences``. Classes ------- .. autoapisummary:: segrails.monitoring.tracker.TableTracker Module Contents --------------- .. py:class:: TableTracker(table_name: str = 'SegrailsInferences', env: str = 'dev', connection_string: str = '', account_url: str = '') Écrit les métriques d'inférence dans Azure Table Storage (une ligne par appel). Auth (par ordre de priorité) : connection string → DefaultAzureCredential (MI/az login). :param table_name: Nom de la table Azure (créée automatiquement si absente). :param env: Environnement de déploiement (dev / test / beta / prod). :param connection_string: Surcharge ``AZURE_TABLES_CONNECTION_STRING``. :param account_url: Surcharge ``AZURE_TABLES_ACCOUNT_URL`` (utilisé avec DefaultAzureCredential). .. rubric:: Example >>> tracker = TableTracker(table_name="SegrailsInferences", env="dev") >>> tracker.log_inference(result) .. py:attribute:: _table_name :value: 'SegrailsInferences' .. py:attribute:: _env :value: 'dev' .. py:attribute:: _session_id .. py:attribute:: _client :type: Any :value: None .. py:property:: enabled :type: bool Return True if the tracker is connected and ready to write. .. py:method:: log_inference(result: altametris.segrails.result.SegrailsResult, session_id: str | None = None, pipeline_name: str | None = None, env: str | None = None, end_time: str | None = None) -> None Write one inference row to the table (background thread). No-op if the tracker is disabled. Errors during write are caught and logged as warnings — they never propagate to the caller. :param result: SegrailsResult returned by SegrailsClient.predict(). :param session_id: Logical session identifier used as PartitionKey. Defaults to the machine hostname (``socket.gethostname()``). :param pipeline_name: Calling pipeline identifier. :param env: Override the tracker's env tag for this row only. :param end_time: ISO 8601 timestamp of when predict() returned. Used to compute End_time and Duration columns. .. py:method:: _build_client(connection_string: str, account_url: str, table_name: str) -> Any Build and return a TableClient, or None on failure. .. py:method:: _write(entity: dict[str, Any]) -> None Write entity to the table. Logs warning on error. .. py:method:: _build_entity(result: altametris.segrails.result.SegrailsResult, session_id: str, pipeline_name: str | None = None, env: str | None = None, end_time: str | None = None) -> dict[str, Any] Build the table entity dict from a SegrailsResult.