Placement inside worker

Is it possible to get the placement inside of a worker (for analytics reasons)? It seems like colo is the closest DC to the user, not the actual placement (when using smart placement).
5 Replies
zegevlier
zegevlier•5d ago
It's a bit hacky, but you can always send a request to https://cloudflare.com/cdn-cgi/trace, parse out the colo= field and use that. That request should be really quick, since it's all inside of CF's network. I am not aware of any other way to get the colo your worker is running in from inside your code.
iano
ianoOP•5d ago
oh thats helpful ok
DaniFoldi
DaniFoldi•4d ago
smart placement also sets the cf-placement header on the request which you can check: https://developers.cloudflare.com/workers/configuration/smart-placement/#cf-placement-header
zegevlier
zegevlier•4d ago
I did not know about that. That is a better solution in this case, at least if it doesn't get removed 😅
iano
ianoOP•3d ago
As far as I can tell that header isnt set on the request object that actually comes in to the worker, though it is helpful on the response At least I couldnt find any way to get at it

Did you find this page helpful?