does CF workers include any kind of sortable Request ID like ULID/UUIDv7 into the request context?
Hi, I'm trying to improve logging in in R2 by generating an Request ID. Does Workers has any kind of Request ID included in the request context so I can save a few ms of generating an UUIDv7. This is really crucial to our system, since we are saving auditing data into R2 data catalog.
15 Replies
There’s a RayID, but those aren’t guaranteed unique afaik
RayID is not sortable and unique boss...
btw only fetch workers has RayID in the request header (presumed that it was generated by Cf CDN), cron worker does not have that
I mean could there be an ID like AWS-Request-ID? It's included in every requests
Yeah, sorry, that’s what I meant. The closest thing to a Request ID Workers has is RayIDs, but it wouldn’t really work for your case
If you do need a truly sortable/unique ID, I think you would just need to bite the bullet and generate it yourself
okay boss... does cf has any plan to support this? Including it in logs/response header/workers context?
I don’t think so? You can also generate it in a rule, but that would still require extra time
Let me check
Cloudflare Docs
Functions
The Cloudflare Rules language provides functions for manipulating and validating values in an expression:
hmm but i really need uuidv7 or ulid, in my observation cf does not any features like lambda@edge to do that trick
Yeah, your best bet is probably just importing a package that can do it for you
:Buon:
Like this https://uuid.rocks/ulid
Or well, I guess you could just hit this endpoint for one too?
If that works?
currently I'm using a hono middleware to handle things for me. Hitting uuid.rocks like above does include the network hitching tho
Yeah, if that’s a dealbreaker then I would just use https://www.npmjs.com/package/ulid
npm
ulid
A universally-unique, lexicographically-sortable, identifier generator. Latest version: 3.0.1, last published: 2 months ago. Start using ulid in your project by running
npm i ulid
. There are 857 other projects in the npm registry using ulid.why does it need to be uuidv7 over uuidv4?
I'm just a bit confused why that would be needed... but I suppose I don't know the business use case
uuidv4 is too random and hurts the database performance, damage the BTREE of RDBMS index and void the advantage of data ordering in some other DataWarehouse/NoSQL like tabular, snowflake, cloudera or cassandra
basically anything is better of sortable or indexed, such as your dictionary, your yellow pages, etc
Like what Donald Knuth (or John Von Neumann) once said: Every problem can be reduced to sorting and searching, so making the data sortable is one of the step that makes it easier to sort and find
so unless you are using a KV database and does not really care about ordering (because you have already know what to find) then uuidv4 is enough for you. But most of cases that I've encountered, having a sortable-id will benefits the index a lot, so why not using it?
A lot of other distributed system such as discord, sony and twitter also uses some sort of sortable ID for their database