Environment:1jehuang Jcode Cloudflare Workers
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Telemetry, Serverless |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Cloudflare Workers runtime with D1, R2, and Analytics Engine bindings for the jcode telemetry pipeline, providing serverless event ingestion with dual-write storage.
Description
The Cloudflare Workers environment hosts the jcode telemetry worker — a serverless function that ingests anonymous telemetry events from jcode clients. The worker uses multiple Cloudflare bindings: D1 (relational database for durable records), R2 (object storage for consented transcripts), and Analytics Engine (high-volume firehose with ~90-day retention). The worker implements dual-write: every event goes to both D1 (for durable identity/lifecycle rows) and Analytics Engine (for raw event analysis). D1 size is monitored against an 8GB soft limit to trigger emergency pruning before hitting the 10GB hard cap. A nightly cron job (17 4 * * *) runs retention-based pruning.
Usage
Use this environment for all telemetry worker implementations: insertEvent (event ingestion with dual-write), pruneOldEvents (scheduled and emergency pruning), oauthAccount (OAuth account tracking with hashing), normalizeLabel (model label normalization), and syncModelPrices (nightly price sync from models.dev). It is the mandatory runtime for the entire telemetry pipeline.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Cloudflare edge | Serverless, no OS management |
| Hardware | Cloudflare infrastructure | Auto-scaled |
| Disk | D1: 10GB hard cap, 8GB soft limit | Analytics Engine: ~90-day retention, no cap |
Dependencies
Cloudflare Bindings
- `DB` — D1 database (
jcode-telemetry, ID:abaa524c-3e90-4ba9-a569-027e78a083c6) - `TRANSCRIPTS` — R2 bucket (
jcode-consensed-transcripts, 30-day lifecycle) - `FIREHOSE` — Analytics Engine dataset (
jcode_telemetry_firehose) - `FIREHOSE_WEB` — Analytics Engine dataset (
jcode_web_firehose) - `FIREHOSE_DISCOVERY` — Analytics Engine dataset (
jcode_discovery_firehose) - `FIREHOSE_INSTALL` — Analytics Engine dataset (
jcode_install_firehose) - `FIREHOSE_GEO` — Analytics Engine dataset (
jcode_geo_firehose) - `FIREHOSE_CONCURRENCY` — Analytics Engine dataset (
jcode_concurrency_firehose) - `FIREHOSE_USAGE` — Analytics Engine dataset (
jcode_usage_firehose)
NPM Packages
- `wrangler` = ^4 (dev dependency, Cloudflare Workers CLI)
Configuration
- `compatibility_date` = "2025-01-01"
- Custom domains:
telemetry.solosystems.dev,telemetry.jcode.sh - Cron:
17 4 * * *(nightly retention prune) - `ALLOWED_ORIGIN` = "*" (anonymous telemetry, permissive CORS)
Credentials
- Cloudflare API token (for
wrangler deploy) - D1 database ID is configured in
wrangler.toml - Analytics Engine requires one-time dashboard enablement (see action required comment in wrangler.toml)
Quick Install
# Install wrangler
cd telemetry-worker
npm install
# Deploy the worker
npx wrangler deploy
# Run migrations (see package.json scripts):
npx wrangler d1 execute jcode-telemetry --remote --file=migrations/0001_expand_events.sql
Code Evidence
D1 database binding from telemetry-worker/wrangler.toml:19-22:
[[d1_databases]]
binding = "DB"
database_name = "jcode-telemetry"
database_id = "abaa524c-3e90-4ba9-a569-027e78a083c6"
D1 soft limit for emergency pruning from telemetry-worker/src/worker.js:101:
const D1_SOFT_LIMIT_BYTES = 8_000_000_000;
const EMERGENCY_PRUNE_COOLDOWN_MS = 10 * 60 * 1000;
Cron trigger from telemetry-worker/wrangler.toml:16-17:
[triggers]
crons = ["17 4 * * *"]
Analytics Engine one-time enable caveat from telemetry-worker/wrangler.toml:38-42:
# ACTION REQUIRED: Analytics Engine needs a one-time enable in the dashboard
# Until then this binding must stay commented out or `wrangler deploy` fails
# with code 10089. The worker code degrades gracefully without the binding
# (responses report firehose:false).
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `wrangler deploy fails with code 10089` | Analytics Engine not enabled in dashboard | Enable Analytics Engine at dash.cloudflare.com/.../workers/analytics-engine, then uncomment binding and redeploy
|
| `D1 database full` | D1 exceeded 10GB hard cap | Emergency prune triggers at 8GB soft limit; verify cron is running |
| `firehose: false` in response | FIREHOSE binding commented out | Worker degrades gracefully; enable Analytics Engine and uncomment binding |
Compatibility Notes
- Analytics Engine: Requires one-time dashboard enablement. Worker degrades gracefully without the binding (responses report
firehose:false). - D1 storage: Hard-capped at 10GB by Cloudflare Workers Paid. Soft limit at 8GB triggers emergency prune with 10-minute cooldown.
- R2 transcripts: Must configure 30-day lifecycle rule separately in the dashboard.
- Custom domains:
telemetry.solosystems.devandtelemetry.jcode.shmanaged as Workers custom domains (Cloudflare creates DNS + cert).