Skip to content

feat(api): log the phases of every Cloudflare Realtime call - #790

Merged
realhasanshoaib merged 3 commits into
masterfrom
feat/cf-call-trace
Nov 1, 2026
Merged

realhasanshoaib merged 3 commits into
masterfrom
feat/cf-call-trace

Conversation

@realhasanshoaib

@realhasanshoaib realhasanshoaib commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Slow Cloudflare Realtime calls (add tracks, renegotiate, close, session create) cannot be explained from our logs today: we log the total time, not where it went. This adds one log line per call so the next production data shows whether a slow call lost time in DNS, connect, TLS, a stale reused connection or Cloudflare itself.

Fix

  • Each call logs cloudflare_sfu.call_trace with dns_ms, connect_ms, tls_ms, ttfb_ms (request sent to first response byte), conn_reused, conn_idle_ms, ip_family (v4 or v6), colo (the 3-letter suffix of the cf-ray header), operation, kind (pull, publish, mixed, or empty for calls without tracks), track_count and http_status.
  • A call that gets no answer still logs, with http_status 0 and ttfb_ms 0.
  • The line carries the trace ID through the context, so it joins the existing cloudflare_sfu.add_tracks line.
  • It never logs an address, a ray ID, a header value other than the colo, or a body.
  • Status and error code of failed calls are already logged (http_status, provider_code, provider_raw_code), so nothing was added there.
  • It adds one log line per Cloudflare call, which roughly doubles the lines per add-tracks attempt.
  • No behavior changes: the trace only observes the request through httptrace.

Proof

  • call_trace_test.go uses a fake Cloudflare that sets a cf-ray header and delays 60 ms. It checks the exact field set, colo FRA, ip_family v4, ttfb_ms near the delay, conn_reused false then true on the second call, and that the ray ID and server address are absent from the log. Other tests cover a call with no answer, the colo parser (lowercase, padding, missing, too long) and the v4/v6 family.
  • go test for adapters/cloudflare/... and httpapi/... passes on Instabox. The pre-commit gate passed.
  • Not checked: a real HTTPS call to Cloudflare, so tls_ms is covered only by the zero case.

Undo: revert this commit; nothing else depends on the log line.

Created with Claude Sonnet 5.5 in Claude Code.


Devin Review

Each add-tracks, renegotiate, close and session-create call now logs one
cloudflare_sfu.call_trace line with dns_ms, connect_ms, tls_ms, ttfb_ms,
conn_reused, conn_idle_ms, the IP family, the 3-letter Cloudflare colo, the
operation, pull or publish, and the track count. No behavior changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@realhasanshoaib realhasanshoaib added risk:low Low risk: an agent may merge it once every check and review passes. size:L 100-499 changed lines, not counting tests, lockfiles or generated files. labels Nov 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T17:36:50.016595Z 60962a5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

…at warn, classify capture pulls

- body_ms covers the wait between the first response byte and the end of the body.
- A failed dial still stamps connect_ms, so a connect timeout shows its length.
- A failed call logs its trace at warn, so it survives CHALK_API_LOG_LEVEL=warn.
- Recording pulls (captureTracksRequest) log their kind and track count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

…cels at info

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@realhasanshoaib
realhasanshoaib merged commit e777e6d into master Nov 1, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Low risk: an agent may merge it once every check and review passes. size:L 100-499 changed lines, not counting tests, lockfiles or generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant