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/observability/gotchas.md
1## Common Errors23### "Logs not appearing"45**Cause:** Observability disabled, Worker not redeployed, no traffic, low sampling rate, or log size exceeds 256 KB6**Solution:**7```bash8# Verify config9cat wrangler.jsonc | jq '.observability'1011# Check deployment12wrangler deployments list <WORKER_NAME>1314# Test with curl15curl https://your-worker.workers.dev16```17Ensure `observability.enabled = true`, redeploy Worker, check `head_sampling_rate`, verify traffic1819### "Traces not being captured"2021**Cause:** Traces not enabled, incorrect sampling rate, Worker not redeployed, or destination unavailable22**Solution:**23```jsonc24// Temporarily set to 100% sampling for debugging25{26"observability": {27"enabled": true,28"head_sampling_rate": 1.0,29"traces": {30"enabled": true31}32}33}34```35Ensure `observability.traces.enabled = true`, set `head_sampling_rate` to 1.0 for testing, redeploy, check destination status3637## Limits3839| Resource/Limit | Value | Notes |40|----------------|-------|-------|41| Max log size | 256 KB | Logs exceeding this are truncated |42| Default sampling rate | 1.0 (100%) | Reduce for high-traffic Workers |43| Max destinations | Varies by plan | Check dashboard |44| Trace context propagation | 100 spans max | Deep call chains may lose spans |45| Analytics Engine write rate | 25 writes/request | Excess writes dropped silently |4647## Performance Gotchas4849### Spectre Mitigation Timing5051**Problem:** `Date.now()` and `performance.now()` have reduced precision (coarsened to 100μs)52**Cause:** Spectre vulnerability mitigation in V853**Solution:** Accept reduced precision or use Workers Traces for accurate timing54```typescript55// Date.now() is coarsened - trace spans are accurate56export default {57async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {58// For user-facing timing, Date.now() is fine59const start = Date.now();60const response = await processRequest(request);61const duration = Date.now() - start;6263// For detailed performance analysis, use Workers Traces instead64return response;65}66}67```6869### Analytics Engine _sample_interval Aggregation7071**Problem:** Queries return incorrect totals when not multiplying by `_sample_interval`72**Cause:** Analytics Engine stores sampled data points, each representing multiple events73**Solution:** Always multiply counts/sums by `_sample_interval` in aggregations74```sql75-- WRONG: Undercounts actual events76SELECT blob1 AS customer_id, COUNT(*) AS total_calls77FROM api_usage GROUP BY customer_id;7879-- CORRECT: Accounts for sampling80SELECT blob1 AS customer_id, SUM(_sample_interval) AS total_calls81FROM api_usage GROUP BY customer_id;82```8384### Trace Context Propagation Limits8586**Problem:** Deep call chains lose trace context after 100 spans87**Cause:** Cloudflare limits trace depth to prevent performance impact88**Solution:** Design for flatter architectures or use custom correlation IDs for deep chains89```typescript90// For deep call chains, add custom correlation ID91const correlationId = crypto.randomUUID();92console.log({ correlationId, event: 'request_start' });9394// Pass correlationId through headers to downstream services95await fetch('https://api.example.com', {96headers: { 'X-Correlation-ID': correlationId }97});98```99100## Pricing (2026)101102### Workers Traces103- **GA Pricing (starts March 1, 2026):**104- $0.10 per 1M trace spans captured105- Retention: 14 days included106- **Free tier:** 10M trace spans/month107- **Note:** Beta usage (before March 1, 2026) is free108109### Workers Logs110- **Included:** Free for all Workers111- **Logpush:** Requires Business/Enterprise plan112113### Analytics Engine114- **Included:** 10M writes/month on Paid Workers plan115- **Additional:** $0.25 per 1M writes beyond included quota116