Possible to Access Worker Invocation/Request ID inside Worker?

I have a worker that sits in front of some API endpoints to handle some business logic. The worker eventually forwards a JSON payload to the API endpoint via a queue. TL;DR; I want to append the invocation/request ID I see in the worker logs so I can better debug between CF and my API backend. Is this Request ID/Invocation ID accessible inside a worker? Thx in advance for the help.
No description
5 Replies
Hello, I’m Allie!
That might be the ray ID? Should be a header on the request named “cf-ray”
Hello, I’m Allie!
Cloudflare Docs
Cloudflare HTTP headers
Cloudflare passes all HTTP request headers to your origin web server and adds additional headers as specified below.
Derek Cavaliero
Derek CavalieroOP3w ago
I was thinking it might be yeah. Though the docs describe that ray header as a different formatted string but it may be delimited with some other values for the colo it went through
Hello, I’m Allie!
Looking at it, you might just need to remove the Colo, yeah
Derek Cavaliero
Derek CavalieroOP3w ago
thanks, ill give it a shot and see if it works Yeah - confirmed its the Ray ID. I am curious how that works given that in the docs they say a Ray ID is not necessarily unique, but in the worker logs they certainly seem to be treated as unique. Perhaps its different for workers vs accessing it outside CF's edge environments.

Did you find this page helpful?