Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/analytics-engine/gotchas.md
1# Analytics Engine Gotchas23## Critical Issues45### Sampling at High Volumes67**Problem:** Queries return fewer points than written at >1M writes/min.89**Solution:**10```typescript11// Pre-aggregate before writing12let buffer = { count: 0, total: 0 };13buffer.count++; buffer.total += value;1415// Write once per second instead of per request16if (Date.now() % 1000 === 0) {17env.ANALYTICS.writeDataPoint({ doubles: [buffer.count, buffer.total] });18}19```2021**Detection:** `npx wrangler tail` → look for "sampling enabled"2223### writeDataPoint Returns void2425```typescript26// ❌ Pointless await27await env.ANALYTICS.writeDataPoint({...});2829// ✅ Fire-and-forget30env.ANALYTICS.writeDataPoint({...});31```3233Writes can fail silently. Check tail logs.3435### Index vs Blob3637| Cardinality | Use | Example |38|-------------|-----|---------|39| Millions | **Index** | user_id, api_key |40| Hundreds | **Blob** | endpoint, status_code, country |4142```typescript43// ✅ Correct44{ blobs: [method, path, status], indexes: [userId] }45```4647### Can't Query from Workers4849Query API requires HTTP auth. Use external service or cache in KV/D1.5051### No Custom Timestamps5253Auto-generated at write time. Store original in blob if needed.5455## Common Errors5657| Error | Fix |58|-------|-----|59| Binding not found | Check wrangler.jsonc, redeploy |60| No data in query | Wait 30s; check dataset name; check time range |61| Query timeout | Add time filter; use index for filtering |6263## Limits6465| Resource | Limit |66|----------|-------|67| Blobs per point | 20 |68| Doubles per point | 20 |69| Indexes per point | 1 |70| Blob/Index size | 16KB |71| Write rate (no sampling) | ~1M/min |72| Retention | 90 days |73| Query timeout | 30s |7475## Best Practices7677✅ Pre-aggregate at high volumes78✅ Use index for high-cardinality (millions)79✅ Always include time filter in queries80✅ Design schema before coding8182❌ Don't await writeDataPoint83❌ Don't use index for low-cardinality84❌ Don't query without time range85❌ Don't assume all writes succeed86