Skip to main content
Operating a globally distributed algorithmic trading network demands extreme observability. A silent failure in an order loop or a transient API throttling event can lead to missed targets and unhedged exposures. This guide outlines our telemetry architecture, covering Cloudflare Workers 100% request sampling, time-series SQL database queries, R2 logging, and automated alarm systems.

⚡ 1. 100% Request Head Sampling

To monitor traffic at Cloudflare’s edge compiler level, every worker in the Hoox monorepo enables native observability tracing inside its wrangler.jsonc:

Metrics Tracked Automatically

Once enabled, Cloudflare captures and graphs these metrics near-instantaneously:
  • Requests velocity: Total hits and requests/second rates.
  • CPU execution duration (ms): The exact CPU time consumed by the isolate thread.
  • Uncaught Exceptions: Crashes or code errors that bypass middlewares.
  • Subrequest Counts: Outbound HTTP calls made to exchange APIs or other workers.

💾 2. Cloudflare Analytics Engine (SQL Telemetry)

While Cloudflare collects basic HTTP metrics, Hoox uses Cloudflare Analytics Engine inside analytics-worker to track trading-specific variables (e.g. execution slippage, exchange response delays, fee sums).

Under-the-Hood SQL Queries

The analytics-worker exposes a SQL interface to query the metrics dataset directly from your Next.js Dashboard:

📝 3. Logging & R2 Storage Offloading

Because transactional databases like SQLite D1 have write limits, Hoox implements a dual-tier logging policy:
  • High-Value Data: Transaction statuses and fills are written to your D1 trades table.
  • Verbose Telemetry: Full, verbose JSON payload exchanges, network headers, and WebSocket stream records are serialized and saved to R2 Storage using date-based key paths: logs/bybit/BTCUSDT/2026-05-19/order-18049284739.json
This offloading reduces database write volumes by up to 75%, keeping your database compact, fast, and fully within free-tier limits.

🚨 4. Standardized Alarm Systems

If a critical error or execution failure occurs (e.g., an order is rejected due to insufficient margin, or the kill switch is flipped due to drawdown limits):
  1. The executing worker intercepts the exception using the shared error handler.
  2. Direct V8 Service Binding pings telegram-worker instantly.
  3. You receive an emergency alert on your phone.

Need to tail live worker logs to debug a custom strategy? Run hoox logs tail trade-worker in your terminal to open a real-time WebSocket connection to Cloudflare’s global edge logging console!

🔗 Next Steps

Last modified on June 17, 2026