Spaces:
Build error
Build error
Create telemetry.py
Browse files- telemetry.py +22 -0
telemetry.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# telemetry.py
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
LOG_FILE = "telemetry_log.jsonl"
|
| 7 |
+
|
| 8 |
+
def log_event(agent_id, action, status, metadata=None):
|
| 9 |
+
"""Logs each agent event with timestamp and context."""
|
| 10 |
+
event = {
|
| 11 |
+
"timestamp": datetime.utcnow().isoformat(),
|
| 12 |
+
"agent_id": agent_id,
|
| 13 |
+
"action": action,
|
| 14 |
+
"status": status,
|
| 15 |
+
"metadata": metadata or {}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# Write to local JSONL file (can be replaced with Supabase later)
|
| 19 |
+
with open(LOG_FILE, "a") as f:
|
| 20 |
+
f.write(json.dumps(event) + "\n")
|
| 21 |
+
|
| 22 |
+
print(f"[Telemetry] Logged: {action} - {status}")
|