Skip to main content
The analytics-worker is the observability engine of the Hoox trading platform. Deployed as a private internal microservice, it aggregates time-series metrics, database query latencies, execution performance ratios, and API status codes across all V8 isolates. By translating incoming events and writing them to Cloudflare Analytics Engine, it provides the backend telemetry used to draw live charts in the Next.js Dashboard.

⚡ 1. Declared Wrangler Configurations & Bindings

The analytics-worker binds directly to Cloudflare’s Analytics Engine dataset and does not expose any public endpoints:
No CLOUDFLARE_API_TOKEN or CLOUDFLARE_ACCOUNT_ID are in secrets — these are set as vars in wrangler.jsonc and used for the Cloudflare SQL API query path.

🔑 2. Environmental Variables & Encrypted Secrets

  • CLOUDFLARE_API_TOKEN (var): A secure token with Account.Analytics read permissions, allowing the worker to query stored datasets via the Cloudflare SQL API.
  • CLOUDFLARE_ACCOUNT_ID (var): Your Cloudflare Account ID used in SQL API requests.

🔌 3. Internal REST API Specification

Note: For the canonical endpoint directory with full request/response examples across all workers, see /docs/devops/api/endpoints.
All endpoints are reachable via Cloudflare Service Bindings only (no public URL). Each endpoint validates its payload with a Zod schema using .strict() to reject unknown fields.

A. Track Trade Event

  • Endpoint: POST /track/trade
  • Payload:
  • Response: { "success": true }

B. Track API Call Event

Invoked by other workers (like hoox or trade-worker) immediately upon completing an action.
  • Endpoint: POST /track/api-call
  • Payload:

Under-the-Hood Analytics Engine Write

The worker formats and writes a time-series data point to the hoox-analytics dataset:
  • Response (200) : { "success": true }

C. Track Worker Performance

  • Endpoint: POST /track/worker-perf
  • Payload:

D. Track Signal

  • Endpoint: POST /track/signal
  • Payload:

E. Track Notification

  • Endpoint: POST /track/notification
  • Payload:

F. Health

  • Endpoint: GET /health
  • Response: { "status": "ok", "worker": "analytics-worker" }

Query Methods (Exported Functions)

The analytics worker exports query functions that are called via Service Bindings (not HTTP). Each builds a SQL query and executes it against the Cloudflare Analytics Engine SQL API: All SQL queries are built via sanitizeQueryInputs() which validates parameters using allowlists and regex to prevent SQL injection.

📈 4. Dashboard Visual Integrations

The metrics written to hoox-analytics are queried by the dashboard to render:
  1. System Health Indicators: Real-time error spikes trigger warning banners in under 2 seconds.
  2. Isolate Latency Charts: Visual line graphs showing V8 processing speeds vs exchange API transit speeds.
  3. Volume Load Heatmaps: Visualizes peak trading hours and signal traffic volumes globally.

Testing analytics locally? Local Wrangler dev automatically intercepts writeDataPoint calls and logs the parsed Blobs and Doubles straight to your terminal standard output, ensuring easy debugging!

🔗 Next Steps

Last modified on June 17, 2026