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
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.oh thats helpful ok
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-headerI did not know about that. That is a better solution in this case, at least if it doesn't get removed 😅
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