Workers cf.ray scope

All,

I just finished building out a logging capability so that I can collecting log messages from my Workers. One of the fields, in addition to cf.colo is cf.ray. My initial assumption was that the ray ID was particular to a machine within the colo. Since multiple instances of my Worker might be running on single machine, I create an instance ID that I include in my log entries. The idea being to be able to coorrelate log messages to a single run of my script.

var rayid  = ""
var instid = ""
var colo   = ""

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min
}

/* ... */
    let r  = getRandomInt(0, 2**32 - 1)
    let a  = r.toString(16)
    instid = "0x" + a.padStart(8, '0')
/* ... */

If I had a better understanding of the scope of the rayID, I could get rid of this instance ID, which I’d really like to do.

Does anyone know what, specifically, the Ray ID refers to?

Thanks,

Jason.

The Ray ID, as far as it’s publicly available is a somewhat sequential counter of the request, nothing specific to the machine. There should be no difference between instances if there are no issues in the code.

A RayID is an almost unique ID which relates to the client request. In Workers there is also a ParentRayID which is the Ray ID of the parent request if this request was made using a Worker script.

2 Likes

Awesome, thanks folks! I’ve removed my instance ID. rayid should be sufficient for correlating log entries from a single run of my script.

1 Like