mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-20 11:19:56 +08:00
fix: telemetry source tagging + duration guards
Add --source, --error-message, --failed-step flags to gstack-telemetry-log. Source tagging (live vs test via GSTACK_TELEMETRY_SOURCE env) prevents E2E tests from polluting production data. Duration guards cap unreasonable values (>24h or negative → null). Partial cherry-pick from garrytan/community-mode — non-breaking parts only. Skips install_fingerprint rename (needs schema migration). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,21 +32,30 @@ OUTCOME="unknown"
|
|||||||
USED_BROWSE="false"
|
USED_BROWSE="false"
|
||||||
SESSION_ID=""
|
SESSION_ID=""
|
||||||
ERROR_CLASS=""
|
ERROR_CLASS=""
|
||||||
|
ERROR_MESSAGE=""
|
||||||
|
FAILED_STEP=""
|
||||||
EVENT_TYPE="skill_run"
|
EVENT_TYPE="skill_run"
|
||||||
|
SOURCE=""
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--skill) SKILL="$2"; shift 2 ;;
|
--skill) SKILL="$2"; shift 2 ;;
|
||||||
--duration) DURATION="$2"; shift 2 ;;
|
--duration) DURATION="$2"; shift 2 ;;
|
||||||
--outcome) OUTCOME="$2"; shift 2 ;;
|
--outcome) OUTCOME="$2"; shift 2 ;;
|
||||||
--used-browse) USED_BROWSE="$2"; shift 2 ;;
|
--used-browse) USED_BROWSE="$2"; shift 2 ;;
|
||||||
--session-id) SESSION_ID="$2"; shift 2 ;;
|
--session-id) SESSION_ID="$2"; shift 2 ;;
|
||||||
--error-class) ERROR_CLASS="$2"; shift 2 ;;
|
--error-class) ERROR_CLASS="$2"; shift 2 ;;
|
||||||
--event-type) EVENT_TYPE="$2"; shift 2 ;;
|
--error-message) ERROR_MESSAGE="$2"; shift 2 ;;
|
||||||
|
--failed-step) FAILED_STEP="$2"; shift 2 ;;
|
||||||
|
--event-type) EVENT_TYPE="$2"; shift 2 ;;
|
||||||
|
--source) SOURCE="$2"; shift 2 ;;
|
||||||
*) shift ;;
|
*) shift ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Source: flag > env > default 'live'
|
||||||
|
SOURCE="${SOURCE:-${GSTACK_TELEMETRY_SOURCE:-live}}"
|
||||||
|
|
||||||
# ─── Read telemetry tier ─────────────────────────────────────
|
# ─── Read telemetry tier ─────────────────────────────────────
|
||||||
TIER="$("$CONFIG_CMD" get telemetry 2>/dev/null || true)"
|
TIER="$("$CONFIG_CMD" get telemetry 2>/dev/null || true)"
|
||||||
TIER="${TIER:-off}"
|
TIER="${TIER:-off}"
|
||||||
@@ -135,6 +144,20 @@ mkdir -p "$ANALYTICS_DIR"
|
|||||||
ERR_FIELD="null"
|
ERR_FIELD="null"
|
||||||
[ -n "$ERROR_CLASS" ] && ERR_FIELD="\"$ERROR_CLASS\""
|
[ -n "$ERROR_CLASS" ] && ERR_FIELD="\"$ERROR_CLASS\""
|
||||||
|
|
||||||
|
ERR_MSG_FIELD="null"
|
||||||
|
[ -n "$ERROR_MESSAGE" ] && ERR_MSG_FIELD="\"$(echo "$ERROR_MESSAGE" | head -c 200 | sed 's/"/\\"/g')\""
|
||||||
|
|
||||||
|
STEP_FIELD="null"
|
||||||
|
[ -n "$FAILED_STEP" ] && STEP_FIELD="\"$(echo "$FAILED_STEP" | head -c 30)\""
|
||||||
|
|
||||||
|
# Cap unreasonable durations
|
||||||
|
if [ -n "$DURATION" ] && [ "$DURATION" -gt 86400 ] 2>/dev/null; then
|
||||||
|
DURATION="" # null if > 24h
|
||||||
|
fi
|
||||||
|
if [ -n "$DURATION" ] && [ "$DURATION" -lt 0 ] 2>/dev/null; then
|
||||||
|
DURATION="" # null if negative
|
||||||
|
fi
|
||||||
|
|
||||||
DUR_FIELD="null"
|
DUR_FIELD="null"
|
||||||
[ -n "$DURATION" ] && DUR_FIELD="$DURATION"
|
[ -n "$DURATION" ] && DUR_FIELD="$DURATION"
|
||||||
|
|
||||||
@@ -144,10 +167,11 @@ INSTALL_FIELD="null"
|
|||||||
BROWSE_BOOL="false"
|
BROWSE_BOOL="false"
|
||||||
[ "$USED_BROWSE" = "true" ] && BROWSE_BOOL="true"
|
[ "$USED_BROWSE" = "true" ] && BROWSE_BOOL="true"
|
||||||
|
|
||||||
printf '{"v":1,"ts":"%s","event_type":"%s","skill":"%s","session_id":"%s","gstack_version":"%s","os":"%s","arch":"%s","duration_s":%s,"outcome":"%s","error_class":%s,"used_browse":%s,"sessions":%s,"installation_id":%s,"_repo_slug":"%s","_branch":"%s"}\n' \
|
printf '{"v":1,"ts":"%s","event_type":"%s","skill":"%s","session_id":"%s","gstack_version":"%s","os":"%s","arch":"%s","duration_s":%s,"outcome":"%s","error_class":%s,"error_message":%s,"failed_step":%s,"used_browse":%s,"sessions":%s,"installation_id":%s,"source":"%s","_repo_slug":"%s","_branch":"%s"}\n' \
|
||||||
"$TS" "$EVENT_TYPE" "$SKILL" "$SESSION_ID" "$GSTACK_VERSION" "$OS" "$ARCH" \
|
"$TS" "$EVENT_TYPE" "$SKILL" "$SESSION_ID" "$GSTACK_VERSION" "$OS" "$ARCH" \
|
||||||
"$DUR_FIELD" "$OUTCOME" "$ERR_FIELD" "$BROWSE_BOOL" "${SESSIONS:-1}" \
|
"$DUR_FIELD" "$OUTCOME" "$ERR_FIELD" "$ERR_MSG_FIELD" "$STEP_FIELD" \
|
||||||
"$INSTALL_FIELD" "$REPO_SLUG" "$BRANCH" >> "$JSONL_FILE" 2>/dev/null || true
|
"$BROWSE_BOOL" "${SESSIONS:-1}" \
|
||||||
|
"$INSTALL_FIELD" "$SOURCE" "$REPO_SLUG" "$BRANCH" >> "$JSONL_FILE" 2>/dev/null || true
|
||||||
|
|
||||||
# ─── Trigger sync if tier is not off ─────────────────────────
|
# ─── Trigger sync if tier is not off ─────────────────────────
|
||||||
SYNC_CMD="$GSTACK_DIR/bin/gstack-telemetry-sync"
|
SYNC_CMD="$GSTACK_DIR/bin/gstack-telemetry-sync"
|
||||||
|
|||||||
Reference in New Issue
Block a user