Improve error handling for telemetry uploads

- Use response.raise_for_status when telemetry upload files
- Do not send null packets to the destination server
This commit is contained in:
sabaimran
2024-01-25 20:40:42 +05:30
parent 098a8e4fb1
commit 211c5623e8
3 changed files with 9 additions and 6 deletions

View File

@@ -311,7 +311,8 @@ def upload_telemetry():
return
try:
logger.debug(f"📡 Upload usage telemetry to {constants.telemetry_server}:\n{state.telemetry}")
logger.info(f"📡 Uploading telemetry to {constants.telemetry_server}...")
logger.debug(f"Telemetry state:\n{state.telemetry}")
for log in state.telemetry:
for field in log:
# Check if the value for the field is JSON serializable
@@ -319,7 +320,8 @@ def upload_telemetry():
json.dumps(log[field])
except TypeError:
log[field] = str(log[field])
requests.post(constants.telemetry_server, json=state.telemetry)
response = requests.post(constants.telemetry_server, json=state.telemetry)
response.raise_for_status()
except Exception as e:
logger.error(f"📡 Error uploading telemetry: {e}", exc_info=True)
else:

View File

@@ -9,6 +9,7 @@ from khoj.routers.helpers import generate_online_subqueries
logger = logging.getLogger(__name__)
SERPER_DEV_API_KEY = os.getenv("SERPER_DEV_API_KEY")
OLOSTEP_API_KEY = os.getenv("OLOSTEP_API_KEY")
url = "https://google.serper.dev/search"

View File

@@ -86,10 +86,10 @@ def update_telemetry_state(
"user_agent": user_agent or "unknown",
"referer": referer or "unknown",
"host": host or "unknown",
"server_id": str(user.uuid) if user else None,
"subscription_type": subscription.type if subscription else None,
"is_recurring": subscription.is_recurring if subscription else None,
"client_id": str(client_app.name) if client_app else None,
"server_id": str(user.uuid),
"subscription_type": subscription.type,
"is_recurring": subscription.is_recurring,
"client_id": str(client_app.name) if client_app else "default",
}
if metadata: