Skip to content

fix(proxy): include cfRay and lbProbe in HTTP request log context - #1757

Open
pankajc46 wants to merge 1 commit into
cloudflare:masterfrom
pankajc46:fix/proxy-log-cfray
Open

pankajc46 wants to merge 1 commit into
cloudflare:masterfrom
pankajc46:fix/proxy-log-cfray

Conversation

@pankajc46

@pankajc46 pankajc46 commented Oct 8, 2026 •

Copy link
Copy Markdown

Summary

newHTTPLogger builds the logger used for every proxied HTTP request, but it discards the zerolog.Context returned by ctx.Str(logFieldCFRay, ...) and ctx.Bool(logFieldLBProbe, ...). zerolog.Context methods have value receivers and return the updated context, so cfRay and lbProbe have been missing from these log lines since TUN-8238 (971360d, first released in 2024.2.1).

As a result, origin request error lines and the debug request/response lines carry no Ray ID, so they can't be correlated with Cloudflare edge logs (Logpush RayID) or with origin access logs that record the Cf-Ray header.

Fix

Assign the returned context:

ctx = ctx.Str(logFieldCFRay, cfRay)
ctx = ctx.Bool(logFieldLBProbe, lbProbe)

This restores fields newHTTPLogger was already meant to emit. No new log fields, and no change to log levels or messages.

Test plan

  • Added TestNewHTTPLoggerContextFields (request with Cf-Ray, load balancer probe, plain request). It fails on master (cfRay and lbProbe missing) and passes with this change.
  • go test -race ./proxy/...
  • go vet ./proxy/, gofmt -l, goimports -local github.com/cloudflare/cloudflared
  • golangci-lint run ./proxy/... (v2.14.0, repo config): 0 issues
  • CI green on this PR

Fixes #1756

newHTTPLogger discarded the zerolog.Context returned by ctx.Str and
ctx.Bool. zerolog.Context methods have value receivers and return the
updated context, so the cfRay and lbProbe fields were never added to the
per-request logger. Since TUN-8238 (2024.2.1), origin request error lines
and the debug request/response lines carry no Ray ID, so they can't be
correlated with Cloudflare edge logs or origin access logs.

Assign the returned context, and add a test covering the Cf-Ray, load
balancer probe and plain request cases.

Fixes cloudflare#1756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 cfRay is missing from proxied request logs (newHTTPLogger discards the zerolog context)

1 participant