Getting RayId in workers

I would like to retrieve the either the RayId or the RequestId from the worker’s script. Would this be possible? I looked into request.cf and request.headers but I can’t seem to find anything in there that related to the rayId.

What I would like to do is to have this passed down as the RootId for log tracing so we could see the whole trail of this request from CF into AWS.

You can get the cf-ray or the cf-request-id headers. They are there…

1 Like

I don’t think so. I print them out and they are empty.

request.headers['cf-ray']

That is an Headers object, it’s not an array… do request.headers.get['cf-ray'] or better request.headers.get['cf-request-id'] since it’s the long term one.

1 Like

you can reference an object via the [] as well. not that it matters but doing that is empty too.

Ok, so for some reason none of the above worked when i print them out but looping them allows me to see that it’s there now.

 for (var pair of request.headers.entries()) {
       console.log(pair[0]+ ': '+ pair[1]);
 }

Sorry, wrong parenthesis. It’s a JS Object with it’s own interfaces, it’s not accessible directly.

request.headers.get('cf-ray')
request.headers.get('cf-request-id')
1 Like

Yeah lol. I was about to say. I tried with () and it worked

Thanks!

1 Like