Add telemetry debug/logging and failure report

Enhance post_update_to_api robustness and observability: add debug traces for entry, missing curl, duplicate submissions, DIAGNOSTICS/RANDOM_UUID checks, payload/URL output, and HTTP response code capture; make curl non-blocking and tolerant of failures. Also invoke post_update_to_api on installation failure so build/install errors are reported to telemetry. Includes a small comment glyph fix in build.func. Changes keep telemetry as a silent, best-effort path that won't break script execution.
This commit is contained in:
CanbiZ (MickLesk) 2026-02-09 16:53:25 +01:00
parent ce375b02aa
commit 5aa85ace6a
2 changed files with 31 additions and 7 deletions

View File

@ -323,15 +323,30 @@ EOF
# - Never blocks or fails script execution
# ------------------------------------------------------------------------------
post_update_to_api() {
# DEBUG: Show function entry
echo "[DEBUG] post_update_to_api() called with status=$1 exit_code=$2" >&2
# Silent fail - telemetry should never break scripts
command -v curl &>/dev/null || return 0
command -v curl &>/dev/null || {
echo "[DEBUG] curl not found, skipping" >&2
return 0
}
# Prevent duplicate submissions
POST_UPDATE_DONE=${POST_UPDATE_DONE:-false}
[[ "$POST_UPDATE_DONE" == "true" ]] && return 0
[[ "$POST_UPDATE_DONE" == "true" ]] && {
echo "[DEBUG] Already sent update, skipping" >&2
return 0
}
[[ "${DIAGNOSTICS:-no}" == "no" ]] && return 0
[[ -z "${RANDOM_UUID:-}" ]] && return 0
[[ "${DIAGNOSTICS:-no}" == "no" ]] && {
echo "[DEBUG] DIAGNOSTICS=no, skipping" >&2
return 0
}
[[ -z "${RANDOM_UUID:-}" ]] && {
echo "[DEBUG] RANDOM_UUID empty, skipping" >&2
return 0
}
local status="${1:-failed}"
local raw_exit_code="${2:-1}"
@ -377,10 +392,16 @@ post_update_to_api() {
EOF
)
echo "[DEBUG] Sending update to: $TELEMETRY_URL" >&2
echo "[DEBUG] Update payload: $JSON_PAYLOAD" >&2
# Fire-and-forget: never block, never fail
curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
local http_code
http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" &>/dev/null || true
-d "$JSON_PAYLOAD" -o /dev/stderr 2>&1) || true
echo "[DEBUG] HTTP response code: $http_code" >&2
POST_UPDATE_DONE=true
}

View File

@ -1882,7 +1882,7 @@ advanced_settings() {
fi
;;
# ══════════════<E29590><E29590><EFBFBD>════════════════════════════════════════════════════════════
# ══════════════<E29590><E29590><EFBFBD><EFBFBD>════════════════════════════════════════════════════════════
# STEP 3: Container ID
# ═══════════════════════════════════════════════════════════════════════════
3)
@ -4014,6 +4014,9 @@ EOF'
if [[ $install_exit_code -ne 0 ]]; then
msg_error "Installation failed in container ${CTID} (exit code: ${install_exit_code})"
# Report failure to telemetry API
post_update_to_api "failed" "$install_exit_code"
# Copy both logs from container before potential deletion
local build_log_copied=false
local install_log_copied=false