segrails.monitoring.tracker¶
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¶
Écrit les métriques d'inférence dans Azure Table Storage (une ligne par appel). |
Module Contents¶
- class segrails.monitoring.tracker.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).
- Parameters:
table_name – Nom de la table Azure (créée automatiquement si absente).
env – Environnement de déploiement (dev / test / beta / prod).
connection_string – Surcharge
AZURE_TABLES_CONNECTION_STRING.account_url – Surcharge
AZURE_TABLES_ACCOUNT_URL(utilisé avec DefaultAzureCredential).
Example
>>> tracker = TableTracker(table_name="SegrailsInferences", env="dev") >>> tracker.log_inference(result)
- _table_name = 'SegrailsInferences'¶
- _env = 'dev'¶
- _session_id¶
- _client: Any = None¶
- property enabled: bool¶
Return True if the tracker is connected and ready to write.
- 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.
- Parameters:
result – SegrailsResult returned by SegrailsClient.predict().
session_id – Logical session identifier used as PartitionKey. Defaults to the machine hostname (
socket.gethostname()).pipeline_name – Calling pipeline identifier.
env – Override the tracker’s env tag for this row only.
end_time – ISO 8601 timestamp of when predict() returned. Used to compute End_time and Duration columns.
- _build_client(connection_string: str, account_url: str, table_name: str) Any¶
Build and return a TableClient, or None on failure.
- _write(entity: dict[str, Any]) None¶
Write entity to the table. Logs warning on error.
- _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.