From bb8f4dcde8fc59a92c1cd345eed73e34b4e86c3e Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Thu, 9 Apr 2026 10:06:41 +0700 Subject: [PATCH] feat: enable Cloudflare Workers observability (logs + traces) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add observability config to wrangler.jsonc with logs and traces enabled, 100% sampling, and persistence. Free tier feature — no code changes needed. --- docs/system-architecture.md | 9 +++++++++ src/bot-info-commands.js | 1 - wrangler.jsonc | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/system-architecture.md b/docs/system-architecture.md index 469cd2a..71fb3bd 100644 --- a/docs/system-architecture.md +++ b/docs/system-architecture.md @@ -97,6 +97,15 @@ Binding: `claude-status` queue - **403/400 handling**: subscriber removed from KV, message acknowledged - **Network errors**: `msg.retry()` for transient failures +## Observability + +Enabled via `wrangler.jsonc` `observability` config. Automatic — no code changes required. + +- **Logs**: All `console.log`/`console.error` calls, request metadata, exceptions. Persisted with invocation logs enabled. Free tier: 200k logs/day, 3-day retention. +- **Traces**: Automatic instrumentation of fetch calls, KV reads, queue operations. Persisted. +- **Sampling**: 100% (`head_sampling_rate: 1`) for both logs and traces — reduce for high-volume scenarios +- **Dashboard**: Cloudflare Dashboard → Workers → Observability + ## Security - **Statuspage webhook auth**: URL path secret validated with timing-safe SHA-256 comparison diff --git a/src/bot-info-commands.js b/src/bot-info-commands.js index 4be67ba..7b81f3b 100644 --- a/src/bot-info-commands.js +++ b/src/bot-info-commands.js @@ -10,7 +10,6 @@ import { humanizeStatus, STATUS_URL, } from "./status-fetcher.js"; - /** * Register info commands: /help, /status, /history, /uptime */ diff --git a/wrangler.jsonc b/wrangler.jsonc index 41b4e9b..1987f49 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -23,6 +23,21 @@ "max_retries": 3 } ] + }, + "observability": { + "enabled": false, + "head_sampling_rate": 1, + "logs": { + "enabled": true, + "head_sampling_rate": 1, + "persist": true, + "invocation_logs": true + }, + "traces": { + "enabled": true, + "persist": true, + "head_sampling_rate": 1 + } } // Secrets (set via `wrangler secret put`): // BOT_TOKEN - Telegram bot token